33#include < string>
44#include < optional>
55#include < ostream>
6+ #include < utility>
67#include < nlohmann/json.hpp>
8+ #include < nlohmann/json_fwd.hpp>
9+
710#include " ScalarComponent.h"
811#include " Util/JsonUtils.h"
12+ #include " DataComponent.h"
13+ #include " SimpleComponent.h"
914
1015namespace ConnectedSystemsAPI ::DataModels::Component {
1116 class Category ;
@@ -24,10 +29,6 @@ namespace ConnectedSystemsAPI::DataModels::Component {
2429 Category& operator =(Category&&) noexcept = default ;
2530 ~Category () override = default ;
2631
27- void validate () const override {
28- ScalarComponent::validate ();
29- }
30-
3132 nlohmann::ordered_json toJson () const override {
3233 nlohmann::ordered_json j;
3334 to_json (j, *this );
@@ -39,49 +40,44 @@ namespace ConnectedSystemsAPI::DataModels::Component {
3940 // / This property is optional to enable structure to act as a schema for values provided separately (e.g., in a datastream)
4041 // / </summary>
4142 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 ; }
43+ void setValue (std::optional<std::string> v) { value = std::move (v); }
4744 bool hasValue () const noexcept { return value.has_value (); }
4845 void clearValue () noexcept { value.reset (); }
4946
5047 // / <summary>
5148 // / Name of the dictionary where the possible values for this component are listed and defined.
5249 // / </summary>
5350 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 ; }
51+ void setCodeSpace (std::optional<std::string> cs) { codeSpace = std::move (cs); }
5952 bool hasCodeSpace () const noexcept { return codeSpace.has_value (); }
6053 void clearCodeSpace () noexcept { codeSpace.reset (); }
6154
55+ friend void from_json (const nlohmann::json& j, Category& v);
56+ friend void to_json (nlohmann::ordered_json& j, const Category& v);
57+
58+ friend bool operator ==(const Category& a, const Category& b) { return a.toJson () == b.toJson (); }
59+ friend bool operator !=(const Category& a, const Category& b) { return !(a == b); }
60+
6261 friend std::ostream& operator <<(std::ostream& os, const Category& v) {
6362 nlohmann::ordered_json j;
6463 to_json (j, v);
6564 return os << j.dump (2 );
6665 }
67-
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); }
7066 };
7167
72- inline DataComponent::Registrar<Category> registerCategory{ " Category" };
68+ const inline DataComponent::Registrar<Category> registerCategory{ " Category" };
7369
7470 inline void from_json (const nlohmann::json& j, Category& v) {
7571 from_json (j, static_cast <ScalarComponent&>(v));
7672
77- v.setValue ( ConnectedSystemsAPI::JsonUtils::tryParseString (j, " value" ) );
78- v.setCodeSpace ( ConnectedSystemsAPI::JsonUtils::tryParseString (j, " codeSpace" ) );
73+ v.value = ConnectedSystemsAPI::JsonUtils::tryParseString (j, " value" );
74+ v.codeSpace = ConnectedSystemsAPI::JsonUtils::tryParseString (j, " codeSpace" );
7975 }
8076
8177 inline void to_json (nlohmann::ordered_json& j, const Category& v) {
8278 to_json (j, static_cast <const ScalarComponent&>(v));
8379
84- if (v.getValue ()) j[" value" ] = v.getValue () .value ();
85- if (v.getCodeSpace ()) j[" codeSpace" ] = v.getCodeSpace () .value ();
80+ if (v.hasValue ()) j[" value" ] = v.value .value ();
81+ if (v.hasCodeSpace ()) j[" codeSpace" ] = v.codeSpace .value ();
8682 }
8783}
0 commit comments