Skip to content

Commit 2cd6d5b

Browse files
Refactoring
1 parent 4dcfb5e commit 2cd6d5b

53 files changed

Lines changed: 3321 additions & 3470 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CSAPI-lib/DataModels/Component/Boolean.h

Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,62 @@
77
#include "ScalarComponent.h"
88
#include "Util/JsonUtils.h"
99

10-
namespace ConnectedSystemsAPI {
11-
namespace DataModels {
12-
namespace Component {
13-
class Boolean;
14-
void to_json(nlohmann::ordered_json& j, const Boolean& v);
10+
namespace ConnectedSystemsAPI::DataModels::Component {
11+
class Boolean;
12+
void to_json(nlohmann::ordered_json& j, const Boolean& v);
1513

16-
class Boolean : public ScalarComponent {
17-
private:
18-
std::optional<bool> value = std::nullopt;
14+
class Boolean : public ScalarComponent {
15+
private:
16+
std::optional<bool> value = std::nullopt;
1917

20-
public:
21-
Boolean() = default;
22-
Boolean(const Boolean&) = default;
23-
Boolean(Boolean&&) noexcept = default;
24-
Boolean& operator=(const Boolean&) = default;
25-
Boolean& operator=(Boolean&&) noexcept = default;
26-
~Boolean() override = default;
18+
public:
19+
Boolean() = default;
20+
Boolean(const Boolean&) = default;
21+
Boolean(Boolean&&) noexcept = default;
22+
Boolean& operator=(const Boolean&) = default;
23+
Boolean& operator=(Boolean&&) noexcept = default;
24+
~Boolean() override = default;
2725

28-
void validate() const override {
29-
ScalarComponent::validate();
30-
}
26+
void validate() const override {
27+
ScalarComponent::validate();
28+
}
3129

32-
nlohmann::ordered_json toJson() const override {
33-
nlohmann::ordered_json j;
34-
to_json(j, *this);
35-
return j;
36-
}
30+
nlohmann::ordered_json toJson() const override {
31+
nlohmann::ordered_json j;
32+
to_json(j, *this);
33+
return j;
34+
}
3735

38-
/// <summary>
39-
/// Inline value(s) for the component.
40-
/// This property is optional to enable structure to act as a schema for values provided separately (e.g., in a datastream)
41-
/// </summary>
42-
const std::optional<bool>& getValue() const noexcept { return value; }
43-
void setValue(std::optional<bool> v) noexcept { value = std::move(v); }
44-
void setValue(bool v) noexcept { value = v; }
45-
bool hasValue() const noexcept { return value.has_value(); }
46-
void clearValue() noexcept { value.reset(); }
47-
};
36+
/// <summary>
37+
/// Inline value(s) for the component.
38+
/// This property is optional to enable structure to act as a schema for values provided separately (e.g., in a datastream)
39+
/// </summary>
40+
const std::optional<bool>& getValue() const noexcept { return value; }
41+
void setValue(std::optional<bool> v) noexcept { value = std::move(v); }
42+
void setValue(bool v) noexcept { value = v; }
43+
bool hasValue() const noexcept { return value.has_value(); }
44+
void clearValue() noexcept { value.reset(); }
45+
};
4846

49-
inline DataComponent::Registrar<Boolean> registerBoolean{ "Boolean" };
50-
inline bool operator==(const Boolean& a, const Boolean& b) { return a.toJson() == b.toJson(); }
51-
inline bool operator!=(const Boolean& a, const Boolean& b) { return !(a == b); }
47+
inline DataComponent::Registrar<Boolean> registerBoolean{ "Boolean" };
48+
inline bool operator==(const Boolean& a, const Boolean& b) { return a.toJson() == b.toJson(); }
49+
inline bool operator!=(const Boolean& a, const Boolean& b) { return !(a == b); }
5250

53-
inline void from_json(const nlohmann::json& j, Boolean& v) {
54-
from_json(j, static_cast<ScalarComponent&>(v));
51+
inline void from_json(const nlohmann::json& j, Boolean& v) {
52+
from_json(j, static_cast<ScalarComponent&>(v));
5553

56-
v.setValue(ConnectedSystemsAPI::JsonUtils::tryParseBoolean(j, "value"));
57-
}
54+
v.setValue(ConnectedSystemsAPI::JsonUtils::tryParseBoolean(j, "value"));
55+
}
5856

59-
inline void to_json(nlohmann::ordered_json& j, const Boolean& v) {
60-
to_json(j, static_cast<const ScalarComponent&>(v));
57+
inline void to_json(nlohmann::ordered_json& j, const Boolean& v) {
58+
to_json(j, static_cast<const ScalarComponent&>(v));
6159

62-
if (v.getValue()) j["value"] = v.getValue().value();
63-
}
60+
if (v.getValue()) j["value"] = v.getValue().value();
61+
}
6462

65-
inline std::ostream& operator<<(std::ostream& os, const Boolean& v) {
66-
nlohmann::ordered_json j;
67-
to_json(j, v);
68-
return os << j.dump(2);
69-
}
70-
}
63+
inline std::ostream& operator<<(std::ostream& os, const Boolean& v) {
64+
nlohmann::ordered_json j;
65+
to_json(j, v);
66+
return os << j.dump(2);
7167
}
7268
}

CSAPI-lib/DataModels/Component/BooleanBuilder.h

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,31 @@
55
#include "Boolean.h"
66
#include "DataComponentBuilder.h"
77

8-
namespace ConnectedSystemsAPI {
9-
namespace DataModels {
10-
namespace Component {
11-
class BooleanBuilder : public DataComponentBuilder<BooleanBuilder, Boolean> {
12-
private:
13-
std::optional<bool> value;
8+
namespace ConnectedSystemsAPI::DataModels::Component {
9+
class BooleanBuilder : public DataComponentBuilder<BooleanBuilder, Boolean> {
10+
private:
11+
std::optional<bool> value;
1412

15-
void validate() const {
16-
this->validateBase();
17-
}
13+
void validate() const {
14+
this->validateBase();
15+
}
1816

19-
public:
20-
BooleanBuilder() = default;
17+
public:
18+
BooleanBuilder() = default;
2119

22-
BooleanBuilder& withValue(std::optional<bool> v) { value = std::move(v); return *this; }
23-
BooleanBuilder& withValue(bool v) { value = v; return *this; }
24-
BooleanBuilder& clearValue() { value.reset(); return *this; }
20+
BooleanBuilder& withValue(std::optional<bool> v) { value = std::move(v); return *this; }
21+
BooleanBuilder& withValue(bool v) { value = v; return *this; }
22+
BooleanBuilder& clearValue() { value.reset(); return *this; }
2523

26-
Boolean build() {
27-
validate();
24+
Boolean build() {
25+
validate();
2826

29-
Boolean b;
30-
this->applyBase(b);
27+
Boolean b;
28+
this->applyBase(b);
3129

32-
if (value) b.setValue(value);
30+
if (value) b.setValue(value);
3331

34-
return b;
35-
}
36-
};
32+
return b;
3733
}
38-
}
34+
};
3935
}

CSAPI-lib/DataModels/Component/Category.h

Lines changed: 64 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,84 +7,81 @@
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

Comments
 (0)