nix-super/src/libfetchers/attrs.hh

36 lines
902 B
C++
Raw Normal View History

2020-03-17 21:54:36 +02:00
#pragma once
///@file
2020-03-17 21:54:36 +02:00
#include "types.hh"
#include <variant>
#include <nlohmann/json_fwd.hpp>
#include <optional>
2020-03-17 21:54:36 +02:00
namespace nix::fetchers {
typedef std::variant<std::string, uint64_t, Explicit<bool>> Attr;
2020-03-17 21:54:36 +02:00
typedef std::map<std::string, Attr> Attrs;
Attrs jsonToAttrs(const nlohmann::json & json);
2020-10-28 16:41:18 +02:00
nlohmann::json attrsToJSON(const Attrs & attrs);
2020-03-17 21:54:36 +02:00
std::optional<std::string> maybeGetStrAttr(const Attrs & attrs, const std::string & name);
std::string getStrAttr(const Attrs & attrs, const std::string & name);
std::optional<uint64_t> maybeGetIntAttr(const Attrs & attrs, const std::string & name);
2020-03-17 21:54:36 +02:00
uint64_t getIntAttr(const Attrs & attrs, const std::string & name);
2020-03-17 21:54:36 +02:00
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);
2020-03-17 21:54:36 +02:00
}