ifw-core  5.0.0-pre2
did.hpp
Go to the documentation of this file.
1 
6 #ifndef IFW_DIT_DID_HPP_
7 #define IFW_DIT_DID_HPP_
8 
9 #include <limits.h>
10 
11 #include <string>
12 
13 #include <core/dit/did/header.hpp>
14 #include <core/dit/did/record.hpp>
15 
16 namespace core::dit::did
17 {
18 
20  typedef enum
21  {
22  NONE = 0,
25  ALL
27 
31  class Did
32  {
33  public:
44  static std::string SubstituteIndeces(const std::string &key);
45 
55  static std::string SubstituteIndex(const std::string &key);
56 
57  Did();
58 
59  ~Did();
60 
73  void Load(const std::string &did_filename, const bool clear = false);
74 
76  void Clear();
77 
79  const std::vector<std::string> &GetDidsLoaded() const;
80 
82  const std::vector<std::string> &GetDidsLoadedCompletePath() const;
83 
85  const std::vector<dit::did::Header> &GetHeaders() const;
86 
88  bool HasRecord(const std::string &pattern, const bool allow_idx_subst = true) const;
89 
100  bool LookUp(const std::string &pattern,
101  dit::did::Record &record,
102  const bool allow_idx_subst = true,
103  const bool exception = true) const;
104 
115  bool LookUp(const std::string &pattern,
116  std::vector<dit::did::Record> &records,
117  const bool allow_idx_subst = true,
118  const bool exception = false) const;
119 
121  void GetKeys(std::vector<std::string> &keys) const;
122 
129  std::string ToString(HdrSpec header = HdrSpec::LAST,
130  const std::string &pattern = "",
131  const bool compact = false) const;
132 
134  friend std::ostream &operator<<(std::ostream &os, const Did &did);
135 
136  private:
137  std::unique_ptr<elt::configng::CiiConfigDocument> m_did_doc;
138 
139  // List of dictionaries (filenames) currently loaded
140  // (m_dids_loaded[0] = first DID loaded).
141  std::vector<std::string> m_dids_loaded;
142  std::vector<std::string> m_dids_loaded_complete_path;
143 
144  // Maps dictionary filename into the header of that dictionary.
145  std::vector<dit::did::Header> m_headers;
146 
147  // Maps keyword names into keyword records.
148  std::map<std::string, dit::did::Record> m_records;
149 
150  // Map with alternative keyword names for keys with optional indeces.
151  std::map<std::string, dit::did::Record *> m_alt_records;
152 
153  int16_t _LookUp(const std::string &pattern,
154  std::vector<dit::did::Record> &records,
155  const bool allow_idx_subst,
156  const bool exception,
157  const int16_t max_records) const;
158  };
159 
160 } // namespace core::dit::did
161 
162 #endif // !IFW_DIT_DID_HPP_
Data Interface Dictionary class.
Definition: did.hpp:32
std::string ToString(HdrSpec header=HdrSpec::LAST, const std::string &pattern="", const bool compact=false) const
Create a DID from the content in the object in a string buffer.
Definition: did.cpp:302
bool LookUp(const std::string &pattern, dit::did::Record &record, const bool allow_idx_subst=true, const bool exception=true) const
Look up a key in the DIDs loaded. First occurrence taken.
Definition: did.cpp:218
~Did()
Definition: did.cpp:71
friend std::ostream & operator<<(std::ostream &os, const Did &did)
Dump the contents of the class on the output stream.
Definition: did.cpp:383
bool HasRecord(const std::string &pattern, const bool allow_idx_subst=true) const
Check if a record, is contained in the object.
Definition: did.cpp:212
static std::string SubstituteIndex(const std::string &key)
Substitutes a numeric index of a keyword to obtain the generic representation.
Definition: did.cpp:12
const std::vector< std::string > & GetDidsLoaded() const
Get the filenames of the DIDs, currently loaded (el [0] = first DID loaded).
Definition: did.cpp:197
void Clear()
Clear the object.
Definition: did.cpp:75
static std::string SubstituteIndeces(const std::string &key)
Substitutes numeric indeces of keyword components to the generic representation.
Definition: did.cpp:31
const std::vector< dit::did::Header > & GetHeaders() const
Get the header objects for the DIDs loaded (el [0] = first DID loaded).
Definition: did.cpp:207
const std::vector< std::string > & GetDidsLoadedCompletePath() const
Get the complete filenames of the DIDs, currently loaded (el [0] = first DID loaded).
Definition: did.cpp:202
void Load(const std::string &did_filename, const bool clear=false)
Load the referenced dictionary.
Definition: did.cpp:83
bool LookUp(const std::string &pattern, std::vector< dit::did::Record > &records, const bool allow_idx_subst=true, const bool exception=false) const
LookUp Scan the dictionary for keys with the given regular expression pattern.
void GetKeys(std::vector< std::string > &keys) const
Generate list of keys defined.
Definition: did.cpp:389
Did()
Definition: did.cpp:67
Data Interface Dictionary keyword record class.
Definition: record.hpp:46
Definition: defines.cpp:11
HdrSpec
Used to refer to which header(s) to address.
Definition: did.hpp:21
@ FIRST
Definition: did.hpp:23
@ NONE
Definition: did.hpp:22
@ LAST
Definition: did.hpp:24
@ ALL
Definition: did.hpp:25