Sen API
Sen Libraries
Loading...
Searching...
No Matches
property.h
Go to the documentation of this file.
1// === property.h ======================================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_CORE_META_PROPERTY_H
9#define SEN_CORE_META_PROPERTY_H
10
12#include "sen/core/meta/event.h"
14#include "sen/core/meta/type.h"
15
16// std
17#include <memory>
18#include <string>
19#include <string_view>
20#include <utility>
21#include <vector>
22
23namespace sen
24{
25
28
37
39struct PropertySpec final
40{
41 PropertySpec(std::string name,
42 std::string description,
46 bool checkedSet = false,
47 std::vector<std::string> tags = {})
48 : name(std::move(name))
51 , type(std::move(type))
53 , tags(std::move(tags))
55 {
56 }
57
58 // Comparison operators
59 friend bool operator==(const PropertySpec& lhs, const PropertySpec& rhs) noexcept
60 {
61 return lhs.name == rhs.name && lhs.description == rhs.description && lhs.category == rhs.category &&
62 lhs.transportMode == rhs.transportMode && lhs.tags == rhs.tags && lhs.checkedSet == rhs.checkedSet &&
63 lhs.type == rhs.type;
64 }
65 friend bool operator!=(const PropertySpec& lhs, const PropertySpec& rhs) noexcept { return !(lhs == rhs); }
66
67public:
68 std::string name; // NOLINT(misc-non-private-member-variables-in-classes)
69 std::string description; // NOLINT(misc-non-private-member-variables-in-classes)
70 PropertyCategory category = PropertyCategory::dynamicRO; // NOLINT(misc-non-private-member-variables-in-classes)
71 ConstTypeHandle<> type; // NOLINT(misc-non-private-member-variables-in-classes)
72 TransportMode transportMode = TransportMode::multicast; // NOLINT(misc-non-private-member-variables-in-classes)
73 std::vector<std::string> tags; // NOLINT(misc-non-private-member-variables-in-classes)
74 bool checkedSet = false; // NOLINT(misc-non-private-member-variables-in-classes)
75};
76
78class Property final
79{
80 SEN_NOCOPY_NOMOVE(Property)
82
83public:
86 [[nodiscard]] static std::shared_ptr<Property> make(PropertySpec spec);
87
88public: // special members
89 Property(PropertySpec spec, Private notUsable);
90 ~Property() = default;
91
92public:
94 [[nodiscard]] std::string_view getName() const noexcept;
95
97 [[nodiscard]] std::string_view getDescription() const noexcept;
98
100 [[nodiscard]] MemberHash getId() const noexcept;
101
103 [[nodiscard]] PropertyCategory getCategory() const noexcept;
104
106 [[nodiscard]] ConstTypeHandle<> getType() const noexcept;
107
109 [[nodiscard]] TransportMode getTransportMode() const noexcept;
110
112 [[nodiscard]] const Method& getGetterMethod() const noexcept;
113
115 [[nodiscard]] const Method& getSetterMethod() const noexcept;
116
118 [[nodiscard]] const Event& getChangeEvent() const noexcept;
119
121 [[nodiscard]] const std::vector<std::string>& getTags() const noexcept;
122
124 [[nodiscard]] bool getCheckedSet() const noexcept;
125
128 [[nodiscard]] static std::string makeGetterMethodName(const PropertySpec& spec);
129
132 [[nodiscard]] static std::string makeSetterMethodName(const PropertySpec& spec);
133
136 [[nodiscard]] static std::string makeChangeNotificationEventName(const PropertySpec& spec);
137
139 [[nodiscard]] bool operator==(const Property& other) const noexcept;
140
142 [[nodiscard]] bool operator!=(const Property& other) const noexcept;
143
145 [[nodiscard]] MemberHash getHash() const noexcept;
146
147private:
148 PropertySpec spec_;
149 MemberHash id_;
150 MemberHash hash_;
151 std::shared_ptr<const Method> setterMethod_;
152 std::shared_ptr<const Method> getterMethod_;
153 std::shared_ptr<const Event> changeEvent_;
154};
155
157
158//----------------------------------------------------------------------------------------------------------------------
159// Inline implementation
160//----------------------------------------------------------------------------------------------------------------------
161
163template <>
164struct impl::hash<PropertySpec>
165{
166 u32 operator()(const PropertySpec& spec) const noexcept
167 {
168 auto result = hashCombine(hashSeed, spec.name, spec.category, spec.transportMode, spec.type->getHash());
169
170 for (const auto& tag: spec.tags)
171 {
172 result = hashCombine(result, tag);
173 }
174 return result;
175 }
176};
177
178} // namespace sen
179
180#endif // SEN_CORE_META_PROPERTY_H
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
Represents an event.
Definition core/include/sen/core/meta/event.h:34
Represents a method.
Definition method.h:96
bool getCheckedSet() const noexcept
If true, the user will validate sets to the property value.
const std::vector< std::string > & getTags() const noexcept
Any user-defined tags.
static std::shared_ptr< Property > make(PropertySpec spec)
Factory function that validates the spec and creates a property. Throws std::exception if the spec is...
static std::string makeChangeNotificationEventName(const PropertySpec &spec)
Utility function that creates the name of a change notification event. Throws std::exception if the s...
Property(PropertySpec spec, Private notUsable)
std::string_view getName() const noexcept
The name of the property.
TransportMode getTransportMode() const noexcept
Gets the transport mode for this property.
~Property()=default
MemberHash getHash() const noexcept
Returns a unique hash for the Property computed at compile time.
const Method & getSetterMethod() const noexcept
The setter method.
static std::string makeGetterMethodName(const PropertySpec &spec)
Utility function that creates the name of a getter method. Throws std::exception if the spec has an e...
PropertyCategory getCategory() const noexcept
Gets the property category.
const Event & getChangeEvent() const noexcept
The change notification event.
std::string_view getDescription() const noexcept
The documentation of the property.
ConstTypeHandle getType() const noexcept
Gets the return type of the method (nullptr means void).
MemberHash getId() const noexcept
The propety id.
const Method & getGetterMethod() const noexcept
The getter method.
static std::string makeSetterMethodName(const PropertySpec &spec)
Utility function that creates the name of a setter method. Throws std::exception if the spec has an e...
constexpr u32 hashSeed
Initial seed for all hashes.
Definition hash32.h:33
u32 hashCombine(u32 seed, const Types &... args) noexcept
Combines the hash of different values into a single 32-bit hash.
Definition hash32.h:214
#define SEN_PRIVATE_TAG
Definition compiler_macros.h:490
PropertyCategory
How a property is seen by others.
Definition property.h:31
TypeHandle< const T > ConstTypeHandle
Definition type.h:319
TransportMode
How to transport information.
Definition type.h:56
@ staticRO
Does not change over time, can only be set via code.
Definition property.h:32
@ staticRW
Does not change over time, can be set via code and configuration.
Definition property.h:33
@ dynamicRO
May change over time, cannot be set from outside.
Definition property.h:35
@ dynamicRW
May change over time, can be set from outside.
Definition property.h:34
@ multicast
Directed to all receivers, unreliable, unordered, no congestion control.
Definition type.h:58
uint32_t u32
Definition numbers.h:25
Definition assert.h:17
STL namespace.
The hash of a member.
Definition type.h:39
Data of a property.
Definition property.h:40
PropertyCategory category
Definition property.h:70
TransportMode transportMode
Definition property.h:72
ConstTypeHandle type
Definition property.h:71
friend bool operator!=(const PropertySpec &lhs, const PropertySpec &rhs) noexcept
Definition property.h:65
friend bool operator==(const PropertySpec &lhs, const PropertySpec &rhs) noexcept
Definition property.h:59
std::string description
Definition property.h:69
std::vector< std::string > tags
Definition property.h:73
std::string name
Definition property.h:68
bool checkedSet
Definition property.h:74
PropertySpec(std::string name, std::string description, ConstTypeHandle<> type, PropertyCategory category=PropertyCategory::dynamicRO, TransportMode transportMode=TransportMode::multicast, bool checkedSet=false, std::vector< std::string > tags={})
Definition property.h:41