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