Nuria Framework - Core
Core module of the NuriaProject Framework
 All Classes Functions Typedefs Enumerations Enumerator Groups
session.hpp
1 /* Copyright (c) 2014, The Nuria Project
2  * This software is provided 'as-is', without any express or implied
3  * warranty. In no event will the authors be held liable for any damages
4  * arising from the use of this software.
5  * Permission is granted to anyone to use this software for any purpose,
6  * including commercial applications, and to alter it and redistribute it
7  * freely, subject to the following restrictions:
8  * 1. The origin of this software must not be misrepresented; you must not
9  * claim that you wrote the original software. If you use this software
10  * in a product, an acknowledgment in the product documentation would be
11  * appreciated but is not required.
12  * 2. Altered source versions must be plainly marked as such, and must not be
13  * misrepresented as being the original software.
14  * 3. This notice may not be removed or altered from any source
15  * distribution.
16  */
17 
18 #ifndef NURIA_SESSION_HPP
19 #define NURIA_SESSION_HPP
20 
21 #include "essentials.hpp"
22 
23 #include <QSharedData>
24 #include <QVariant>
25 
26 namespace Nuria {
27 
28 class AbstractSessionManager;
29 class SessionPrivate;
30 class Session;
31 
32 NURIA_CORE_EXPORT bool operator== (const Session &a, const Session &b);
33 NURIA_CORE_EXPORT bool operator!= (const Session &a, const Session &b);
34 
45 class NURIA_CORE_EXPORT Session {
46 public:
48  Session ();
49 
51  Session (const Session& other);
52 
54  Session &operator= (const Session &other);
55 
57  ~Session ();
58 
60  bool isValid () const;
61 
63  QByteArray id () const;
64 
69  AbstractSessionManager *manager () const;
70 
72  bool isDirty () const;
73 
79  void markDirty ();
80 
87  void markClean ();
88 
90  void remove ();
91 
101  int refCount () const;
102 
109  QVariant value (const QString &key) const;
110 
112  bool contains (const QString &key) const;
113 
122  QVariant &operator[] (const QString &key);
123 
125  QVariant operator[] (const QString &key) const;
126 
127 
128 private:
129  friend class AbstractSessionManager;
130  friend bool operator== (const Session &a, const Session &b);
131  friend bool operator!= (const Session &a, const Session &b);
132 
136  Session (const QByteArray &id, AbstractSessionManager *manager);
137 
138  QExplicitlySharedDataPointer< SessionPrivate > d;
139 };
140 
141 } // namespace Nuria
142 
143 Q_DECLARE_METATYPE(Nuria::Session)
144 
145 #endif // NURIA_SESSION_HPP
Interface for a session manager.
Definition: abstractsessionmanager.hpp:55
A data storage managed by an AbstractSessionManager.
Definition: session.hpp:45