Function get

Synopsis

#include <lib/inc/drogon/Attribute.h>

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

Description

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");

Source

Lines 39-56 in lib/inc/drogon/Attribute.h.

template <typename T>
const T &get(const std::string &key) const
{
    const static T nullVal = T();
    auto it = attributesMap_.find(key);
    if (it != attributesMap_.end())
    {
        if (typeid(T) == it->second.type())
        {
            return *(any_cast<T>(&(it->second)));
        }
        else
        {
            LOG_ERROR << "Bad type";
        }
    }
    return nullVal;
}





Add Discussion as Guest

Log in to DocsForge