TreeFrogFramework  2.8
tsession.h
Go to the documentation of this file.
1 #pragma once
2 #include <QByteArray>
3 #include <QVariant>
4 #include <TGlobal>
5 
6 
7 class T_CORE_EXPORT TSession : public QVariantMap {
8 public:
9  TSession(const QByteArray &id = QByteArray());
10  TSession(const TSession &other);
11  TSession &operator=(const TSession &other);
12 
13  QByteArray id() const { return sessionId; }
14  void reset();
15  iterator insert(const QString &key, const QVariant &value);
16  int remove(const QString &key);
17  QVariant take(const QString &key);
18  const QVariant value(const QString &key) const;
19  const QVariant value(const QString &key, const QVariant &defaultValue) const;
20  static QByteArray sessionName();
21 
22 private:
23  QByteArray sessionId;
24 
25  void clear(); // disabled
26  friend class TSessionCookieStore;
27  friend class TActionContext;
28 };
29 
30 
31 inline TSession::TSession(const QByteArray &id) :
32  sessionId(id)
33 {
34 }
35 
36 inline TSession::TSession(const TSession &other) :
37  QVariantMap(*static_cast<const QVariantMap *>(&other)), sessionId(other.sessionId)
38 {
39 }
40 
41 inline TSession &TSession::operator=(const TSession &other)
42 {
43  QVariantMap::operator=(*static_cast<const QVariantMap *>(&other));
44  sessionId = other.sessionId;
45  return *this;
46 }
47 
48 inline TSession::iterator TSession::insert(const QString &key, const QVariant &value)
49 {
50  return QVariantMap::insert(key, value);
51 }
52 
53 inline int TSession::remove(const QString &key)
54 {
55  return QVariantMap::remove(key);
56 }
57 
58 inline QVariant TSession::take(const QString &key)
59 {
60  return QVariantMap::take(key);
61 }
62 
63 inline const QVariant TSession::value(const QString &key) const
64 {
65  return QVariantMap::value(key);
66 }
67 
68 inline const QVariant TSession::value(const QString &key, const QVariant &defaultValue) const
69 {
70  return QVariantMap::value(key, defaultValue);
71 }
72 
The TSession class holds information associated with individual visitors.
Definition: tsession.h:7
TSession & operator=(const TSession &other)
Definition: tsession.h:41
QVariant take(const QString &key)
Definition: tsession.h:58
TSession(const QByteArray &id=QByteArray())
Constructs a empty session with the ID id.
Definition: tsession.h:31
const QVariant value(const QString &key) const
Returns the value associated with the key.
Definition: tsession.h:63
int remove(const QString &key)
Definition: tsession.h:53
iterator insert(const QString &key, const QVariant &value)
Inserts a new item with the key and a value of value.
Definition: tsession.h:48
QByteArray id() const
Returns the ID.
Definition: tsession.h:13
#define T_CORE_EXPORT
Definition: tdeclexport.h:28