NAWA 0.8
Web Application Framework for C++
Session.h
Go to the documentation of this file.
1
6/*
7 * Copyright (C) 2019-2021 Tobias Flaig.
8 *
9 * This file is part of nawa.
10 *
11 * nawa is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License,
13 * version 3, as published by the Free Software Foundation.
14 *
15 * nawa is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef NAWA_SESSION_H
25#define NAWA_SESSION_H
26
27#include <any>
28#include <memory>
32
33namespace nawa {
37 class Session {
39
40 public:
42
47 explicit Session(Connection& connection);
48
79 void start(nawa::Cookie properties = Cookie());
80
85 [[nodiscard]] bool established() const;
86
94 [[nodiscard]] bool isSet(std::string const& key) const;
95
105 std::any operator[](std::string const& key) const;
106
113 void set(std::string key, const std::any& value);
114
126 void set(std::string key, char const* value) {
127 set(std::move(key), std::make_any<std::string>(value));
128 }
129
140 template<typename T>
141 void set(std::string key, T const& value) {
142 set(std::move(key), std::any(value));
143 }
144
150 void unset(std::string const& key);
151
158 void invalidate();
159
164 [[nodiscard]] std::string getID() const;
165 };
166}// namespace nawa
167
168#endif//NAWA_SESSION_H
Structure for creating Cookie objects. Content can be set by using a constructor.
Session(Connection &connection)
Definition: Session.cpp:119
std::string getID() const
Definition: Session.cpp:303
void start(nawa::Cookie properties=Cookie())
Definition: Session.cpp:126
void set(std::string key, char const *value)
Definition: Session.h:126
void set(std::string key, const std::any &value)
Definition: Session.cpp:268
std::any operator[](std::string const &key) const
Definition: Session.cpp:257
void invalidate()
Definition: Session.cpp:284
bool established() const
Definition: Session.cpp:245
void set(std::string key, T const &value)
Definition: Session.h:141
void unset(std::string const &key)
Definition: Session.cpp:276
bool isSet(std::string const &key) const
Definition: Session.cpp:249
Forward declarations.
Macros for frequently used patterns.
#define NAWA_DEFAULT_DESTRUCTOR_DEF(Class)
Definition: macros.h:34
#define NAWA_PRIVATE_DATA()
Definition: macros.h:30
Definition: AppInit.h:31