NAWA 0.9
Web Application Framework for C++
Session.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 Tobias Flaig.
3 *
4 * This file is part of nawa.
5 *
6 * nawa is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License,
8 * version 3, as published by the Free Software Foundation.
9 *
10 * nawa is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
17 */
18
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
45 static void destroy();
46
47 public:
49
54 explicit Session(Connection& connection);
55
70 std::string start(std::string sessionId, std::optional<unsigned long> keepalive = std::nullopt);
71
102 void start(nawa::Cookie properties = Cookie());
103
108 [[nodiscard]] bool established() const;
109
117 [[nodiscard]] bool isSet(std::string const& key) const;
118
128 std::any operator[](std::string const& key) const;
129
136 void set(std::string key, const std::any& value);
137
149 void set(std::string key, char const* value) {
150 set(std::move(key), std::make_any<std::string>(value));
151 }
152
163 template<typename T>
164 void set(std::string key, T const& value) {
165 set(std::move(key), std::any(value));
166 }
167
173 void unset(std::string const& key);
174
181 void invalidate();
182
187 [[nodiscard]] std::string getID() const;
188
193 };
194}// namespace nawa
195
196#endif//NAWA_SESSION_H
Structure for creating Cookie objects. Content can be set by using a constructor.
Session(Connection &connection)
Definition: Session.cpp:120
std::any operator[](std::string const &key) const
Definition: Session.cpp:286
void set(std::string key, char const *value)
Definition: Session.h:149
void set(std::string key, const std::any &value)
Definition: Session.cpp:297
std::string start(std::string sessionId, std::optional< unsigned long > keepalive=std::nullopt)
Definition: Session.cpp:127
void invalidate()
Definition: Session.cpp:313
bool established() const
Definition: Session.cpp:274
void set(std::string key, T const &value)
Definition: Session.h:164
friend RequestHandler
Definition: Session.h:192
std::string getID() const
Definition: Session.cpp:332
void unset(std::string const &key)
Definition: Session.cpp:305
bool isSet(std::string const &key) const
Definition: Session.cpp:278
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