LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qtjsonabstract.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef QTJSONABSTRACT_H_
23 #define QTJSONABSTRACT_H_
24 
25 #include <QString>
26 #include <cjson/json.h>
27 #include <QList>
28 #include <QVariant>
29 #include <QDataStream>
30 #include <QDebug>
31 
33 {
34 
35 public:
36 
37  QtJsonAbstract * add(const QString& k, qint32 v);
38  QtJsonAbstract * add(const QString& k, qreal v);
39  QtJsonAbstract * add(const QString& k, bool v);
40  QtJsonAbstract * add(const QString& k, const QString& v);
41  QtJsonAbstract * add(const QString& k, const QList<QVariant>& a);
42  QtJsonAbstract * add(const QString& k, const QtJsonAbstract& object);
43  static QtJsonAbstract * add(QtJsonAbstract * p_target,const QString& k, const QList<QVariant>& a);
44 
45  QVariant extract(const QString& k) const;
46  QList<QPair<QString,QVariant> > extractAll() const;
47  typedef QList<QPair<QString,QVariant> > ContentsList;
48  typedef QList<QPair<QString,QVariant> >::iterator ContentsListIterator;
49  typedef QList<QPair<QString,QVariant> >::const_iterator ContentsListConstIterator;
50 
51  QtJsonAbstract * clone() const;
52  QString toString();
53 
54  static QtJsonAbstract * create();
55  static QtJsonAbstract * jsonParse(const QString& s);
56  static QtJsonAbstract * jsonParseFromStream(QDataStream& stream);
57 
58  static void throwAway(QtJsonAbstract * p_object);
59 
60  mutable json_object * o;
61 
62  friend QDataStream& operator<<(QDataStream &, const QtJsonAbstract& );
63  friend QDataStream& operator>>(QDataStream &, QtJsonAbstract& );
64  friend QDebug& operator<<(QDebug& , const QtJsonAbstract& );
65 
66 private:
67  QtJsonAbstract() : o(0) {}
68  QtJsonAbstract(json_object * obj) : o(obj) {}
70  QtJsonAbstract& operator=(const QtJsonAbstract& c);
71  ~QtJsonAbstract();
72 
73  static json_object * _array(const QList<QVariant>& a);
74  static QVariant _extractArray(json_object * p_o);
75 };
76 
77 QDataStream& operator<<(QDataStream &, const QtJsonAbstract& );
78 QDataStream& operator>>(QDataStream &, QtJsonAbstract& );
79 
80 QDebug& operator<<(QDebug& , const QtJsonAbstract& );
81 
83 {
84 public:
85 
91 
93 
94  friend QDataStream& operator<<(QDataStream &, const QtJsonAbstractVariant& );
95  friend QDataStream& operator>>(QDataStream &, QtJsonAbstractVariant& );
96  friend QDebug& operator<<(QDebug& dbg, const QtJsonAbstractVariant& );
97 
99  return s_initObject;
100  }
101 
102 private:
103  QtJsonAbstractVariant(bool init);
104  static QtJsonAbstractVariant s_initObject;
105 
106 };
107 QDataStream& operator<<(QDataStream &, const QtJsonAbstractVariant& );
108 QDataStream& operator>>(QDataStream &, QtJsonAbstractVariant& );
109 QDebug& operator<<(QDebug& , const QtJsonAbstractVariant& );
110 
111 Q_DECLARE_METATYPE(QtJsonAbstractVariant)
112 
113 static const QtJsonAbstractVariant initVariantTypeObject = QtJsonAbstractVariant::initMetaType();
114 
115 #endif /* QTJSONABSTRACT_H_ */