qmjsontype.h
Go to the documentation of this file.
1 //
2 // QtMark JSON Library
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Rodney Forbes <forbesr@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef QMJSONTYPE_H
23 #define QMJSONTYPE_H
24 
25 // ============================================================================
26 // Libraries
27 // ============================================================================
28 
29 #include <qmjsonfeatures.h>
30 
31 #include <QtCore>
32 
33 #if defined(QM_JSON_LIBRARY)
34 #define QM_JSON_EXPORT Q_DECL_EXPORT
35 #else
36 #define QM_JSON_EXPORT Q_DECL_IMPORT
37 #endif
38 
39 #include <qmpointer.h>
40 
41 // ============================================================================
42 // Enums
43 // ============================================================================
44 
46 {
54 };
55 
57 {
60 };
61 
63 {
66 };
67 
69 {
73 };
74 
76 {
79 };
80 
81 // ============================================================================
82 // Conversions
83 // ============================================================================
84 
85 inline Qt::CaseSensitivity convertQMJsonSort(QMJsonSort sort)
86 {
87  switch(sort)
88  {
89  case QMJsonSort_None:
91  return Qt::CaseInsensitive;
92 
94  return Qt::CaseSensitive;
95  }
96 
97  return Qt::CaseInsensitive;
98 }
99 
100 // ============================================================================
101 // Class Prototypes
102 // ============================================================================
103 
104 class QMJsonValue;
105 class QMJsonObject;
106 
107 // ============================================================================
108 // Base Type
109 // ============================================================================
110 
112 {
113 public:
114 
116  virtual ~QMJsonTypeBase() {}
117 
118  virtual QDebug print(QDebug dbg) = 0;
119  virtual bool isBaseType(void) = 0;
120 
121  virtual QString toJson(int32_t tab, QMJsonSort sort) = 0;
122  virtual void toComplexJson(const QMPointer<QMJsonObject> &obj) = 0;
123 };
124 
125 // ============================================================================
126 // Class Definition
127 // ============================================================================
128 
129 template <class T>
131 {
132 
133 public:
134 
135  QMJsonType(T value);
136  virtual ~QMJsonType();
137 
138  virtual void set(const T &value);
139  virtual const T &get(void);
140 
141  virtual QDebug print(QDebug dbg);
142  virtual bool isBaseType(void);
143 
144  virtual QString toJson(int32_t tab, QMJsonSort sort);
145  static QMPointer<QMJsonValue> fromJson(const QString &json, int32_t &index);
146 
147  virtual void toComplexJson(const QMPointer<QMJsonObject> &obj);
148  static QMPointer<QMJsonValue> fromComplexJson(const QMPointer<QMJsonObject> &obj);
149 
150 private:
151 
152  T mValue;
153 };
154 
155 // ============================================================================
156 // Class Implementation
157 // ============================================================================
158 
159 template <class T>
161  mValue(value)
162 {
163 }
164 
165 template <class T>
167 {
168 }
169 
170 template <class T>
171 void QMJsonType<T>::set(const T &value)
172 {
173  mValue = value;
174 }
175 
176 template <class T>
177 const T &QMJsonType<T>::get(void)
178 {
179  return mValue;
180 }
181 
182 template <class T>
183 QDebug QMJsonType<T>::print(QDebug dbg)
184 {
185  return dbg << mValue;
186 }
187 
188 template <class T>
189 QString QMJsonType<T>::toJson(int32_t tab, QMJsonSort sort)
190 {
191  (void) tab;
192  (void) sort;
193 
194  return QString();
195 }
196 
197 template <class T>
198 QMPointer<QMJsonValue> QMJsonType<T>::fromJson(const QString &json, int32_t &index)
199 {
200  (void) json;
201  (void) index;
202 
203  return QMPointer<QMJsonValue>();
204 }
205 
206 template <class T>
207 void QMJsonType<T>::toComplexJson(const QMPointer<QMJsonObject> &obj)
208 {
209  (void) obj;
210 }
211 
212 template <class T>
214 {
215  return false;
216 }
217 
218 #endif // QMJSONTYPE_H
virtual QString toJson(int32_t tab, QMJsonSort sort)
Definition: qmjsontype.h:189
#define QM_JSON_EXPORT
Definition: qmjsontype.h:36
QMJsonReplacementPolicy
Definition: qmjsontype.h:56
QMJsonArrayUnitePolicy
Definition: qmjsontype.h:75
virtual const T & get(void)
Definition: qmjsontype.h:177
QMJsonFormat
Definition: qmjsontype.h:62
virtual void set(const T &value)
Definition: qmjsontype.h:171
virtual QDebug print(QDebug dbg)
Definition: qmjsontype.h:183
static QMPointer< QMJsonValue > fromJson(const QString &json, int32_t &index)
Definition: qmjsontype.h:198
QMJsonType(T value)
Definition: qmjsontype.h:160
virtual bool isBaseType(void)
Definition: qmjsontype.h:213
virtual ~QMJsonType()
Definition: qmjsontype.h:166
QMJsonValueType
Definition: qmjsontype.h:45
virtual ~QMJsonTypeBase()
Definition: qmjsontype.h:116
QMJsonSort
Definition: qmjsontype.h:68
Qt::CaseSensitivity convertQMJsonSort(QMJsonSort sort)
Definition: qmjsontype.h:85
static QMPointer< QMJsonValue > fromComplexJson(const QMPointer< QMJsonObject > &obj)
virtual void toComplexJson(const QMPointer< QMJsonObject > &obj)
Definition: qmjsontype.h:207