17#include <trantor/utils/Logger.h>
40 const T &
get(
const std::string &key)
const
42 static const T nullVal = T();
43 auto it = attributesMap_.find(key);
44 if (it != attributesMap_.end())
46 if (
typeid(T) == it->second.type())
48 return *(std::any_cast<T>(&(it->second)));
52 LOG_ERROR <<
"Bad type";
63 return attributesMap_[key];
73 void insert(
const std::string &key,
const std::any &obj)
75 attributesMap_[key] = obj;
85 void insert(
const std::string &key, std::any &&obj)
87 attributesMap_[key] = std::move(obj);
93 void erase(
const std::string &key)
95 attributesMap_.erase(key);
101 bool find(
const std::string &key)
103 if (attributesMap_.find(key) == attributesMap_.end())
115 attributesMap_.clear();
124 using AttributesMap = std::map<std::string, std::any>;
125 AttributesMap attributesMap_;
128using AttributesPtr = std::shared_ptr<Attributes>;
const T & get(const std::string &key) const
Get the data identified by the key parameter.
Definition Attribute.h:40
void clear()
Clear all attributes.
Definition Attribute.h:113
bool find(const std::string &key)
Return true if the data identified by the key exists.
Definition Attribute.h:101
void insert(const std::string &key, std::any &&obj)
Insert a key-value pair.
Definition Attribute.h:85
void insert(const std::string &key, const std::any &obj)
Insert a key-value pair.
Definition Attribute.h:73
Attributes()=default
Constructor, usually called by the framework.
std::any & operator[](const std::string &key)
Get the 'any' object identified by the given key.
Definition Attribute.h:61
void erase(const std::string &key)
Erase the data identified by the given key.
Definition Attribute.h:93
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23