diff options
author | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-05-26 12:30:48 -0400 |
---|---|---|
committer | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-05-26 12:30:48 -0400 |
commit | d49e65ba9df79a574885a056affc3ab9caf8cfbb (patch) | |
tree | d82972ef5a345736cb1b5b01a30a0762cd8a7a8b /src/libfetchers/attrs.hh | |
parent | 832bd534dc0ab36fd8267f62b67ab1db1498d2b4 (diff) | |
parent | b90241ceb13500238e428f8943d221f24bf5322b (diff) |
Merge remote-tracking branch 'john-ericson/enum-FileIngestionMethod' into no-stringly-typed-derivation-output
Diffstat (limited to 'src/libfetchers/attrs.hh')
-rw-r--r-- | src/libfetchers/attrs.hh | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libfetchers/attrs.hh b/src/libfetchers/attrs.hh new file mode 100644 index 000000000..d6e0ae000 --- /dev/null +++ b/src/libfetchers/attrs.hh @@ -0,0 +1,39 @@ +#pragma once + +#include "types.hh" + +#include <variant> + +#include <nlohmann/json_fwd.hpp> + +namespace nix::fetchers { + +/* Wrap bools to prevent string literals (i.e. 'char *') from being + cast to a bool in Attr. */ +template<typename T> +struct Explicit { + T t; +}; + +typedef std::variant<std::string, int64_t, Explicit<bool>> Attr; +typedef std::map<std::string, Attr> Attrs; + +Attrs jsonToAttrs(const nlohmann::json & json); + +nlohmann::json attrsToJson(const Attrs & attrs); + +std::optional<std::string> maybeGetStrAttr(const Attrs & attrs, const std::string & name); + +std::string getStrAttr(const Attrs & attrs, const std::string & name); + +std::optional<int64_t> maybeGetIntAttr(const Attrs & attrs, const std::string & name); + +int64_t getIntAttr(const Attrs & attrs, const std::string & name); + +std::optional<bool> maybeGetBoolAttr(const Attrs & attrs, const std::string & name); + +bool getBoolAttr(const Attrs & attrs, const std::string & name); + +std::map<std::string, std::string> attrsToQuery(const Attrs & attrs); + +} |