aboutsummaryrefslogtreecommitdiff
path: root/qt/common/containers/basics/test.hxx
blob: ad7442ce996e69315b91368b9000d3154d620dce (plain)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// file      : qt/common/containers/basics/test.hxx
// copyright : Copyright (c) 2009-2017 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

#ifndef TEST_HXX
#define TEST_HXX

#include <QtCore/QString>
#include <QtCore/QVector>
#include <QtCore/QList>
#include <QtCore/QLinkedList>
#include <QtCore/QSet>
#include <QtCore/QMap>
#include <QtCore/QMultiMap>
#include <QtCore/QHash>
#include <QtCore/QMultiHash>

#include <odb/core.hxx>

#pragma db value
struct comp
{
  comp () {}
  comp (int n, const QString& s) : num (n), str (s) {}

  #pragma db column("number")
  int num;
  QString str;
};

inline bool
operator== (const comp& x, const comp& y)
{
  return x.num == y.num && x.str == y.str;
}

inline bool
operator< (const comp& x, const comp& y)
{
  return x.num != y.num ? x.num < y.num : x.str < y.str;
}

typedef QVector<int> num_vector;
typedef QVector<QString> str_vector;
typedef QVector<comp> comp_vector;

typedef QList<int> num_list;
typedef QList<QString> str_list;
typedef QList<comp> comp_list;

typedef QLinkedList<int> num_linked_list;
typedef QLinkedList<QString> str_linked_list;
typedef QLinkedList<comp> comp_linked_list;

typedef QSet<int> num_set;
typedef QSet<QString> str_set;

typedef QMap<int, QString> num_str_map;
typedef QMap<QString, int> str_num_map;
typedef QMap<int, comp> num_comp_map;
typedef QMap<comp, QString> comp_str_map;

typedef QMultiMap<int, QString> num_str_multimap;
typedef QMultiMap<QString, int> str_num_multimap;
typedef QMultiMap<int, comp> num_comp_multimap;

typedef QHash<int, QString> num_str_hash;
typedef QHash<QString, int> str_num_hash;
typedef QHash<QString, comp> str_comp_hash;

typedef QMultiHash<int, QString> num_str_multihash;
typedef QMultiHash<QString, int> str_num_multihash;
typedef QMultiHash<int, comp> num_comp_multihash;

#pragma db value
struct cont_comp1
{
  // This composite value does not have any columns.
  //
  num_vector sv; // Have the name "conflict" with the one in the object.
};

#pragma db value
struct cont_comp2
{
  cont_comp2 (): num (777), str ("ggg") {}

  int num;
  str_list sl;
  QString str;
};

#pragma db object
struct object
{
  object (): nv (comp1_.sv), sl (comp2_.sl) {}
  object (const QString& id) : id_ (id), nv (comp1_.sv), sl (comp2_.sl) {}

  #pragma db id
  QString id_;

  int num;

  cont_comp1 comp1_;
  cont_comp2 comp2_;

  // vector
  //
  #pragma db transient
  num_vector& nv;

  #pragma db table("object_strings") id_column ("obj_id")
  str_vector sv;

  #pragma db value_column("")
  comp_vector cv;

  #pragma db unordered
  num_vector uv;

  // list
  //
  #pragma db transient
  str_list& sl;

  num_list nl;
  comp_list cl;

  // linked list
  //
  str_linked_list sll;
  num_linked_list nll;
  comp_linked_list cll;

  // set
  //
  num_set ns;
  str_set ss;

  // map
  //
  num_str_map nsm;
  str_num_map snm;
  num_comp_map ncm;
  comp_str_map csm;

  // multimap
  //
  num_str_multimap nsmm;
  str_num_multimap snmm;
  num_comp_multimap ncmm;

  // hash
  //
  num_str_hash nsh;
  str_num_hash snh;
  str_comp_hash sch;

  // multihash
  //
  num_str_multihash nsmh;
  str_num_multihash snmh;
  num_comp_multihash ncmh;

  QString str;
};

inline bool
operator== (const object& x, const object& y)
{
  if (x.uv.size () != y.uv.size ())
    return false;

  int xs (0), ys (0);

  for (num_vector::size_type i (0); i < x.uv.size (); ++i)
  {
    xs += x.uv[i];
    ys += y.uv[i];
  }

  return
    x.id_ == y.id_ &&
    x.num == y.num &&

    x.comp2_.num == y.comp2_.num &&
    x.comp2_.str == y.comp2_.str &&

    x.nv == y.nv &&
    x.sv == y.sv &&
    x.cv == y.cv &&
    xs == ys &&

    x.sl == y.sl &&
    x.nl == y.nl &&
    x.cl == y.cl &&

    x.nll == y.nll &&
    x.sll == y.sll &&
    x.cll == y.cll &&

    x.ns == y.ns &&
    x.ss == y.ss &&

    x.nsm == y.nsm &&
    x.snm == y.snm &&
    x.ncm == y.ncm &&
    x.csm == y.csm &&

    x.nsmm.uniqueKeys () == y.nsmm.uniqueKeys () &&
    x.snmm.uniqueKeys () == y.snmm.uniqueKeys () &&
    x.ncmm.uniqueKeys () == y.ncmm.uniqueKeys () &&

    x.nsh == y.nsh &&
    x.snh == y.snh &&
    x.sch == y.sch &&

    x.nsmh.uniqueKeys () == y.nsmh.uniqueKeys () &&
    x.snmh.uniqueKeys () == y.snmh.uniqueKeys () &&
    x.ncmh.uniqueKeys () == y.ncmh.uniqueKeys () &&

    x.str == y.str;
}

#endif // TEST_HXX