drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::Attributes Class Reference

This class represents the attributes stored in the HTTP request. One can add/get any type of data to/from an Attributes object. More...

#include <drogon/Attribute.h>

Public Member Functions

template<typename T>
const T & get (const std::string &key) const
 Get the data identified by the key parameter.
std::any & operator[] (const std::string &key)
 Get the 'any' object identified by the given key.
void insert (const std::string &key, const std::any &obj)
 Insert a key-value pair.
void insert (const std::string &key, std::any &&obj)
 Insert a key-value pair.
void erase (const std::string &key)
 Erase the data identified by the given key.
bool find (const std::string &key)
 Return true if the data identified by the key exists.
void clear ()
 Clear all attributes.
 Attributes ()=default
 Constructor, usually called by the framework.

Detailed Description

This class represents the attributes stored in the HTTP request. One can add/get any type of data to/from an Attributes object.

Member Function Documentation

◆ get()

template<typename T>
const T & drogon::Attributes::get ( const std::string & key) const
inline

Get the data identified by the key parameter.

Note
if the data is not found, a default value is returned. For example:
auto &userName = attributesPtr->get<std::string>("user name");

◆ insert() [1/2]

void drogon::Attributes::insert ( const std::string & key,
const std::any & obj )
inline

Insert a key-value pair.

Note
here the any object can be created implicitly. for example
attributesPtr->insert("user name", userNameString);

◆ insert() [2/2]

void drogon::Attributes::insert ( const std::string & key,
std::any && obj )
inline

Insert a key-value pair.

Note
here the any object can be created implicitly. for example
attributesPtr->insert("user name", userNameString);

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