diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-02-05 15:50:08 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-02-05 15:50:08 +0200 |
commit | 43fa55c1b8e389838c83be933bb30a2caaf7468d (patch) | |
tree | 310bc0ecc43ea38276a7e8ff2a541f2cba395333 /common/container/change-tracking/test.hxx | |
parent | 3eee63801cbe833f6557d6f85c5778b6209140be (diff) |
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.
Diffstat (limited to 'common/container/change-tracking/test.hxx')
-rw-r--r-- | common/container/change-tracking/test.hxx | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/common/container/change-tracking/test.hxx b/common/container/change-tracking/test.hxx new file mode 100644 index 0000000..0387faf --- /dev/null +++ b/common/container/change-tracking/test.hxx @@ -0,0 +1,81 @@ +// file : common/container/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 <common/config.hxx> // HAVE_CXX11 + +#include <string> +#include <memory> +#include <vector> + +#ifdef HAVE_CXX11 +# include <utility> // std::move +#endif + +#include <odb/core.hxx> +#include <odb/vector.hxx> + +#pragma db object pointer(std::auto_ptr) +struct object +{ + object () {} + object (const std::string& 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 + std::string id_; + + unsigned int i; + + odb::vector<std::string> s; + + inline bool + operator== (const object& o) {return id_ == o.id_ && i == o.i && s == o.s;} +}; + +// Test mixing "smart" and "dumb" container (specifically, erase(obj)). +// +#pragma db object +struct mix_object +{ + mix_object () {} + mix_object (unsigned long id): id_ (id) {} + + #pragma db id + unsigned long id_; + + odb::vector<int> ov; + std::vector<int> sv; +}; + +// Test using change tracking container as inverse member. +// +struct inv_object2; + +#pragma db object session +struct inv_object1 +{ + #pragma db id auto + unsigned long id_; + + inv_object2* o2; +}; + +#pragma db object session +struct inv_object2 +{ + #pragma db id auto + unsigned long id_; + + #pragma db inverse(o2) + odb::vector<inv_object1*> o1; +}; + +#endif // TEST_HXX |