Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
identifier.h
Go to the documentation of this file.
1 #pragma once
2 #include <functional>
3 #include <ostream>
4 #include <string>
5 
6 #include "nlohmann/json.hpp"
7 
8 namespace hgps::core {
9 
17 struct Identifier final {
19  constexpr Identifier() = default;
20 
25  Identifier(const char *const value);
26 
31  Identifier(std::string value);
32 
35  bool is_empty() const noexcept;
36 
39  std::size_t size() const noexcept;
40 
43  const std::string &to_string() const noexcept;
44 
47  std::size_t hash() const noexcept;
48 
52  bool equal(const std::string &other) const noexcept;
53 
57  bool equal(const Identifier &other) const noexcept;
58 
62  bool operator==(const Identifier &rhs) const noexcept;
63 
67  std::strong_ordering operator<=>(const Identifier &rhs) const noexcept = default;
68 
71  static Identifier empty();
72 
77  friend std::ostream &operator<<(std::ostream &stream, const Identifier &identifier);
78 
79  private:
80  std::string value_{};
81  std::size_t hash_code_{std::hash<std::string>{}("")};
82 
83  void validate_identifeir() const;
84 };
85 
86 void from_json(const nlohmann::json &j, Identifier &id);
87 
88 void from_json(const nlohmann::json &j, std::map<Identifier, double> &map);
89 
90 } // namespace hgps::core
91 
92 namespace std {
93 
95 template <> struct hash<hgps::core::Identifier> {
96  size_t operator()(const hgps::core::Identifier &id) const noexcept { return id.hash(); }
97 };
98 
99 } // namespace std
Top-level namespace for Health-GPS Core C++ API.
Definition: analysis.h:7
void from_json(const nlohmann::json &j, Identifier &id)
Definition: identifier.cpp:59
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
nlohmann::json json
JSON parser namespace alias.
Definition: jsonparser.h:16
Global namespace.
Definition: jsonparser.h:88
Entity unique identifier data type.
Definition: identifier.h:17
bool is_empty() const noexcept
Checks whether this is an empty identifier.
Definition: identifier.cpp:23
bool equal(const std::string &other) const noexcept
Determines whether a string representation and this instance have same value.
Definition: identifier.cpp:35
constexpr Identifier()=default
Initialises a new instance of the hgps::core::Identifier class.
std::size_t size() const noexcept
Gets the side of the identifier.
Definition: identifier.cpp:25
std::size_t hash() const noexcept
Gets the identifier hash code value.
Definition: identifier.cpp:29
static Identifier empty()
Represents the empty Identifier, read-only.
Definition: identifier.cpp:8
const std::string & to_string() const noexcept
Convert the identifier to a string representation.
Definition: identifier.cpp:27
size_t operator()(const hgps::core::Identifier &id) const noexcept
Definition: identifier.h:96