SNode.C
Loading...
Searching...
No Matches
utils::MultibleAttributeInjector Class Reference

#include <AttributeInjector.h>

Inheritance diagram for utils::MultibleAttributeInjector:
Collaboration diagram for utils::MultibleAttributeInjector:

Public Member Functions

template<InjectableAttribute Attribute, fixed_string key = "">
constexpr bool setAttribute (const Attribute &attribute, const std::string &subKey="", bool overwrite=false)
 
template<InjectableAttribute Attribute, fixed_string key = "">
constexpr bool setAttribute (const Attribute &&attribute, const std::string &subKey="", bool overwrite=false)
 
template<InjectableAttribute Attribute, fixed_string key = "">
constexpr bool delAttribute (const std::string &subKey="")
 
template<InjectableAttribute Attribute, fixed_string key = "">
constexpr bool hasAttribute (const std::string &subKey="") const
 
template<InjectableAttribute Attribute, fixed_string key = "">
bool getAttribute (const std::function< void(Attribute &)> &onFound, const std::string &subKey="") const
 
template<InjectableAttribute Attribute, fixed_string key = "">
void getAttribute (const std::function< void(Attribute &)> &onFound, const std::function< void(const std::string &)> &onNotFound, const std::string &subKey="") const
 
void reset ()
 

Private Attributes

std::map< std::string, std::shared_ptr< void > > attributes
 

Detailed Description

Definition at line 124 of file AttributeInjector.h.

Member Function Documentation

◆ delAttribute()

template<InjectableAttribute Attribute, fixed_string key = "">
bool utils::MultibleAttributeInjector::delAttribute ( const std::string & subKey = "")
inlineconstexpr

Definition at line 153 of file AttributeInjector.h.

153 {
154 bool deleted = attributes.erase(typeid(Attribute).name() + std::string(key) + subKey) > 0;
155
156 return deleted;
157 }
std::map< std::string, std::shared_ptr< void > > attributes

◆ getAttribute() [1/2]

template<InjectableAttribute Attribute, fixed_string key = "">
void utils::MultibleAttributeInjector::getAttribute ( const std::function< void(Attribute &)> & onFound,
const std::function< void(const std::string &)> & onNotFound,
const std::string & subKey = "" ) const
inline

Definition at line 183 of file AttributeInjector.h.

185 {
186 std::map<std::string, std::shared_ptr<void>>::const_iterator it =
187 attributes.find(typeid(Attribute).name() + std::string(key) + subKey);
188
189 if (it != attributes.end()) {
190 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(it->second));
191 } else {
192 onNotFound(std::string(typeid(Attribute).name()) + std::string(key) + subKey);
193 }
194 }

◆ getAttribute() [2/2]

template<InjectableAttribute Attribute, fixed_string key = "">
bool utils::MultibleAttributeInjector::getAttribute ( const std::function< void(Attribute &)> & onFound,
const std::string & subKey = "" ) const
inline

Definition at line 167 of file AttributeInjector.h.

167 {
168 bool found = false;
169
170 std::map<std::string, std::shared_ptr<void>>::const_iterator it =
171 attributes.find(typeid(Attribute).name() + std::string(key) + subKey);
172
173 if (it != attributes.end()) {
174 found = true;
175
176 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(it->second));
177 }
178
179 return found;
180 }

◆ hasAttribute()

template<InjectableAttribute Attribute, fixed_string key = "">
bool utils::MultibleAttributeInjector::hasAttribute ( const std::string & subKey = "") const
inlineconstexpr

Definition at line 160 of file AttributeInjector.h.

160 {
161 bool found = attributes.find(typeid(Attribute).name() + std::string(key) + subKey) != attributes.end();
162
163 return found;
164 }

◆ reset()

void utils::MultibleAttributeInjector::reset ( )
inline

Definition at line 196 of file AttributeInjector.h.

196 {
197 attributes.clear();
198 }

◆ setAttribute() [1/2]

template<InjectableAttribute Attribute, fixed_string key = "">
bool utils::MultibleAttributeInjector::setAttribute ( const Attribute && attribute,
const std::string & subKey = "",
bool overwrite = false )
inlineconstexpr

Definition at line 140 of file AttributeInjector.h.

140 {
141 bool inserted = false;
142
143 if (attributes.find(typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
144 attributes[typeid(Attribute).name() + std::string(key) + subKey] =
145 std::shared_ptr<void>(new AttributeProxy<Attribute>(attribute));
146 inserted = true;
147 }
148
149 return inserted;
150 }

◆ setAttribute() [2/2]

template<InjectableAttribute Attribute, fixed_string key = "">
bool utils::MultibleAttributeInjector::setAttribute ( const Attribute & attribute,
const std::string & subKey = "",
bool overwrite = false )
inlineconstexpr

Definition at line 127 of file AttributeInjector.h.

127 {
128 bool inserted = false;
129
130 if (attributes.find(typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
131 attributes[typeid(Attribute).name() + std::string(key) + subKey] =
132 std::shared_ptr<void>(new AttributeProxy<Attribute>(attribute));
133 inserted = true;
134 }
135
136 return inserted;
137 }

Member Data Documentation

◆ attributes

std::map<std::string, std::shared_ptr<void> > utils::MultibleAttributeInjector::attributes
private

Definition at line 201 of file AttributeInjector.h.


The documentation for this class was generated from the following file: