Function get

Synopsis

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

template <typename T>
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 = sessionPtr->get<std::string>("user name");

Source

Lines 43-62 in lib/inc/drogon/Session.h.

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





Add Discussion as Guest

Log in