From 0d49ea1fe08cf1eab41a00149393a291c65a59d7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 25 Jan 2024 20:32:06 +0300 Subject: Turn odb-tests repository into package for muti-package repository --- odb-tests/qt/common/containers/basics/test.hxx | 224 +++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 odb-tests/qt/common/containers/basics/test.hxx (limited to 'odb-tests/qt/common/containers/basics/test.hxx') diff --git a/odb-tests/qt/common/containers/basics/test.hxx b/odb-tests/qt/common/containers/basics/test.hxx new file mode 100644 index 0000000..2c61c88 --- /dev/null +++ b/odb-tests/qt/common/containers/basics/test.hxx @@ -0,0 +1,224 @@ +// file : qt/common/containers/basics/test.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#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 num_vector; +typedef QVector str_vector; +typedef QVector comp_vector; + +typedef QList num_list; +typedef QList str_list; +typedef QList comp_list; + +typedef QLinkedList num_linked_list; +typedef QLinkedList str_linked_list; +typedef QLinkedList comp_linked_list; + +typedef QSet num_set; +typedef QSet str_set; + +typedef QMap num_str_map; +typedef QMap str_num_map; +typedef QMap num_comp_map; +typedef QMap comp_str_map; + +typedef QMultiMap num_str_multimap; +typedef QMultiMap str_num_multimap; +typedef QMultiMap num_comp_multimap; + +typedef QHash num_str_hash; +typedef QHash str_num_hash; +typedef QHash str_comp_hash; + +typedef QMultiHash num_str_multihash; +typedef QMultiHash str_num_multihash; +typedef QMultiHash 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 -- cgit v1.1