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 146 of file AttributeInjector.h.

Member Function Documentation

◆ delAttribute()

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

Definition at line 175 of file AttributeInjector.h.

175 {
176 bool deleted = attributes.erase(typeid(Attribute).name() + std::string(key) + subKey) > 0;
177
178 return deleted;
179 }
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 205 of file AttributeInjector.h.

207 {
208 std::map<std::string, std::shared_ptr<void>>::const_iterator it =
209 attributes.find(typeid(Attribute).name() + std::string(key) + subKey);
210
211 if (it != attributes.end()) {
212 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(it->second));
213 } else {
214 onNotFound(std::string(typeid(Attribute).name()) + std::string(key) + subKey);
215 }
216 }

Referenced by main().

Here is the caller graph for this function:

◆ 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 189 of file AttributeInjector.h.

189 {
190 bool found = false;
191
192 std::map<std::string, std::shared_ptr<void>>::const_iterator it =
193 attributes.find(typeid(Attribute).name() + std::string(key) + subKey);
194
195 if (it != attributes.end()) {
196 found = true;
197
198 onFound(**std::static_pointer_cast<AttributeProxy<Attribute>>(it->second));
199 }
200
201 return found;
202 }

◆ hasAttribute()

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

Definition at line 182 of file AttributeInjector.h.

182 {
183 bool found = attributes.find(typeid(Attribute).name() + std::string(key) + subKey) != attributes.end();
184
185 return found;
186 }

◆ reset()

void utils::MultibleAttributeInjector::reset ( )
inline

Definition at line 218 of file AttributeInjector.h.

218 {
219 attributes.clear();
220 }

◆ setAttribute() [1/2]

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

Definition at line 162 of file AttributeInjector.h.

162 {
163 bool inserted = false;
164
165 if (attributes.find(typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
166 attributes[typeid(Attribute).name() + std::string(key) + subKey] =
167 std::shared_ptr<void>(new AttributeProxy<Attribute>(attribute));
168 inserted = true;
169 }
170
171 return inserted;
172 }

◆ setAttribute() [2/2]

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

Definition at line 149 of file AttributeInjector.h.

149 {
150 bool inserted = false;
151
152 if (attributes.find(typeid(Attribute).name() + std::string(key) + subKey) == attributes.end() || overwrite) {
153 attributes[typeid(Attribute).name() + std::string(key) + subKey] =
154 std::shared_ptr<void>(new AttributeProxy<Attribute>(attribute));
155 inserted = true;
156 }
157
158 return inserted;
159 }

Referenced by express::middleware::JsonMiddleware::JsonMiddleware().

Here is the caller graph for this function:

Member Data Documentation

◆ attributes

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

Definition at line 223 of file AttributeInjector.h.


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