77#include " ScalarComponent.h"
88#include " Util/JsonUtils.h"
99
10- namespace ConnectedSystemsAPI {
11- namespace DataModels {
12- namespace Component {
13- class Category ;
14- void to_json (nlohmann::ordered_json& j, const Category& q);
10+ namespace ConnectedSystemsAPI ::DataModels::Component {
11+ class Category ;
12+ void to_json (nlohmann::ordered_json& j, const Category& q);
1513
16- class Category : public ScalarComponent {
17- private:
18- std::optional<std::string> value;
19- std::optional<std::string> codeSpace;
14+ class Category : public ScalarComponent {
15+ private:
16+ std::optional<std::string> value;
17+ std::optional<std::string> codeSpace;
2018
21- public:
22- Category () = default ;
23- Category (const Category&) = default ;
24- Category (Category&&) noexcept = default ;
25- Category& operator =(const Category&) = default ;
26- Category& operator =(Category&&) noexcept = default ;
27- ~Category () override = default ;
19+ public:
20+ Category () = default ;
21+ Category (const Category&) = default ;
22+ Category (Category&&) noexcept = default ;
23+ Category& operator =(const Category&) = default ;
24+ Category& operator =(Category&&) noexcept = default ;
25+ ~Category () override = default ;
2826
29- void validate () const override {
30- ScalarComponent::validate ();
31- }
27+ void validate () const override {
28+ ScalarComponent::validate ();
29+ }
30+
31+ nlohmann::ordered_json toJson () const override {
32+ nlohmann::ordered_json j;
33+ to_json (j, *this );
34+ return j;
35+ }
3236
33- nlohmann::ordered_json toJson () const override {
34- nlohmann::ordered_json j;
35- to_json (j, *this );
36- return j;
37- }
37+ // / <summary>
38+ // / Inline value(s) for the component.
39+ // / This property is optional to enable structure to act as a schema for values provided separately (e.g., in a datastream)
40+ // / </summary>
41+ const std::optional<std::string>& getValue () const noexcept { return value; }
42+ void setValue (const std::optional<std::string>& v) { value = v; }
43+ void setValue (std::optional<std::string>&& v) { value = std::move (v); }
44+ void setValue (const std::string& v) { value = v; }
45+ void setValue (std::string&& v) { value = std::move (v); }
46+ void setValue (const char * v) { value = v ? std::optional<std::string>(v) : std::nullopt ; }
47+ bool hasValue () const noexcept { return value.has_value (); }
48+ void clearValue () noexcept { value.reset (); }
3849
39- // / <summary>
40- // / Inline value(s) for the component.
41- // / This property is optional to enable structure to act as a schema for values provided separately (e.g., in a datastream)
42- // / </summary>
43- const std::optional<std::string>& getValue () const noexcept { return value; }
44- void setValue (const std::optional<std::string>& v) { value = v; }
45- void setValue (std::optional<std::string>&& v) { value = std::move (v); }
46- void setValue (const std::string& v) { value = v; }
47- void setValue (std::string&& v) { value = std::move (v); }
48- void setValue (const char * v) { value = v ? std::optional<std::string>(v) : std::nullopt ; }
49- bool hasValue () const noexcept { return value.has_value (); }
50- void clearValue () noexcept { value.reset (); }
50+ // / <summary>
51+ // / Name of the dictionary where the possible values for this component are listed and defined.
52+ // / </summary>
53+ const std::optional<std::string>& getCodeSpace () const noexcept { return codeSpace; }
54+ void setCodeSpace (const std::optional<std::string>& cs) { codeSpace = cs; }
55+ void setCodeSpace (std::optional<std::string>&& cs) { codeSpace = std::move (cs); }
56+ void setCodeSpace (const std::string& cs) { codeSpace = cs; }
57+ void setCodeSpace (std::string&& cs) { codeSpace = std::move (cs); }
58+ void setCodeSpace (const char * cs) { codeSpace = cs ? std::optional<std::string>(cs) : std::nullopt ; }
59+ bool hasCodeSpace () const noexcept { return codeSpace.has_value (); }
60+ void clearCodeSpace () noexcept { codeSpace.reset (); }
5161
52- // / <summary>
53- // / Name of the dictionary where the possible values for this component are listed and defined.
54- // / </summary>
55- const std::optional<std::string>& getCodeSpace () const noexcept { return codeSpace; }
56- void setCodeSpace (const std::optional<std::string>& cs) { codeSpace = cs; }
57- void setCodeSpace (std::optional<std::string>&& cs) { codeSpace = std::move (cs); }
58- void setCodeSpace (const std::string& cs) { codeSpace = cs; }
59- void setCodeSpace (std::string&& cs) { codeSpace = std::move (cs); }
60- void setCodeSpace (const char * cs) { codeSpace = cs ? std::optional<std::string>(cs) : std::nullopt ; }
61- bool hasCodeSpace () const noexcept { return codeSpace.has_value (); }
62- void clearCodeSpace () noexcept { codeSpace.reset (); }
63- };
62+ friend std::ostream& operator <<(std::ostream& os, const Category& v) {
63+ nlohmann::ordered_json j;
64+ to_json (j, v);
65+ return os << j.dump (2 );
66+ }
6467
65- inline DataComponent::Registrar< Category> registerCategory{ " Category" };
66- inline bool operator == (const Category& a, const Category& b) { return a. toJson () == b. toJson ( ); }
67- inline bool operator !=( const Category& a, const Category& b) { return !(a == b); }
68+ friend bool operator ==( const Category& a, const Category& b) { return a. toJson () == b. toJson (); }
69+ friend bool operator != (const Category& a, const Category& b) { return !(a == b); }
70+ };
6871
69- inline void from_json (const nlohmann::json& j, Category& v) {
70- from_json (j, static_cast <ScalarComponent&>(v));
72+ inline DataComponent::Registrar<Category> registerCategory{ " Category" };
7173
72- v.setValue (ConnectedSystemsAPI::JsonUtils::tryParseString (j, " value" ));
73- v.setCodeSpace (ConnectedSystemsAPI::JsonUtils::tryParseString (j, " codeSpace" ));
74- }
74+ inline void from_json (const nlohmann::json& j, Category& v) {
75+ from_json (j, static_cast <ScalarComponent&>(v));
7576
76- inline void to_json (nlohmann::ordered_json& j, const Category& v) {
77- to_json (j, static_cast <const ScalarComponent&>(v));
77+ v.setValue (ConnectedSystemsAPI::JsonUtils::tryParseString (j, " value" ));
78+ v.setCodeSpace (ConnectedSystemsAPI::JsonUtils::tryParseString (j, " codeSpace" ));
79+ }
7880
79- if (v.getValue ()) j[" value" ] = v.getValue ().value ();
80- if (v.getCodeSpace ()) j[" codeSpace" ] = v.getCodeSpace ().value ();
81- }
81+ inline void to_json (nlohmann::ordered_json& j, const Category& v) {
82+ to_json (j, static_cast <const ScalarComponent&>(v));
8283
83- inline std::ostream& operator <<(std::ostream& os, const Category& v) {
84- nlohmann::ordered_json j;
85- to_json (j, v);
86- return os << j.dump (2 );
87- }
88- }
84+ if (v.getValue ()) j[" value" ] = v.getValue ().value ();
85+ if (v.getCodeSpace ()) j[" codeSpace" ] = v.getCodeSpace ().value ();
8986 }
9087}
0 commit comments