Dev Essential
Loading...
Searching...
No Matches
infomodel_base.h
Go to the documentation of this file.
1
14
15#ifndef UTILITIES_INFOMODEL_BASE_H_INCLUDED
16#define UTILITIES_INFOMODEL_BASE_H_INCLUDED
17
21
22#include <memory>
23#include <string>
24#include <unordered_map>
25#include <cstdint>
26
27namespace ddl {
28
29namespace dd {
30
31namespace datamodel {
32
36class IInfo {
37public:
42 virtual ~IInfo() = default;
43
49 virtual uint8_t getInfoType() const = 0;
50};
51
57template <typename INFO_T>
58class Info : public IInfo {
59protected:
66 uint8_t getInfoType() const override
67 {
68 return INFO_T::INFO_TYPE_ID;
69 }
70};
71
76class InfoMap {
77public:
81 InfoMap() = default;
86 InfoMap(const InfoMap&){};
98 {
99 return *this;
100 };
101
107 {
108 return *this;
109 };
110
116 template <typename INFO_T>
117 const INFO_T* getInfo() const
118 {
119 return dynamic_cast<const INFO_T*>(getInfo(INFO_T::INFO_TYPE_ID));
120 }
121
127 template <typename INFO_T>
128 INFO_T* getInfo()
129 {
130 return dynamic_cast<INFO_T*>(getInfo(INFO_T::INFO_TYPE_ID));
131 }
132
139 template <typename INFO_T>
140 void setInfo(const std::shared_ptr<INFO_T>& info)
141 {
142 std::shared_ptr<IInfo> info_downcast = info;
143 if (info_downcast->getInfoType() == INFO_T::INFO_TYPE_ID) {
144 setInfo(info_downcast);
145 }
146 else {
147 throw Error(
148 "InfoMap::setInfo",
149 "Registration not possible, runtime info is differnt then compiletime info");
150 }
151 }
152
153private:
154 IInfo* getInfo(uint8_t info_type)
155 {
156 auto found = _infos.find(info_type);
157 if (found != _infos.end()) {
158 return found->second.get();
159 }
160 else {
161 return nullptr;
162 }
163 }
164 const IInfo* getInfo(uint8_t info_type) const
165 {
166 auto found = _infos.find(info_type);
167 if (found != _infos.cend()) {
168 return found->second.get();
169 }
170 else {
171 return nullptr;
172 }
173 }
174 void setInfo(const std::shared_ptr<IInfo>& info)
175 {
176 _infos[info->getInfoType()] = info;
177 }
178
179#if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
180#pragma GCC diagnostic push
181#pragma GCC diagnostic ignored "-Wattributes"
182#endif // defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
183
184 std::unordered_map<uint8_t, std::shared_ptr<IInfo>> _infos;
185
186#if defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
187#pragma GCC diagnostic pop
188#endif // defined(__GNUC__) && ((__GNUC__ == 5) && (__GNUC_MINOR__ == 2))
189};
190
191} // namespace datamodel
192} // namespace dd
193
194namespace utility {
195 using ::ddl::dd::datamodel::IInfo;
196 using ::ddl::dd::datamodel::Info;
197 using ::ddl::dd::datamodel::InfoMap;
198}
199
200} // namespace ddl
201
202#endif // UTILITIES_INFOMODEL_BASE_H_INCLUDED
Exception helper class to collect information while parsing, adding DD Objects or other failed operat...
Definition ddl_error.h:31
Basic Info interface can be added to the ddl::dd::datamodel::InfoMap.
Definition infomodel_base.h:36
virtual uint8_t getInfoType() const =0
Get the Info Type ID.
virtual ~IInfo()=default
virtual DTOR for IInfo object
InfoMap & operator=(InfoMap &&)
move assignment operator
Definition infomodel_base.h:106
void setInfo(const std::shared_ptr< INFO_T > &info)
Set the Info object as shared pointer.
Definition infomodel_base.h:140
InfoMap(InfoMap &&)
move CTOR
Definition infomodel_base.h:91
INFO_T * getInfo()
Get the Info Pointer.
Definition infomodel_base.h:128
InfoMap & operator=(const InfoMap &)
copy assignment operator
Definition infomodel_base.h:97
InfoMap(const InfoMap &)
copy CTOR
Definition infomodel_base.h:86
const INFO_T * getInfo() const
Get the Info Pointer.
Definition infomodel_base.h:117
Helper template class to create valid IInfo objects.
Definition infomodel_base.h:58
uint8_t getInfoType() const override
Get the Info Type object.
Definition infomodel_base.h:66
Basic Info interface can be added to the ddl::dd::datamodel::InfoMap.
Definition infomodel_base.h:36
definition of the datamodel namespace
Definition datamodel_base.h:28
definition of the dd namespace
Definition datamodel_base.h:26
definition of the utility namespace
Definition ddl.h:66
definition of the ddl namespace
Definition codec.h:21