File: DBusTestData.hh

package info (click to toggle)
workrave 1.10.54-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,004 kB
  • sloc: cpp: 46,596; ansic: 9,760; sh: 2,754; javascript: 1,935; makefile: 1,452; python: 973; xml: 672; objc: 455; perl: 113; cs: 70; sed: 16
file content (175 lines) | stat: -rw-r--r-- 4,123 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Test.hh
//
// Copyright (C) 2013 Rob Caelers & Raymond Penners
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef DBUSTESTDATA_HH
#define DBUSTESTDATA_HH

#include <string>
#include <set>

#ifdef DBUS_BACKEND_QT
#  include <QDBusArgument>
#  include <QMetaType>
#endif

class DBusTestData
{
public:
  enum Enum
  {
    ONE,
    TWO,
    THREE,
    FOUR,
    FIVE,
  };

  struct StructWithAllBasicTypes
  {
    int m_int;
    uint8_t m_uint8;
    int16_t m_int16;
    uint16_t m_uint16;
    int32_t m_int32;
    uint32_t m_uint32;
    int64_t m_int64;
    uint64_t m_uint64;
    std::string m_string;
    bool m_bool;
    double m_double;
    Enum m_enum;
  };

  struct StructWithAllBasicTypesReorder
  {
    int m_int;
    uint8_t m_uint8;
    int16_t m_int16;
    uint16_t m_uint16;
    std::string m_string;
    int32_t m_int32;
    uint32_t m_uint32;
    int64_t m_int64;
    uint64_t m_uint64;
    bool m_bool;
    double m_double;
    Enum m_enum;
  };

  typedef std::list<StructWithAllBasicTypes> ListOfStructWithAllBasicTypes;
  typedef std::map<std::string, StructWithAllBasicTypes> MapOfStructWithAllBasicTypes;

  struct Data
  {
    Data()
      : m_key(0)
      , m_data(0)
    {
    }
    Data(int k, int d)
      : m_key(k)
      , m_data(d)
    {
    }

    bool operator==(const Data &other) const { return m_key == other.m_key && m_data == other.m_data; }

    int m_key;
    int m_data;
  };

  typedef std::map<std::string, Data> DataMap;
  typedef std::list<Data> DataList;

  typedef std::map<std::string, std::string> StringMap;
  typedef std::list<std::string> StringList;

  static std::string enum_to_str(DBusTestData::Enum value)
  {
    std::string ret;

    switch (value)
      {
      case DBusTestData::ONE:
        ret = "one";
        break;
      case DBusTestData::TWO:
        ret = "two";
        break;
      case DBusTestData::THREE:
        ret = "three";
        break;
      case DBusTestData::FOUR:
        ret = "four";
        break;
      case DBusTestData::FIVE:
        ret = "five";
        break;
      }

    return ret;
  }

  static Enum str_to_enum(const std::string &value)
  {
    Enum ret = DBusTestData::ONE;
    if ("one" == value)
      {
        ret = DBusTestData::ONE;
      }
    else if ("two" == value)
      {
        ret = DBusTestData::TWO;
      }
    else if ("three" == value)
      {
        ret = DBusTestData::THREE;
      }
    else if ("four" == value)
      {
        ret = DBusTestData::FOUR;
      }
    else if ("five" == value)
      {
        ret = DBusTestData::FIVE;
      }

    return ret;
  }

  DBusTestData();
  virtual ~DBusTestData();
};

#ifdef DBUS_BACKEND_QT
Q_DECLARE_METATYPE(DBusTestData::StructWithAllBasicTypes)
Q_DECLARE_METATYPE(DBusTestData::StructWithAllBasicTypesReorder)
Q_DECLARE_METATYPE(DBusTestData::Data)

QDBusArgument &operator<<(QDBusArgument &argument, const DBusTestData::StructWithAllBasicTypes &message);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusTestData::StructWithAllBasicTypes &message);

QDBusArgument &operator<<(QDBusArgument &argument, const DBusTestData::StructWithAllBasicTypesReorder &message);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusTestData::StructWithAllBasicTypesReorder &message);

QDBusArgument &operator<<(QDBusArgument &argument, const DBusTestData::Data &message);
const QDBusArgument &operator>>(const QDBusArgument &argument, DBusTestData::Data &message);
#endif

#endif // DBUSTESTDATA_HH