From 43fa55c1b8e389838c83be933bb30a2caaf7468d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 5 Feb 2013 15:50:08 +0200 Subject: Add support for change-tracking containers ODB now supports "smart" ordered containers. Such containers get extra functions for updating and deleting individual elements. Based on this functionality implement two change-tracking containers: odb::vector (equivalent to std::vector) and QOdbList (equivalent to QList). New tests: common/container/change-tracking and qt/common/container/change- tracking. --- qt/common/containers/basics/driver.cxx | 570 +++++++++++++++++++++ qt/common/containers/basics/makefile | 126 +++++ qt/common/containers/basics/test.hxx | 225 +++++++++ qt/common/containers/basics/test.std | 0 qt/common/containers/change-tracking/driver.cxx | 632 ++++++++++++++++++++++++ qt/common/containers/change-tracking/makefile | 126 +++++ qt/common/containers/change-tracking/test.hxx | 43 ++ qt/common/containers/change-tracking/test.std | 0 qt/common/containers/driver.cxx | 570 --------------------- qt/common/containers/makefile | 126 ----- qt/common/containers/test.hxx | 225 --------- qt/common/containers/test.std | 0 12 files changed, 1722 insertions(+), 921 deletions(-) create mode 100644 qt/common/containers/basics/driver.cxx create mode 100644 qt/common/containers/basics/makefile create mode 100644 qt/common/containers/basics/test.hxx create mode 100644 qt/common/containers/basics/test.std create mode 100644 qt/common/containers/change-tracking/driver.cxx create mode 100644 qt/common/containers/change-tracking/makefile create mode 100644 qt/common/containers/change-tracking/test.hxx create mode 100644 qt/common/containers/change-tracking/test.std delete mode 100644 qt/common/containers/driver.cxx delete mode 100644 qt/common/containers/makefile delete mode 100644 qt/common/containers/test.hxx delete mode 100644 qt/common/containers/test.std (limited to 'qt/common/containers') diff --git a/qt/common/containers/basics/driver.cxx b/qt/common/containers/basics/driver.cxx new file mode 100644 index 0000000..1d22962 --- /dev/null +++ b/qt/common/containers/basics/driver.cxx @@ -0,0 +1,570 @@ +// file : qt/common/containers/basics/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test basic Qt containers persistence. +// + +#include // std::auto_ptr +#include +#include + +#include + +#include +#include + +#include + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + QCoreApplication app (argc, argv); + + try + { + auto_ptr db (create_database (argc, argv)); + + for (unsigned short i (0); i < 2; ++i) + { + object empty ("empty"), med ("medium"), full ("full"); + + // + // empty + // + + empty.num = 0; + empty.str = ""; + + // + // med + // + + med.num = 999; + med.str = "xxx"; + + // vector + // + med.nv.push_back (123); + med.nv.push_back (234); + + med.sv.push_back ("aaa"); + med.sv.push_back ("bbbb"); + + med.cv.push_back (comp (123, "aaa")); + med.cv.push_back (comp (234, "bbbb")); + + med.uv.push_back (123); + med.uv.push_back (234); + + // list + // + med.sl.push_back ("aaa"); + med.sl.push_back ("bbbb"); + + med.nl.push_back (123); + med.nl.push_back (234); + + med.cl.push_back (comp (123, "aaa")); + med.cl.push_back (comp (234, "bbbb")); + + // linked list + // + med.sll.push_back ("aaa"); + med.sll.push_back ("bbbb"); + + med.nll.push_back (123); + med.nll.push_back (234); + + med.cll.push_back (comp (123, "aaa")); + med.cll.push_back (comp (234, "bbbb")); + + // set + // + med.ns.insert (123); + med.ns.insert (234); + + med.ss.insert ("aaa"); + med.ss.insert ("bbbb"); + + // map + // + med.nsm[123] = "aaa"; + med.nsm[234] = "bbbb"; + + med.snm["aaa"] = 123; + med.snm["bbbb"] = 234; + + med.ncm[123] = comp (123, "aaa"); + med.ncm[234] = comp (234, "bbbb"); + + med.csm[comp (123, "aaa")] = "aaa"; + med.csm[comp (234, "bbbb")] = "bbbb"; + + // multimap + // + med.nsmm.insert (123, "aaa"); + med.nsmm.insert (123, "bbbb"); + med.nsmm.insert (234, "ccccc"); + + med.snmm.insert ("aaa", 123); + med.snmm.insert ("aaa", 234); + med.snmm.insert ("bbb", 345); + + med.ncmm.insert (123, comp (123, "aaa")); + med.ncmm.insert (123, comp (234, "bbbb")); + med.ncmm.insert (234, comp (345, "ccccc")); + + // hash + // + med.nsh[123] = "aaa"; + med.nsh[234] = "bbbb"; + + med.snh["aaa"] = 123; + med.snh["bbb"] = 234; + + med.sch["iii"] = comp (123, "aaa"); + med.sch["jjj"] = comp (234, "bbbb"); + + // multihash + // + med.nsmh.insert (123, "aaa"); + med.nsmh.insert (123, "bbbb"); + med.nsmh.insert (234, "ccccc"); + + med.snmh.insert ("aaa", 123); + med.snmh.insert ("aaa", 234); + med.snmh.insert ("bbb", 345); + + med.ncmh.insert (123, comp (123, "aaa")); + med.ncmh.insert (123, comp (234, "bbbb")); + med.ncmh.insert (234, comp (345, "ccccc")); + + // + // full + // + + full.num = 9999; + full.str = "xxxx"; + + // vector + // + full.nv.push_back (1234); + full.nv.push_back (2345); + full.nv.push_back (3456); + + full.sv.push_back ("aaaa"); + full.sv.push_back ("bbbbb"); + full.sv.push_back ("cccccc"); + + full.cv.push_back (comp (1234, "aaaa")); + full.cv.push_back (comp (2345, "bbbbb")); + full.cv.push_back (comp (3456, "cccccc")); + + full.uv.push_back (1234); + full.uv.push_back (2345); + full.uv.push_back (3456); + + // list + // + full.sl.push_back ("aaaa"); + full.sl.push_back ("bbbbb"); + full.sl.push_back ("cccccc"); + + full.nl.push_back (1234); + full.nl.push_back (2345); + full.nl.push_back (3456); + + full.cl.push_back (comp (1234, "aaaa")); + full.cl.push_back (comp (2345, "bbbbb")); + full.cl.push_back (comp (3456, "cccccc")); + + // linked list + // + full.sll.push_back ("aaaa"); + full.sll.push_back ("bbbbb"); + full.sll.push_back ("cccccc"); + + full.nll.push_back (1234); + full.nll.push_back (2345); + full.nll.push_back (3456); + + full.cll.push_back (comp (1234, "aaaa")); + full.cll.push_back (comp (2345, "bbbbb")); + full.cll.push_back (comp (3456, "cccccc")); + + // set + // + full.ns.insert (1234); + full.ns.insert (2345); + full.ns.insert (3456); + + full.ss.insert ("aaaa"); + full.ss.insert ("bbbbb"); + full.ss.insert ("cccccc"); + + // map + // + full.nsm[1234] = "aaaa"; + full.nsm[2345] = "bbbbb"; + full.nsm[3456] = "cccccc"; + + full.snm["aaaa"] = 1234; + full.snm["bbbb"] = 2345; + full.snm["cccc"] = 3456; + + full.ncm[1234] = comp (1234, "aaaa"); + full.ncm[2345] = comp (2345, "bbbbb"); + full.ncm[3456] = comp (3456, "cccccc"); + + full.csm[comp (1234, "aaaa")] = "aaaa"; + full.csm[comp (2345, "bbbb")] = "bbbbb"; + full.csm[comp (3456, "cccc")] = "cccccc"; + + // multimap + // + full.nsmm.insert (1234, "aaaa"); + full.nsmm.insert (1234, "bbbbb"); + full.nsmm.insert (2345, "cccccc"); + full.nsmm.insert (2345, "ddddddd"); + + full.snmm.insert ("aaaa", 1234); + full.snmm.insert ("aaaa", 2345); + full.snmm.insert ("bbbb", 3456); + full.snmm.insert ("bbbb", 4567); + + full.ncmm.insert (1234, comp (1234, "aaaa")); + full.ncmm.insert (1234, comp (2345, "bbbbb")); + full.ncmm.insert (2345, comp (3456, "cccccc")); + full.ncmm.insert (2345, comp (4567, "ddddddd")); + + // hash + // + full.nsh[1234] = "aaaa"; + full.nsh[2345] = "bbbbb"; + full.nsh[3456] = "cccccc"; + + full.snh["aaaa"] = 1234; + full.snh["bbbb"] = 2345; + full.snh["cccc"] = 3456; + + full.sch["iiii"] = comp (1234, "aaaa"); + full.sch["jjjj"] = comp (2345, "bbbbb"); + full.sch["kkkk"] = comp (3456, "cccccc"); + + // multihash + // + full.nsmh.insert (1234, "aaaa"); + full.nsmh.insert (1234, "bbbbb"); + full.nsmh.insert (2345, "cccccc"); + full.nsmh.insert (2345, "ddddddd"); + + full.snmh.insert ("aaaa", 1234); + full.snmh.insert ("aaaa", 2345); + full.snmh.insert ("bbbb", 3456); + full.snmh.insert ("bbbb", 4567); + + full.ncmh.insert (1234, comp (1234, "aaaa")); + full.ncmh.insert (1234, comp (2345, "bbbbb")); + full.ncmh.insert (2345, comp (3456, "cccccc")); + full.ncmh.insert (2345, comp (4567, "ddddddd")); + + // persist + // + { + transaction t (db->begin ()); + db->persist (empty); + db->persist (med); + db->persist (full); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + auto_ptr e (db->load ("empty")); + auto_ptr m (db->load ("medium")); + auto_ptr f (db->load ("full")); + t.commit (); + + assert (empty == *e); + assert (med == *m); + assert (full == *f); + } + + // + // empty + // + + empty.num = 99; + empty.str = "xx"; + + // vector + // + empty.nv.push_back (12); + empty.sv.push_back ("aa"); + empty.cv.push_back (comp (12, "aa")); + empty.uv.push_back (12); + + // list + // + empty.sl.push_back ("aa"); + empty.nl.push_back (12); + empty.cl.push_back (comp (12, "aa")); + + // linked list + // + empty.nll.push_back (12); + empty.sll.push_back ("aa"); + empty.cll.push_back (comp (12, "aa")); + + // set + // + empty.ns.insert (12); + empty.ss.insert ("aa"); + + // map + // + empty.nsm[12] = "aa"; + empty.snm["aa"] = 12; + empty.ncm[12] = comp (12, "aa"); + empty.csm[comp (12, "aa")] = "aa"; + + // multimap + // + empty.nsmm.insert (12, "aa"); + empty.nsmm.insert (12, "bbb"); + empty.nsmm.insert (23, "cccc"); + empty.snmm.insert ("aa", 12); + empty.snmm.insert ("aa", 23); + empty.snmm.insert ("bb", 34); + empty.ncmm.insert (12, comp (12, "aa")); + empty.ncmm.insert (12, comp (23, "bb")); + empty.ncmm.insert (23, comp (34, "cc")); + + // hash + // + empty.nsh[12] = "aa"; + empty.snh["aa"] = 12; + empty.sch["ii"] = comp (12, "aa"); + + // multihash + // + empty.nsmh.insert (12, "aa"); + empty.nsmh.insert (12, "bbb"); + empty.nsmh.insert (23, "cccc"); + empty.snmh.insert ("aa", 12); + empty.snmh.insert ("aa", 23); + empty.snmh.insert ("bb", 34); + empty.ncmh.insert (12, comp (12, "aa")); + empty.ncmh.insert (12, comp (23, "bb")); + empty.ncmh.insert (23, comp (34, "cc")); + + // + // med + // + + med.num = 0; + med.str = ""; + + // vector + // + med.nv.clear (); + med.sv.clear (); + med.cv.clear (); + med.uv.clear (); + + // list + // + med.sl.clear (); + med.nl.clear (); + med.cl.clear (); + + // linked list + // + med.nll.clear (); + med.sll.clear (); + med.cll.clear (); + + // set + // + med.ns.clear (); + med.ss.clear (); + + // map + // + med.nsm.clear (); + med.snm.clear (); + med.ncm.clear (); + med.csm.clear (); + + // multimap + // + med.nsmm.clear (); + med.snmm.clear (); + med.ncmm.clear (); + + // hash + // + med.nsh.clear (); + med.snh.clear (); + med.sch.clear (); + + // multihash + // + med.nsmh.clear (); + med.snmh.clear (); + med.ncmh.clear (); + + + // + // full + // + + full.num++; + full.str += "x"; + + // vector + // + full.nv.back ()++; + full.nv.push_back (4567); + + full.sv.back () += "c"; + full.sv.push_back ("ddddddd"); + + full.cv.back ().num++; + full.cv.back ().str += "c"; + full.cv.push_back (comp (4567, "ddddddd")); + + full.uv.back ()++; + full.uv.push_back (4567); + + // list + // + full.sl.back () += "c"; + full.sl.push_back ("ddddddd"); + + full.nl.back ()++; + full.nl.push_back (4567); + + full.cl.back ().num++; + full.cl.back ().str += "c"; + full.cl.push_back (comp (4567, "ddddddd")); + + // linked list + // + full.sll.back () += "c"; + full.sll.push_back ("ddddddd"); + + full.nll.back ()++; + full.nll.push_back (4567); + + full.cll.back ().num++; + full.cll.back ().str += "c"; + full.cll.push_back (comp (4567, "ddddddd")); + + // set + // + full.ns.insert (4567); + full.ss.insert ("ddddddd"); + + // map + // + full.nsm[3456] += "c"; + full.nsm[4567] = "ddddddd"; + + full.snm["cccc"]++; + full.snm["dddd"] = 4567; + + full.ncm[3456].num++; + full.ncm[3456].str += "c"; + full.ncm[4567] = comp (4567, "ddddddd"); + + full.csm[comp (3456, "cccc")] += "c"; + full.csm[comp (4567, "dddd")] = "ddddddd"; + + // multimap + // + full.nsmm.find (2345).value () += "d"; + full.nsmm.insert (3456, "eeeeeeee"); + + full.snmm.find ("bbbb").value ()++; + full.snmm.insert ("cccc", 5678); + + full.ncmm.find (1234).value ().num++; + full.ncmm.find (2345).value ().str += "d"; + full.ncmm.insert (3456, comp (5678, "eeeeeeee")); + + // hash + // + full.nsh[3456] += "c"; + full.nsh[4567] = "ddddddd"; + + full.snh["cccc"]++; + full.snh["dddd"] = 4567; + + full.sch["iiii"].num++; + full.sch["jjjj"].str += "b"; + full.sch["kkkk"] = comp (4567, "dddddddd"); + + // multihash + // + full.nsmh.find (2345).value () += "d"; + full.nsmh.insert (3456, "eeeeeeee"); + + full.snmh.find ("bbbb").value ()++; + full.snmh.insert ("cccc", 5678); + + full.ncmh.find (1234).value ().num++; + full.ncmh.find (2345).value ().str += "d"; + full.ncmh.insert (3456, comp (5678, "eeeeeeee")); + + // update + // + { + transaction t (db->begin ()); + db->update (empty); + db->update (med); + db->update (full); + t.commit (); + } + + // load & check + // + { + transaction t (db->begin ()); + auto_ptr e (db->load ("empty")); + auto_ptr m (db->load ("medium")); + auto_ptr f (db->load ("full")); + t.commit (); + + assert (empty == *e); + assert (med == *m); + assert (full == *f); + } + + // erase + // + if (i == 0) + { + transaction t (db->begin ()); + db->erase ("empty"); + db->erase ("medium"); + db->erase ("full"); + t.commit (); + } + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/qt/common/containers/basics/makefile b/qt/common/containers/basics/makefile new file mode 100644 index 0000000..2a88495 --- /dev/null +++ b/qt/common/containers/basics/makefile @@ -0,0 +1,126 @@ +# file : qt/common/containers/basics/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +$(call import,\ + $(scf_root)/import/libodb-qt/stub.make,\ + l: odb_qt.l,cpp-options: odb_qt.l.cpp-options) + +$(call import,\ + $(scf_root)/import/libqt/core/stub.make,\ + l: qt_core.l,cpp-options: qt.l.cpp-options) + +# Build. +# +$(driver): $(cxx_obj) $(odb_qt.l) $(common.l) $(qt_core.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ +$(qt_core.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) \ +--profile qt/containers --profile qt/basic --generate-schema \ +--table-prefix qt_cont_bs_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ +$(qt_core.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/qt/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) $(call vc11projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../../template/Makefile.am) + $(call meta-vc9projs,../../template/template,$(name)) + $(call meta-vc10projs,../../template/template,$(name)) + $(call meta-vc11projs,../../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/vc11proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/qt/common/containers/basics/test.hxx b/qt/common/containers/basics/test.hxx new file mode 100644 index 0000000..204d0f9 --- /dev/null +++ b/qt/common/containers/basics/test.hxx @@ -0,0 +1,225 @@ +// file : qt/common/containers/basics/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// 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 diff --git a/qt/common/containers/basics/test.std b/qt/common/containers/basics/test.std new file mode 100644 index 0000000..e69de29 diff --git a/qt/common/containers/change-tracking/driver.cxx b/qt/common/containers/change-tracking/driver.cxx new file mode 100644 index 0000000..15dd825 --- /dev/null +++ b/qt/common/containers/change-tracking/driver.cxx @@ -0,0 +1,632 @@ +// file : qt/common/containers/change-tracking/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test change-tracking Qt containers. +// + +#include // HAVE_CXX11 + +#include // std::auto_ptr +#include +#include + +#ifdef HAVE_CXX11 +# include // std::move +#endif + +#include // QT_VERSION, Q_FOREACH +#include + +#include +#include +#include + +#include +#include + +#include + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +struct counting_tracer: odb::tracer +{ + void + reset (transaction& tr) {u = i = d = s = t = 0; tr.tracer (*this);} + + virtual void + execute (odb::connection&, const char* stmt) + { + string p (stmt, 6); + if (p == "UPDATE") + u++; + else if (p == "INSERT") + i++; + else if (p == "DELETE") + d++; + else if (p == "SELECT") + s++; + t++; + } + + size_t u, i, d, s, t; +}; + +static counting_tracer tr; + +// Compilation test: instantiate all the functions. Only do this if we +// have a fairly recent version of Qt, otherwise some underlying +// functions will be missing. +// +#if QT_VERSION >= 0x050000 +template class QOdbList; +template class QOdbListIteratorImpl >; +template class QOdbListIterator; +template class QMutableOdbListIterator; +#endif + +void +f (const QList&) {} + +int +main (int argc, char* argv[]) +{ + QCoreApplication app (argc, argv); + + try + { + // Test extended interface. + // + { + typedef QOdbList list; + + list ol; + QList ql; + f (ol); // Implicit conversion to QList. + list ol1 (ql); // Initialization from QList. + ol = ql; // Assignement from QList. + + // Container comparison. + // + if (ol != ol1 || + ol != ql || + ql != ol1) + ol.clear (); + + // Container operators. + // + ol += ol1; + ol += ql; + ol = ol1 + ql; + ol = ql + ol1; + + // Iterator comparison/conversion. + // +#ifndef QT_STRICT_ITERATORS + list::const_iterator i (ol.begin ()); + if (i != ol.end ()) + i = ol.end (); +#endif + + Q_FOREACH (const int& i, ol) + cerr << i; + } + + auto_ptr db (create_database (argc, argv)); + + // Test traits logic. + // + { + object o ("1"); + o.i = 123; + o.s.push_back ("a"); + + assert (!o.s._tracking ()); + + // persist + // + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + assert (o.s._tracking ()); + + // load + // + { + transaction t (db->begin ()); + auto_ptr p (db->load ("1")); + assert (p->s._tracking ()); + t.commit (); + } + + // update + // + { + transaction t (db->begin ()); + db->update (o); + t.commit (); + } + + assert (o.s._tracking ()); + + // erase + // + { + transaction t (db->begin ()); + db->erase (o); + t.commit (); + } + + assert (!o.s._tracking ()); + } + + // Test change tracking. + // + object o ("1"); + o.i = 123; + o.s.push_back ("a"); + + { + transaction t (db->begin ()); + db->persist (o); + t.commit (); + } + + // push_back/pop_back + // + { + o.s.push_back ("b"); // insert + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.i == 1 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.pop_back (); + o.s.push_back ("c"); // update + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 2 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.pop_back (); // delete + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.d == 1 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.push_back ("b"); + o.s.pop_back (); // no-op + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.t == 1); + assert (*db->load ("1") == o); + t.commit (); + } + + // insert + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("b"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.insert (o.s.begin (), "a1"); // insert front + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 3 && tr.i == 1 && tr.t == 4); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.insert (o.s.begin () + 1, "a2"); // insert middle + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 3 && tr.i == 1 && tr.t == 4); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.insert (o.s.end (), "b1"); // insert back + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.i == 1 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + // erase + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("b"); + o.s.push_back ("c"); + o.s.push_back ("d"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.erase (o.s.begin ()); // erase front + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 4 && tr.d == 1 && tr.t == 5); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.erase (o.s.begin () + 1); // erase middle + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 2 && tr.d == 1 && tr.t == 3); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.erase (o.s.end () - 1); // erase back + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.d == 1 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + // modify + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("b"); + o.s.push_back ("c"); + o.s.push_back ("d"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.modify (1) += 'b'; + o.s.modify_back () += 'd'; + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 3 && tr.t == 3); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.modify_front () += 'a'; + o.s.modify_back () += 'd'; + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 3 && tr.t == 3); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.begin ().modify () += 'a'; + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 2 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.mbegin (); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 5 && tr.t == 5); + assert (*db->load ("1") == o); + t.commit (); + } + + // clear + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("b"); + o.s.push_back ("c"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.clear (); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.d == 1 && tr.t == 2); + assert (*db->load ("1") == o); + t.commit (); + } + + // assign + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("b"); + o.s.push_back ("c"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + QList v; + v.push_back ("1"); + v.push_back ("2"); + v.push_back ("3"); + v.push_back ("4"); + o.s = v; + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 4 && tr.i == 1 && tr.t == 5); + assert (*db->load ("1") == o); + t.commit (); + } + + // removeOne/removeAll + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("a"); + o.s.push_back ("b"); + o.s.push_back ("c"); + o.s.push_back ("a"); + o.s.push_back ("d"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.removeOne ("c"); + assert (o.s.size () == 5 && o.s[3] == "a"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 3 && tr.d == 1 && tr.t == 4); + assert (*db->load ("1") == o); + t.commit (); + } + + { + o.s.removeAll ("a"); + assert (o.s.size () == 2 && o.s[0] == "b" && o.s[1] == "d"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 3 && tr.d == 1 && tr.t == 4); + assert (*db->load ("1") == o); + t.commit (); + } + + // Transaction rollback. + // + { + o.s.clear (); + o.s.push_back ("a"); + o.s.push_back ("b"); + o.s.push_back ("c"); + + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (*db->load ("1") == o); + t.commit (); + } + + { + { + o.s.push_back ("d"); + + transaction t (db->begin ()); + db->update (o); + t.rollback (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.i == 4 && tr.d == 1 && tr.t == 6); + t.commit (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (o); + assert (tr.u == 1 && tr.t == 1); + t.commit (); + } + } + + // Armed copy. + // + { + auto_ptr c; + + { + o.s.pop_back (); + + transaction t (db->begin ()); + db->update (o); + c.reset (new object (o)); + t.rollback (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (c); + assert (tr.u == 1 && tr.i == 3 && tr.d == 1 && tr.t == 5); + t.commit (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (c); + assert (tr.u == 1 && tr.t == 1); + t.commit (); + } + } + + // Armed swap. + // + { + object c (o); + + { + o.s.push_back ("d"); + + transaction t (db->begin ()); + db->update (o); + assert (o.s._tracking () && !c.s._tracking ()); + c.s.swap (o.s); + assert (!o.s._tracking () && c.s._tracking ()); + t.rollback (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (c); + assert (tr.u == 1 && tr.i == 4 && tr.d == 1 && tr.t == 6); + t.commit (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (c); + assert (tr.u == 1 && tr.t == 1); + t.commit (); + } + } + + // Armed move. + // +#ifdef HAVE_CXX11 + { + auto_ptr c; + + { + o.s.pop_back (); + + transaction t (db->begin ()); + db->update (o); + assert (o.s._tracking ()); + c.reset (new object (std::move (o))); + assert (!o.s._tracking () && c->s._tracking ()); + t.rollback (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (c); + assert (tr.u == 1 && tr.i == 2 && tr.d == 1 && tr.t == 4); + t.commit (); + } + + { + transaction t (db->begin ()); + tr.reset (t); + db->update (c); + assert (tr.u == 1 && tr.t == 1); + t.commit (); + } + } +#endif + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/qt/common/containers/change-tracking/makefile b/qt/common/containers/change-tracking/makefile new file mode 100644 index 0000000..7a25503 --- /dev/null +++ b/qt/common/containers/change-tracking/makefile @@ -0,0 +1,126 @@ +# file : qt/common/containers/change-tracking/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +$(call import,\ + $(scf_root)/import/libodb-qt/stub.make,\ + l: odb_qt.l,cpp-options: odb_qt.l.cpp-options) + +$(call import,\ + $(scf_root)/import/libqt/core/stub.make,\ + l: qt_core.l,cpp-options: qt.l.cpp-options) + +# Build. +# +$(driver): $(cxx_obj) $(odb_qt.l) $(common.l) $(qt_core.l) +$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) +$(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ +$(qt_core.l.cpp-options) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) \ +--profile qt/containers --profile qt/basic --generate-schema \ +--table-prefix qt_cont_ct_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ +$(qt_core.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/qt/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) $(call vc11projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../../template/Makefile.am) + $(call meta-vc9projs,../../template/template,$(name)) + $(call meta-vc10projs,../../template/template,$(name)) + $(call meta-vc11projs,../../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/vc11proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/qt/common/containers/change-tracking/test.hxx b/qt/common/containers/change-tracking/test.hxx new file mode 100644 index 0000000..7ad230e --- /dev/null +++ b/qt/common/containers/change-tracking/test.hxx @@ -0,0 +1,43 @@ +// file : qt/common/containers/change-tracking/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include // HAVE_CXX11 + +#include + +#ifdef HAVE_CXX11 +# include // std::move +#endif + +#include + +#include +#include + +#pragma db object pointer(std::auto_ptr) +struct object +{ + object () {} + object (const QString& id): id_ (id) {} + +#ifdef HAVE_CXX11 + object (const object& x): id_ (x.id_), i (x.i), s (x.s) {} + object (object&& x): id_ (std::move (x.id_)), i (x.i), s (std::move (x.s)) {} +#endif + + #pragma db id + QString id_; + + unsigned int i; + + QOdbList s; + + inline bool + operator== (const object& o) {return id_ == o.id_ && i == o.i && s == o.s;} +}; + +#endif // TEST_HXX diff --git a/qt/common/containers/change-tracking/test.std b/qt/common/containers/change-tracking/test.std new file mode 100644 index 0000000..e69de29 diff --git a/qt/common/containers/driver.cxx b/qt/common/containers/driver.cxx deleted file mode 100644 index 5de758c..0000000 --- a/qt/common/containers/driver.cxx +++ /dev/null @@ -1,570 +0,0 @@ -// file : qt/common/containers/driver.cxx -// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC -// license : GNU GPL v2; see accompanying LICENSE file - -// Test Qt containers persistence. -// - -#include // std::auto_ptr -#include -#include - -#include - -#include -#include - -#include - -#include "test.hxx" -#include "test-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - QCoreApplication app (argc, argv); - - try - { - auto_ptr db (create_database (argc, argv)); - - for (unsigned short i (0); i < 2; ++i) - { - object empty ("empty"), med ("medium"), full ("full"); - - // - // empty - // - - empty.num = 0; - empty.str = ""; - - // - // med - // - - med.num = 999; - med.str = "xxx"; - - // vector - // - med.nv.push_back (123); - med.nv.push_back (234); - - med.sv.push_back ("aaa"); - med.sv.push_back ("bbbb"); - - med.cv.push_back (comp (123, "aaa")); - med.cv.push_back (comp (234, "bbbb")); - - med.uv.push_back (123); - med.uv.push_back (234); - - // list - // - med.sl.push_back ("aaa"); - med.sl.push_back ("bbbb"); - - med.nl.push_back (123); - med.nl.push_back (234); - - med.cl.push_back (comp (123, "aaa")); - med.cl.push_back (comp (234, "bbbb")); - - // linked list - // - med.sll.push_back ("aaa"); - med.sll.push_back ("bbbb"); - - med.nll.push_back (123); - med.nll.push_back (234); - - med.cll.push_back (comp (123, "aaa")); - med.cll.push_back (comp (234, "bbbb")); - - // set - // - med.ns.insert (123); - med.ns.insert (234); - - med.ss.insert ("aaa"); - med.ss.insert ("bbbb"); - - // map - // - med.nsm[123] = "aaa"; - med.nsm[234] = "bbbb"; - - med.snm["aaa"] = 123; - med.snm["bbbb"] = 234; - - med.ncm[123] = comp (123, "aaa"); - med.ncm[234] = comp (234, "bbbb"); - - med.csm[comp (123, "aaa")] = "aaa"; - med.csm[comp (234, "bbbb")] = "bbbb"; - - // multimap - // - med.nsmm.insert (123, "aaa"); - med.nsmm.insert (123, "bbbb"); - med.nsmm.insert (234, "ccccc"); - - med.snmm.insert ("aaa", 123); - med.snmm.insert ("aaa", 234); - med.snmm.insert ("bbb", 345); - - med.ncmm.insert (123, comp (123, "aaa")); - med.ncmm.insert (123, comp (234, "bbbb")); - med.ncmm.insert (234, comp (345, "ccccc")); - - // hash - // - med.nsh[123] = "aaa"; - med.nsh[234] = "bbbb"; - - med.snh["aaa"] = 123; - med.snh["bbb"] = 234; - - med.sch["iii"] = comp (123, "aaa"); - med.sch["jjj"] = comp (234, "bbbb"); - - // multihash - // - med.nsmh.insert (123, "aaa"); - med.nsmh.insert (123, "bbbb"); - med.nsmh.insert (234, "ccccc"); - - med.snmh.insert ("aaa", 123); - med.snmh.insert ("aaa", 234); - med.snmh.insert ("bbb", 345); - - med.ncmh.insert (123, comp (123, "aaa")); - med.ncmh.insert (123, comp (234, "bbbb")); - med.ncmh.insert (234, comp (345, "ccccc")); - - // - // full - // - - full.num = 9999; - full.str = "xxxx"; - - // vector - // - full.nv.push_back (1234); - full.nv.push_back (2345); - full.nv.push_back (3456); - - full.sv.push_back ("aaaa"); - full.sv.push_back ("bbbbb"); - full.sv.push_back ("cccccc"); - - full.cv.push_back (comp (1234, "aaaa")); - full.cv.push_back (comp (2345, "bbbbb")); - full.cv.push_back (comp (3456, "cccccc")); - - full.uv.push_back (1234); - full.uv.push_back (2345); - full.uv.push_back (3456); - - // list - // - full.sl.push_back ("aaaa"); - full.sl.push_back ("bbbbb"); - full.sl.push_back ("cccccc"); - - full.nl.push_back (1234); - full.nl.push_back (2345); - full.nl.push_back (3456); - - full.cl.push_back (comp (1234, "aaaa")); - full.cl.push_back (comp (2345, "bbbbb")); - full.cl.push_back (comp (3456, "cccccc")); - - // linked list - // - full.sll.push_back ("aaaa"); - full.sll.push_back ("bbbbb"); - full.sll.push_back ("cccccc"); - - full.nll.push_back (1234); - full.nll.push_back (2345); - full.nll.push_back (3456); - - full.cll.push_back (comp (1234, "aaaa")); - full.cll.push_back (comp (2345, "bbbbb")); - full.cll.push_back (comp (3456, "cccccc")); - - // set - // - full.ns.insert (1234); - full.ns.insert (2345); - full.ns.insert (3456); - - full.ss.insert ("aaaa"); - full.ss.insert ("bbbbb"); - full.ss.insert ("cccccc"); - - // map - // - full.nsm[1234] = "aaaa"; - full.nsm[2345] = "bbbbb"; - full.nsm[3456] = "cccccc"; - - full.snm["aaaa"] = 1234; - full.snm["bbbb"] = 2345; - full.snm["cccc"] = 3456; - - full.ncm[1234] = comp (1234, "aaaa"); - full.ncm[2345] = comp (2345, "bbbbb"); - full.ncm[3456] = comp (3456, "cccccc"); - - full.csm[comp (1234, "aaaa")] = "aaaa"; - full.csm[comp (2345, "bbbb")] = "bbbbb"; - full.csm[comp (3456, "cccc")] = "cccccc"; - - // multimap - // - full.nsmm.insert (1234, "aaaa"); - full.nsmm.insert (1234, "bbbbb"); - full.nsmm.insert (2345, "cccccc"); - full.nsmm.insert (2345, "ddddddd"); - - full.snmm.insert ("aaaa", 1234); - full.snmm.insert ("aaaa", 2345); - full.snmm.insert ("bbbb", 3456); - full.snmm.insert ("bbbb", 4567); - - full.ncmm.insert (1234, comp (1234, "aaaa")); - full.ncmm.insert (1234, comp (2345, "bbbbb")); - full.ncmm.insert (2345, comp (3456, "cccccc")); - full.ncmm.insert (2345, comp (4567, "ddddddd")); - - // hash - // - full.nsh[1234] = "aaaa"; - full.nsh[2345] = "bbbbb"; - full.nsh[3456] = "cccccc"; - - full.snh["aaaa"] = 1234; - full.snh["bbbb"] = 2345; - full.snh["cccc"] = 3456; - - full.sch["iiii"] = comp (1234, "aaaa"); - full.sch["jjjj"] = comp (2345, "bbbbb"); - full.sch["kkkk"] = comp (3456, "cccccc"); - - // multihash - // - full.nsmh.insert (1234, "aaaa"); - full.nsmh.insert (1234, "bbbbb"); - full.nsmh.insert (2345, "cccccc"); - full.nsmh.insert (2345, "ddddddd"); - - full.snmh.insert ("aaaa", 1234); - full.snmh.insert ("aaaa", 2345); - full.snmh.insert ("bbbb", 3456); - full.snmh.insert ("bbbb", 4567); - - full.ncmh.insert (1234, comp (1234, "aaaa")); - full.ncmh.insert (1234, comp (2345, "bbbbb")); - full.ncmh.insert (2345, comp (3456, "cccccc")); - full.ncmh.insert (2345, comp (4567, "ddddddd")); - - // persist - // - { - transaction t (db->begin ()); - db->persist (empty); - db->persist (med); - db->persist (full); - t.commit (); - } - - // load & check - // - { - transaction t (db->begin ()); - auto_ptr e (db->load ("empty")); - auto_ptr m (db->load ("medium")); - auto_ptr f (db->load ("full")); - t.commit (); - - assert (empty == *e); - assert (med == *m); - assert (full == *f); - } - - // - // empty - // - - empty.num = 99; - empty.str = "xx"; - - // vector - // - empty.nv.push_back (12); - empty.sv.push_back ("aa"); - empty.cv.push_back (comp (12, "aa")); - empty.uv.push_back (12); - - // list - // - empty.sl.push_back ("aa"); - empty.nl.push_back (12); - empty.cl.push_back (comp (12, "aa")); - - // linked list - // - empty.nll.push_back (12); - empty.sll.push_back ("aa"); - empty.cll.push_back (comp (12, "aa")); - - // set - // - empty.ns.insert (12); - empty.ss.insert ("aa"); - - // map - // - empty.nsm[12] = "aa"; - empty.snm["aa"] = 12; - empty.ncm[12] = comp (12, "aa"); - empty.csm[comp (12, "aa")] = "aa"; - - // multimap - // - empty.nsmm.insert (12, "aa"); - empty.nsmm.insert (12, "bbb"); - empty.nsmm.insert (23, "cccc"); - empty.snmm.insert ("aa", 12); - empty.snmm.insert ("aa", 23); - empty.snmm.insert ("bb", 34); - empty.ncmm.insert (12, comp (12, "aa")); - empty.ncmm.insert (12, comp (23, "bb")); - empty.ncmm.insert (23, comp (34, "cc")); - - // hash - // - empty.nsh[12] = "aa"; - empty.snh["aa"] = 12; - empty.sch["ii"] = comp (12, "aa"); - - // multihash - // - empty.nsmh.insert (12, "aa"); - empty.nsmh.insert (12, "bbb"); - empty.nsmh.insert (23, "cccc"); - empty.snmh.insert ("aa", 12); - empty.snmh.insert ("aa", 23); - empty.snmh.insert ("bb", 34); - empty.ncmh.insert (12, comp (12, "aa")); - empty.ncmh.insert (12, comp (23, "bb")); - empty.ncmh.insert (23, comp (34, "cc")); - - // - // med - // - - med.num = 0; - med.str = ""; - - // vector - // - med.nv.clear (); - med.sv.clear (); - med.cv.clear (); - med.uv.clear (); - - // list - // - med.sl.clear (); - med.nl.clear (); - med.cl.clear (); - - // linked list - // - med.nll.clear (); - med.sll.clear (); - med.cll.clear (); - - // set - // - med.ns.clear (); - med.ss.clear (); - - // map - // - med.nsm.clear (); - med.snm.clear (); - med.ncm.clear (); - med.csm.clear (); - - // multimap - // - med.nsmm.clear (); - med.snmm.clear (); - med.ncmm.clear (); - - // hash - // - med.nsh.clear (); - med.snh.clear (); - med.sch.clear (); - - // multihash - // - med.nsmh.clear (); - med.snmh.clear (); - med.ncmh.clear (); - - - // - // full - // - - full.num++; - full.str += "x"; - - // vector - // - full.nv.back ()++; - full.nv.push_back (4567); - - full.sv.back () += "c"; - full.sv.push_back ("ddddddd"); - - full.cv.back ().num++; - full.cv.back ().str += "c"; - full.cv.push_back (comp (4567, "ddddddd")); - - full.uv.back ()++; - full.uv.push_back (4567); - - // list - // - full.sl.back () += "c"; - full.sl.push_back ("ddddddd"); - - full.nl.back ()++; - full.nl.push_back (4567); - - full.cl.back ().num++; - full.cl.back ().str += "c"; - full.cl.push_back (comp (4567, "ddddddd")); - - // linked list - // - full.sll.back () += "c"; - full.sll.push_back ("ddddddd"); - - full.nll.back ()++; - full.nll.push_back (4567); - - full.cll.back ().num++; - full.cll.back ().str += "c"; - full.cll.push_back (comp (4567, "ddddddd")); - - // set - // - full.ns.insert (4567); - full.ss.insert ("ddddddd"); - - // map - // - full.nsm[3456] += "c"; - full.nsm[4567] = "ddddddd"; - - full.snm["cccc"]++; - full.snm["dddd"] = 4567; - - full.ncm[3456].num++; - full.ncm[3456].str += "c"; - full.ncm[4567] = comp (4567, "ddddddd"); - - full.csm[comp (3456, "cccc")] += "c"; - full.csm[comp (4567, "dddd")] = "ddddddd"; - - // multimap - // - full.nsmm.find (2345).value () += "d"; - full.nsmm.insert (3456, "eeeeeeee"); - - full.snmm.find ("bbbb").value ()++; - full.snmm.insert ("cccc", 5678); - - full.ncmm.find (1234).value ().num++; - full.ncmm.find (2345).value ().str += "d"; - full.ncmm.insert (3456, comp (5678, "eeeeeeee")); - - // hash - // - full.nsh[3456] += "c"; - full.nsh[4567] = "ddddddd"; - - full.snh["cccc"]++; - full.snh["dddd"] = 4567; - - full.sch["iiii"].num++; - full.sch["jjjj"].str += "b"; - full.sch["kkkk"] = comp (4567, "dddddddd"); - - // multihash - // - full.nsmh.find (2345).value () += "d"; - full.nsmh.insert (3456, "eeeeeeee"); - - full.snmh.find ("bbbb").value ()++; - full.snmh.insert ("cccc", 5678); - - full.ncmh.find (1234).value ().num++; - full.ncmh.find (2345).value ().str += "d"; - full.ncmh.insert (3456, comp (5678, "eeeeeeee")); - - // update - // - { - transaction t (db->begin ()); - db->update (empty); - db->update (med); - db->update (full); - t.commit (); - } - - // load & check - // - { - transaction t (db->begin ()); - auto_ptr e (db->load ("empty")); - auto_ptr m (db->load ("medium")); - auto_ptr f (db->load ("full")); - t.commit (); - - assert (empty == *e); - assert (med == *m); - assert (full == *f); - } - - // erase - // - if (i == 0) - { - transaction t (db->begin ()); - db->erase ("empty"); - db->erase ("medium"); - db->erase ("full"); - t.commit (); - } - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/qt/common/containers/makefile b/qt/common/containers/makefile deleted file mode 100644 index 3cfc22f..0000000 --- a/qt/common/containers/makefile +++ /dev/null @@ -1,126 +0,0 @@ -# file : qt/common/containers/makefile -# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := test.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -common.l := $(out_root)/libcommon/common/common.l -common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb-qt/stub.make,\ - l: odb_qt.l,cpp-options: odb_qt.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libqt/core/stub.make,\ - l: qt_core.l,cpp-options: qt.l.cpp-options) - -# Build. -# -$(driver): $(cxx_obj) $(odb_qt.l) $(common.l) $(qt_core.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -$(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ -$(qt_core.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --database $(db_id) \ ---profile qt/containers --profile qt/basic --generate-schema \ ---table-prefix qt_cont_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(common.l.cpp-options) $(odb_qt.l.cpp-options) \ -$(qt_core.l.cpp-options) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/qt/common/,,$(src_base))) - -$(dist): db_id := @database@ -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): data_dist := test.std -$(dist): export name := $(name) -$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ -$(call vc10projs,$(name)) $(call vc11projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) $(data_dist)) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - -# Test. -# -$(test): $(driver) $(src_base)/test.std - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/db.options \ ->$(out_base)/test.out) - $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) - $(call message,,rm -f $(out_base)/test.out) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - $(call message,,rm -f $(out_base)/test.out) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - -# Dependencies. -# -$(call import,$(src_root)/libcommon/makefile) diff --git a/qt/common/containers/test.hxx b/qt/common/containers/test.hxx deleted file mode 100644 index 2e452d6..0000000 --- a/qt/common/containers/test.hxx +++ /dev/null @@ -1,225 +0,0 @@ -// file : qt/common/containers/test.hxx -// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC -// 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 diff --git a/qt/common/containers/test.std b/qt/common/containers/test.std deleted file mode 100644 index e69de29..0000000 -- cgit v1.1