5 #ifndef _UGCS_VSM_PROPERTY_H_
6 #define _UGCS_VSM_PROPERTY_H_
8 #include <ucs_vsm_proto.h>
10 #include <ugcs/vsm/optional.h>
11 #include <unordered_map>
16 class Property:
public std::enable_shared_from_this<Property>
24 VALUE_TYPE_DOUBLE = 3,
25 VALUE_TYPE_STRING = 4,
29 VALUE_TYPE_BINARY = 8,
34 VALUE_SPEC_REGULAR = 1,
39 Property(
int id,
const std::string& name, proto::Field_semantic semantic);
42 Property(
int id,
const std::string& name, Value_type type);
49 template<
typename Type>
50 Property(
const std::string& name, Type
value, proto::Field_semantic sem = proto::FIELD_SEMANTIC_DEFAULT):
63 "Unsupported value type");
66 if (semantic == proto::FIELD_SEMANTIC_DEFAULT) {
67 semantic = Get_default_semantic(name);
70 if (semantic == proto::FIELD_SEMANTIC_DEFAULT) {
73 type = VALUE_TYPE_BOOL;
74 semantic = proto::FIELD_SEMANTIC_BOOL;
76 type = VALUE_TYPE_INT;
77 semantic = proto::FIELD_SEMANTIC_NUMERIC;
79 type = VALUE_TYPE_ENUM;
80 semantic = proto::FIELD_SEMANTIC_ENUM;
82 type = VALUE_TYPE_FLOAT;
83 semantic = proto::FIELD_SEMANTIC_NUMERIC;
85 type = VALUE_TYPE_DOUBLE;
86 semantic = proto::FIELD_SEMANTIC_NUMERIC;
88 type = VALUE_TYPE_STRING;
89 semantic = proto::FIELD_SEMANTIC_STRING;
92 type = Get_type_from_semantic(semantic);
98 Add_enum(
const std::string& name,
int value);
107 Set_value(
const std::string& v);
110 Set_value(
const char* v);
116 Set_value(
unsigned int v);
119 Set_value(
const proto::List_value &v);
126 Set_value(
const proto::Field_value& val);
129 Register(proto::Register_field* field);
132 Write_as_property(proto::Property_field* field);
135 Write_as_parameter(proto::Parameter_field* field);
138 Write_as_telemetry(proto::Telemetry_field* field);
159 Get_value(
double &v);
162 Get_value(std::string& v);
168 Get_value(int64_t &v);
171 Get_value(proto::List_value &v);
187 Get_id() {
return field_id;}
190 Get_name() {
return name;}
192 proto::Field_semantic
193 Get_semantic() {
return semantic;}
195 std::chrono::time_point<std::chrono::system_clock>
196 Get_update_time() {
return update_time;}
202 Fields_are_equal(
const proto::Field_value& val1,
const proto::Field_value& val2);
205 Is_equal(
const Property&);
209 Write_value(proto::Field_value* field);
211 bool is_changed =
false;
213 Value_type type = VALUE_TYPE_NONE;
214 proto::Field_semantic semantic = proto::FIELD_SEMANTIC_DEFAULT;
219 std::string string_value;
220 bool bool_value =
false;
221 double double_value = 0;
222 int64_t int_value = 0;
223 proto::List_value list_value;
230 std::unordered_map<int, std::string> enum_values;
231 std::chrono::seconds timeout = std::chrono::seconds(0);
232 Value_spec value_spec = VALUE_SPEC_NA;
233 std::chrono::time_point<std::chrono::system_clock> update_time;
237 std::chrono::time_point<std::chrono::steady_clock> last_commit_time;
241 static constexpr std::chrono::milliseconds COMMIT_TIMEOUT = std::chrono::milliseconds(200);
243 static proto::Field_semantic
244 Get_default_semantic(
const std::string& name);
247 Get_type_from_semantic(
const proto::Field_semantic sem);
253 template<
typename Type>
255 Get_value(
const std::string& name, Type& value)
const
257 auto it = find(name);
258 if (it != end() && !it->second->Is_value_na()) {
259 return it->second->Get_value(value);
Definition: property.h:250
std::shared_ptr< Property > Ptr
Pointer type.
Definition: property.h:18
Various common utilities.
Definition: property.h:16
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
T value
Stored value (in wire byte order).
Definition: endian.h:376