Nix/src/libfetchers/attrs.hh

43 lines
1.1 KiB
C++
Raw Normal View History

2020-03-17 20:54:36 +01:00
#pragma once
///@file
2020-03-17 20:54:36 +01:00
#include "types.hh"
#include "hash.hh"
2020-03-17 20:54:36 +01:00
#include <variant>
#include <nlohmann/json_fwd.hpp>
#include <optional>
2020-03-17 20:54:36 +01:00
namespace nix::fetchers {
typedef std::variant<std::string, uint64_t, Explicit<bool>> Attr;
/**
* An `Attrs` can be thought of a JSON object restricted or simplified
* to be "flat", not containing any subcontainers (arrays or objects)
* and also not containing any `null`s.
*/
2020-03-17 20:54:36 +01:00
typedef std::map<std::string, Attr> Attrs;
Attrs jsonToAttrs(const nlohmann::json & json);
2020-10-28 15:41:18 +01:00
nlohmann::json attrsToJSON(const Attrs & attrs);
2020-03-17 20:54:36 +01: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 20:54:36 +01:00
uint64_t getIntAttr(const Attrs & attrs, const std::string & name);
2020-03-17 20:54:36 +01: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 20:54:36 +01:00
}