ifw-core  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Record.hpp
Go to the documentation of this file.
1 
9 #ifndef IFW_DIT_DID_RECORD_HPP_
10 #define IFW_DIT_DID_RECORD_HPP_
11 
12 #include <string>
13 
14 #include "ctd/defines/defines.hpp"
15 #include "ctd/file/Yaml.hpp"
16 
17 
18 namespace dit {
19  namespace did {
20 
22  class Range {
23  public:
24  Range();
25 
27  Range(ctd::defines::DataType data_type,
28  const std::string& lower_limit,
29  const std::string& upper_limit);
30 
32  Range(const Range& source);
33 
34  ~Range();
35 
37  void SetLimits(ctd::defines::DataType data_type,
38  const std::string& lower_limit,
39  const std::string& upper_limit);
40 
42  template <class TYPE>
43  void GetLowerLimit(TYPE& lower_limit) const {
44  RAD_LOG_TRACE();
45 
46  lower_limit = ctd::conversion::Convert(m_lower_limit, m_data_type, lower_limit);
47  }
48 
50  template <class TYPE>
51  void GetUpperLimit(TYPE& upper_limit) const {
52  RAD_LOG_TRACE();
53 
54  upper_limit = ctd::conversion::Convert(m_upper_limit, m_data_type, upper_limit);
55  }
56 
58  std::string ToString() const;
59 
61  Range& operator = (const Range& source);
62 
63  protected:
65  std::string m_lower_limit;
66  std::string m_upper_limit;
67 
68  private:
69  void _Copy(const Range& source);
70  };
71 
72 
75  public:
76 
78  Reset();
79  };
80 
82 
84  void Reset() {
85  m_flag = 0;
86  m_width = 0;
87  m_precision = 0;
88  m_length = "";
89  m_specifier = 0;
90  };
91 
92  char m_flag {0};
93  int8_t m_width {0};
94  int8_t m_precision {0};
95  std::string m_length;
96  char m_specifier {0};
97  };
98 
100  typedef enum {
110 
115 
116  } DidRecField;
117 
118  // Dictionary Record Fields.
119  const std::string DID_REC_FIELD_CLASS_STR = "Class";
120  const std::string DID_REC_FIELD_TYPE_STR = "Type";
121  const std::string DID_REC_FIELD_FORMAT_STR = "Format";
122  const std::string DID_REC_FIELD_DEFAULT_STR = "Default";
123  const std::string DID_REC_FIELD_UNIT_STR = "Unit";
124  const std::string DID_REC_FIELD_RANGE_STR = "Range";
125  const std::string DID_REC_FIELD_COMMENT_STR = "Comment";
126  const std::string DID_REC_FIELD_TAGS_STR = "Tags";
127  const std::string DID_REC_FIELD_DESCRIPTION_STR = "Description";
128 
130  const std::map<DidRecField, std::string> DID_REC_FIELDS_NB_MAP = {
131  {DID_REC_FIELD_CLASS, DID_REC_FIELD_CLASS_STR},
132  {DID_REC_FIELD_TYPE, DID_REC_FIELD_TYPE_STR},
133  {DID_REC_FIELD_FORMAT, DID_REC_FIELD_FORMAT_STR},
134  {DID_REC_FIELD_DEFAULT, DID_REC_FIELD_DEFAULT_STR},
135  {DID_REC_FIELD_UNIT, DID_REC_FIELD_UNIT_STR},
136  {DID_REC_FIELD_RANGE, DID_REC_FIELD_RANGE_STR},
137  {DID_REC_FIELD_COMMENT, DID_REC_FIELD_COMMENT_STR},
138  {DID_REC_FIELD_TAGS, DID_REC_FIELD_TAGS_STR},
139  {DID_REC_FIELD_DESCRIPTION, DID_REC_FIELD_DESCRIPTION_STR}
140  };
141 
142 
144  const std::map<std::string, DidRecField> DID_REC_FIELDS_NAME_MAP = {
154  };
155 
156 
158  class Record {
159  public:
160 
166  static void DecodeFormat(const std::string& did_format,
167  FormatSpecifier& format_specifier);
168 
170  static std::string PrintRecords(std::vector<dit::did::Record>& records,
171  const DidRecField fields = DID_REC_FIELD_ALL);
172 
173 
174  Record();
175 
181  Record(const std::string& key_name,
182  const ctd::file::Yaml& did);
183 
184  Record(const Record& source);
185 
186  ~Record();
187 
193  void Parse(const std::string& key_name,
194  const ctd::file::Yaml& did);
195 
197  const std::string& GetName() const;
198 
200  const std::string& GetAltName() const;
201 
203  const std::vector<std::string>& GetClasses() const;
204 
207 
209  const std::string& GetFormat() const;
210 
212  template <class TYPE>
213  TYPE GetDefaultValue() const;
214 
216  const std::string& GetUnit() const;
217 
219  const std::vector<Range>& GetRanges() const;
220 
222  const std::string& GetComment() const;
223 
225  const std::vector<std::string>& GetTags() const;
226 
228  const std::string& GetDescription() const;
229 
235  std::string ToString(DidRecField fields = DID_REC_FIELD_ALL,
236  const bool compact = false) const;
237 
239  Record& operator = (const Record& source);
240 
241  protected:
242  std::string m_field_name;
243  std::string m_alt_field_name; // Name without optional indeces.
244  std::string m_org_name;
245  std::vector<std::string> m_field_classes;
247  std::string m_field_format;
248  std::string m_field_default;
249  std::string m_field_unit;
250  std::vector<Range> m_field_ranges;
251  std::string m_field_comment;
252  std::vector<std::string> m_field_tags;
253  std::string m_field_description;
254 
255  private:
256  void _Copy(const Record& source);
257  };
258 
259  }
260 }
261 
262 #endif // !IFW_DIT_DID_RECORD_HPP_
Class to handle YAML files.
Class implementing the handling of Yaml files in the ICS environment.
Definition: Yaml.hpp:27
static void DecodeFormat(const std::string &did_format, FormatSpecifier &format_specifier)
Decode the format in a DID record.
Definition: Record.cpp:75
~Range()
Definition: Record.cpp:33
std::string ToString(DidRecField fields=DID_REC_FIELD_ALL, const bool compact=false) const
Get string copy of one or more header fields.
Definition: Record.cpp:327
int8_t m_width
Definition: Record.hpp:93
Range & operator=(const Range &source)
Copy operator.
Definition: Record.cpp:51
class to handle the format specifier of a DID record.
Definition: Record.hpp:74
std::string ToString() const
Print out the members in a string buffer.
Definition: Record.cpp:68
FormatSpecifier()
Definition: Record.hpp:77
const std::string DID_REC_FIELD_CLASS_STR
Definition: Record.hpp:119
Definition: Record.hpp:109
const std::string & GetComment() const
Get the comment defined.
Definition: Record.cpp:306
std::vector< Range > m_field_ranges
Definition: Record.hpp:250
const std::string & GetDescription() const
Get the description of the key.
Definition: Record.cpp:320
const std::map< DidRecField, std::string > DID_REC_FIELDS_NB_MAP
map to map from record &quot;class&quot; field numeric to string representation.
Definition: Record.hpp:130
Definition: Record.hpp:105
Definition: Record.hpp:111
Common definitions.
std::string m_field_unit
Definition: Record.hpp:249
const std::string DID_REC_FIELD_TAGS_STR
Definition: Record.hpp:126
Record & operator=(const Record &source)
Copy operator.
Definition: Record.cpp:464
const std::string & GetName() const
Return name of the keyword record.
Definition: Record.cpp:250
const std::string DID_REC_FIELD_DEFAULT_STR
Definition: Record.hpp:122
Definition: Record.hpp:106
DataType
Data types numeric representations.
Definition: types.hpp:34
~FormatSpecifier()
Definition: Record.hpp:81
ctd::defines::DataType GetDataType() const
Return data type defined for the keyword.
Definition: Record.cpp:271
Definition: Record.hpp:102
const std::string & GetFormat() const
Return the output format defined for the keyword.
Definition: Record.cpp:278
std::string m_alt_field_name
Definition: Record.hpp:243
const std::string & GetUnit() const
Return the unit, if defined for the key.
Definition: Record.cpp:292
const std::string DID_REC_FIELD_FORMAT_STR
Definition: Record.hpp:121
std::string m_field_default
Definition: Record.hpp:248
void Reset()
Method to reset the object (reset the internal members).
Definition: Record.hpp:84
void Parse(const std::string &key_name, const ctd::file::Yaml &did)
Parse Parse/extract the fields of a keyword record from a Yaml object.
Definition: Record.cpp:136
const std::string DID_REC_FIELD_UNIT_STR
Definition: Record.hpp:123
std::string m_field_format
Definition: Record.hpp:247
TYPE GetDefaultValue() const
Return the default value, if defined for the key.
Definition: Record.cpp:285
static std::string PrintRecords(std::vector< dit::did::Record > &records, const DidRecField fields=DID_REC_FIELD_ALL)
Print (dump) records contained in the class in a string buffer.
Definition: Record.cpp:491
std::vector< std::string > m_field_tags
Definition: Record.hpp:252
ctd::defines::DataType m_data_type
Definition: Record.hpp:64
std::string m_lower_limit
Definition: Record.hpp:65
Definition: Record.hpp:103
Range()
Definition: Record.cpp:12
int8_t m_precision
Definition: Record.hpp:94
char m_specifier
Definition: Record.hpp:96
void Convert(const std::string &str_value, std::string &native_value)
Handle case: Conversion of std::string to std::string.
Definition: conversion.cpp:52
ctd::defines::DataType m_field_type
Definition: Record.hpp:246
Definition: Record.hpp:104
const std::map< std::string, DidRecField > DID_REC_FIELDS_NAME_MAP
map to map from record &quot;class&quot; field string to numeric representation.
Definition: Record.hpp:144
Data Interface Dictionary keyword record class.
Definition: Record.hpp:158
const std::string DID_REC_FIELD_DESCRIPTION_STR
Definition: Record.hpp:127
void SetLimits(ctd::defines::DataType data_type, const std::string &lower_limit, const std::string &upper_limit)
Define (set) the limits for the range.
Definition: Record.cpp:38
std::string m_field_comment
Definition: Record.hpp:251
Class to contain limits for one range.
Definition: Record.hpp:22
std::string m_upper_limit
Definition: Record.hpp:66
Record()
Definition: Record.cpp:111
std::string m_field_name
Definition: Record.hpp:242
DidRecField
Dictionary keyword record field types.
Definition: Record.hpp:100
char m_flag
Definition: Record.hpp:92
std::string m_org_name
Definition: Record.hpp:244
Definition: Record.hpp:107
void GetUpperLimit(TYPE &upper_limit) const
Get the upper limit value.
Definition: Record.hpp:51
Definition: Record.hpp:108
std::string m_field_description
Definition: Record.hpp:253
const std::string & GetAltName() const
Return name of the alternative keyword record (without the optional indeces).
Definition: Record.cpp:257
~Record()
Definition: Record.cpp:131
const std::string DID_REC_FIELD_TYPE_STR
Definition: Record.hpp:120
const std::vector< std::string > & GetTags() const
Get list of the optional tags defined.
Definition: Record.cpp:313
const std::string DID_REC_FIELD_RANGE_STR
Definition: Record.hpp:124
const std::vector< std::string > & GetClasses() const
Get list of classes defined for the record.
Definition: Record.cpp:264
void GetLowerLimit(TYPE &lower_limit) const
Get the lower limit value.
Definition: Record.hpp:43
std::vector< std::string > m_field_classes
Definition: Record.hpp:245
const std::string DID_REC_FIELD_COMMENT_STR
Definition: Record.hpp:125
Definition: Record.hpp:101
std::string m_length
Definition: Record.hpp:95
const std::vector< Range > & GetRanges() const
Get the valid ranges defined for the key.
Definition: Record.cpp:299