Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
iserializer.h
Go to the documentation of this file.
1 /* Libmacro - A multi-platform, extendable macro and hotkey C library
2  Copyright (C) 2013 Jonathan Pelletier, New Paradigm Software
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
23 #ifndef MCR_EXTRAS_ISERIALIZER_H_
24 #define MCR_EXTRAS_ISERIALIZER_H_
25 #ifndef MCR_NOQT
26 
27 #include <QString>
28 #include <QVariant>
29 
30 #include "mcr/extras/base_cpp.h"
31 
32 namespace mcr
33 {
35 class MCR_API ISerializer
36 {
37 public:
42  typedef ISerializer *(*get)();
43 
45 
46  virtual size_t keyCount(bool canonical) const = 0;
47  virtual QString *keysArray(bool canonical) const = 0;
49  virtual QVariant value(const QString &name) const = 0;
50  virtual void setValue(const QString &name, const QVariant &val) = 0;
51 
52  /* Helper functions */
53  inline QStringList keys(bool canonical) const
54  {
55  QStringList ret;
56  auto ptr = keysArray(canonical);
57  for (int i = 0; i < (int)keyCount(canonical); i++) {
58  ret.insert(i, ptr[i]);
59  }
60  return ret;
61  }
62 
63  inline ISerializer &build(const QString &name, const QVariant &val)
64  {
65  setValue(name, val);
66  return *this;
67  }
68 
72  inline QVariantMap values(bool canonical)
73  {
74  QVariantMap ret;
75  auto kz = keys(canonical);
76  for (auto &i: kz) {
77  ret.insert(i, value(i));
78  }
79  return ret;
80  }
82  inline void setValues(const QVariantMap &vals)
83  {
84  for (auto &z: vals.keys()) {
85  setValue(z, vals.value(z));
86  }
87  }
88 };
89 }
90 
91 #endif
92 #endif
void setValues(const QVariantMap &vals)
Set all values of the object (Deserialize)
Definition: iserializer.h:82
#define MCR_DECL_INTERFACE(className)
Definition: defines.h:434
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31
QVariantMap values(bool canonical)
Get all values of the object (Serialize)
Definition: iserializer.h:72
Get/Set all values of an object.
Definition: iserializer.h:35