aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-09-06 09:42:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-09-06 09:42:55 +0200
commit16f2e990acb2463a96611b25effb411ecca2b76c (patch)
treebb95cc6bfeae8ec9edade7555de6493561cef889
parent0e6587f29f40a841f0e393887fea4e5cf385e0e6 (diff)
Split polymorphism test.hxx to multiple files
-rw-r--r--common/circular/multiple/makefile2
-rw-r--r--common/polymorphism/driver.cxx27
-rw-r--r--common/polymorphism/makefile9
-rw-r--r--common/polymorphism/test.hxx1055
-rw-r--r--common/polymorphism/test1.hxx116
-rw-r--r--common/polymorphism/test10.hxx79
-rw-r--r--common/polymorphism/test11.hxx79
-rw-r--r--common/polymorphism/test12.hxx80
-rw-r--r--common/polymorphism/test2.hxx106
-rw-r--r--common/polymorphism/test3.hxx147
-rw-r--r--common/polymorphism/test4.hxx76
-rw-r--r--common/polymorphism/test5.hxx93
-rw-r--r--common/polymorphism/test6.hxx65
-rw-r--r--common/polymorphism/test7.hxx67
-rw-r--r--common/polymorphism/test8.hxx130
-rw-r--r--common/polymorphism/test9.hxx162
16 files changed, 1232 insertions, 1061 deletions
diff --git a/common/circular/multiple/makefile b/common/circular/multiple/makefile
index abd72e7..bce0f5b 100644
--- a/common/circular/multiple/makefile
+++ b/common/circular/multiple/makefile
@@ -41,7 +41,7 @@ $(gen): $(common.l.cpp-options)
# Extra dependecy for the ODB-generated code.
#
-$(gen): $(src_base)/test1.hxx $(src_base)/test2.hxx
+$(gen): $(addprefix $(src_base)/,$(odb_hdr))
$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
diff --git a/common/polymorphism/driver.cxx b/common/polymorphism/driver.cxx
index 09e3321..6093178 100644
--- a/common/polymorphism/driver.cxx
+++ b/common/polymorphism/driver.cxx
@@ -15,8 +15,31 @@
#include <common/common.hxx>
-#include "test.hxx"
-#include "test-odb.hxx"
+#include "test1.hxx"
+#include "test2.hxx"
+#include "test3.hxx"
+#include "test4.hxx"
+#include "test5.hxx"
+#include "test6.hxx"
+#include "test7.hxx"
+#include "test8.hxx"
+#include "test9.hxx"
+#include "test10.hxx"
+#include "test11.hxx"
+#include "test12.hxx"
+
+#include "test1-odb.hxx"
+#include "test2-odb.hxx"
+#include "test3-odb.hxx"
+#include "test4-odb.hxx"
+#include "test5-odb.hxx"
+#include "test6-odb.hxx"
+#include "test7-odb.hxx"
+#include "test8-odb.hxx"
+#include "test9-odb.hxx"
+#include "test10-odb.hxx"
+#include "test11-odb.hxx"
+#include "test12-odb.hxx"
using namespace std;
using namespace odb::core;
diff --git a/common/polymorphism/makefile b/common/polymorphism/makefile
index 9b4385e..36d48ea 100644
--- a/common/polymorphism/makefile
+++ b/common/polymorphism/makefile
@@ -5,7 +5,8 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
cxx_tun := driver.cxx
-odb_hdr := test.hxx
+odb_hdr := test1.hxx test2.hxx test3.hxx test4.hxx test5.hxx test6.hxx \
+test7.hxx test8.hxx test9.hxx test10.hxx test11.hxx test12.hxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
cxx_od := $(cxx_obj:.o=.o.d)
@@ -29,7 +30,7 @@ $(driver): $(cxx_obj) $(common.l)
$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base)
$(cxx_obj) $(cxx_od): $(common.l.cpp-options)
-genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql)
+genf := $(foreach f,$(odb_hdr:.hxx=),$(addprefix $f,-odb.hxx -odb.ixx -odb.cxx .sql))
gen := $(addprefix $(out_base)/,$(genf))
$(gen): $(odb)
@@ -54,6 +55,7 @@ $(dist): sources := $(cxx_tun)
$(dist): headers := $(odb_hdr)
$(dist): data_dist := test.std
$(dist): export name := $(name)
+$(dist): export odb_header_stem := $(basename $(odb_hdr))
$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \
$(call vc10projs,$(name))
$(dist):
@@ -64,8 +66,9 @@ $(dist):
# Test.
#
+$(test): schemas := $(addprefix $(out_base)/,$(odb_hdr:.hxx=.sql))
$(test): $(driver) $(src_base)/test.std
- $(call schema)
+ $(call schema,$(schemas))
$(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)
diff --git a/common/polymorphism/test.hxx b/common/polymorphism/test.hxx
deleted file mode 100644
index 9994fdd..0000000
--- a/common/polymorphism/test.hxx
+++ /dev/null
@@ -1,1055 +0,0 @@
-// file : common/polymorphism/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, HAVE_TR1_MEMORY
-
-#include <string>
-#include <vector>
-#include <memory>
-
-#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
-# include <odb/tr1/memory.hxx>
-#endif
-
-#include <odb/core.hxx>
-#include <odb/callback.hxx>
-#include <odb/lazy-ptr.hxx>
-
-// Test basic polymorphism functionality.
-//
-#pragma db namespace table("t1_")
-namespace test1
-{
- #pragma db object polymorphic
- struct root
- {
- virtual ~root () {}
- root () {}
- root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- std::vector<std::string> strs;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (root))
- return false;
-
- return id == r.id && num == r.num && strs == r.strs;
- }
- };
-
- inline bool
- operator== (const root& x, const root& y) {return x.compare (y);}
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long i, unsigned long n, const std::string& s)
- : root (i, n), str (s) {}
-
- std::string str;
- std::vector<unsigned long> nums;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (base))
- return false;
-
- const base& b (static_cast<const base&> (r));
- return root::compare (r, false) && str == b.str && nums == b.nums;
- }
- };
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, unsigned long n, const std::string& s)
- : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived))
- return false;
-
- const derived& d (static_cast<const derived&> (r));
- return base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
- }
- };
-
- // Views.
- //
- #pragma db view object(root)
- struct root_view
- {
- //#pragma db column(root::typeid_)
- std::string typeid_; // @@ tmp
-
- unsigned long num;
- };
-
- #pragma db view object(base = b)
- struct base_view
- {
- unsigned long id;
- unsigned long num;
- std::string str;
- };
-
- #pragma db view object(derived)
- struct derived_view
- {
- unsigned long num;
- std::string str;
- unsigned long dnum;
- std::string dstr;
- };
-}
-
-// Test inverse object pointers in polymorhic bases.
-//
-#pragma db namespace table("t2_")
-namespace test2
-{
- struct root;
-
- #pragma db object
- struct root_pointer
- {
- root_pointer (root* r = 0): p (r) {}
-
- #pragma db id auto
- unsigned long id;
-
- root* p;
- };
-
- #pragma db object polymorphic
- struct root
- {
- virtual ~root () {}
- root () {}
- root (unsigned long i): id (i) {}
-
- #pragma db id
- unsigned long id;
-
- #pragma db inverse(p)
- odb::lazy_ptr<root_pointer> rp;
- };
-
- struct base;
-
- #pragma db object
- struct base_pointer
- {
- base_pointer (base* b = 0) {if (b != 0) vp.push_back (b);}
-
- #pragma db id auto
- unsigned long id;
-
- std::vector<base*> vp;
- };
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long i, const std::string& s): root (i), str (s) {}
-
- std::string str;
-
- #pragma db inverse(vp)
- odb::lazy_ptr<base_pointer> bp;
- };
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, const std::string& s, unsigned long n)
- : base (i, s), num (n) {}
-
- unsigned long num;
- };
-
- // Views.
- //
- #pragma db view object(root_pointer = rp) object(root)
- struct root_view
- {
- #pragma db column(rp::id)
- unsigned long rp_id;
-
- #pragma db column(root::id)
- unsigned long r_id;
- };
-
- #pragma db view object(base_pointer) object(base = b)
- struct base_view
- {
- #pragma db column(base_pointer::id)
- unsigned long bp_id;
-
- #pragma db column(b::id)
- unsigned long b_id;
-
- std::string str;
- };
-}
-
-// Test delayed loading.
-//
-#pragma db namespace table("t3_")
-namespace test3
-{
- #pragma db object polymorphic
- struct root
- {
- virtual ~root () {}
- root () {}
- root (unsigned long i): id (i) {}
-
- #pragma db id
- unsigned long id;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (root))
- return false;
-
- return id == r.id;
- }
- };
-
- inline bool
- operator== (const root& x, const root& y) {return x.compare (y);}
-
- #pragma db object
- struct base: root
- {
- virtual ~base () {delete rptr;}
- base (): rptr (0) {}
- base (unsigned long i, unsigned long n): root (i), num (n), rptr (0) {}
-
- unsigned long num;
- root* rptr;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (base))
- return false;
-
- const base& b (static_cast<const base&> (r));
- return
- root::compare (r, false) &&
- num == b.num &&
- ((rptr == 0 && b.rptr == 0) || rptr->compare (*b.rptr));
- }
- };
-
- #pragma db object
- struct derived: base
- {
- virtual ~derived () {delete bptr;}
- derived (): bptr (0) {}
- derived (unsigned long i, unsigned long n, const std::string& s)
- : base (i, n), str (s), bptr (0) {}
-
- std::string str;
- base* bptr;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived))
- return false;
-
- const derived& d (static_cast<const derived&> (r));
- return
- base::compare (r, false) &&
- str == d.str &&
- ((bptr == 0 && d.bptr == 0) || bptr->compare (*d.bptr));
- }
- };
-
- // Views.
- //
- #pragma db view object(base) object(root = r)
- struct base_view
- {
- #pragma db column(base::id)
- unsigned long b_id;
-
- #pragma db column(r::id)
- unsigned long r_id;
-
- unsigned long num;
- };
-
- #pragma db view \
- object(derived = d) \
- object(base = b) \
- object(root = r: d::rptr)
- struct derived_view
- {
- #pragma db column(d::id)
- unsigned long d_id;
-
- #pragma db column(b::id)
- unsigned long b_id;
-
- #pragma db column(r::id)
- unsigned long r_id;
-
- #pragma db column(d::num)
- unsigned long d_num;
-
- #pragma db column(b::num)
- unsigned long b_num;
-
- std::string str;
- };
-
- // This is an example of a pathological case, where the right-hand-side
- // of the join condition comes from one of the bases. As a result, we
- // join the base table first, which means we will get both bases and
- // derived objects instead of just derived.
- //
- //#pragma db view object(root = r) object(derived = d)
- #pragma db view object(derived = d) object(root = r)
- struct root_view
- {
- #pragma db column(r::id)
- unsigned long r_id;
-
- #pragma db column(d::id)
- unsigned long d_id;
-
- std::string str;
- };
-}
-
-// Test views.
-//
-#pragma db namespace table("t4_")
-namespace test4
-{
- #pragma db object polymorphic
- struct root1
- {
- virtual ~root1 () {}
- root1 () {}
- root1 (unsigned long i): id (i) {}
-
- #pragma db id
- unsigned long id;
- };
-
- #pragma db object
- struct base1: root1
- {
- base1 () {}
- base1 (unsigned long i, unsigned long n): root1 (i), num (n) {}
-
- unsigned long num;
- };
-
- #pragma db object polymorphic
- struct root2
- {
- virtual ~root2 () {}
- root2 () {}
- root2 (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- };
-
- #pragma db object
- struct base2: root2
- {
- base2 () {}
- base2 (unsigned long i, unsigned long n, const std::string& s)
- : root2 (i, n), str (s) {}
-
- std::string str;
- };
-
- // Test custom join condition.
- //
- #pragma db view object(base2) object(base1: base2::num == base1::num)
- struct view1
- {
- std::string str;
- };
-
- #pragma db view object(base2)
- struct view2
- {
- #pragma db column("min(" + base2::num + ")")
- std::size_t min_num;
- };
-}
-
-// Test polymorphism and optimistic concurrency.
-//
-#pragma db namespace table("t5_")
-namespace test5
-{
- #pragma db object polymorphic optimistic pointer(std::auto_ptr)
- struct root
- {
- virtual ~root () {}
- root () {}
- root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- #pragma db version
- unsigned long version;
-
- unsigned long num;
- std::vector<std::string> strs;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (root))
- return false;
-
- return id == r.id && version == r.version &&
- num == r.num && strs == r.strs;
- }
- };
-
- inline bool
- operator== (const root& x, const root& y) {return x.compare (y);}
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long i, unsigned long n, const std::string& s)
- : root (i, n), str (s) {}
-
- std::string str;
- std::vector<unsigned long> nums;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (base))
- return false;
-
- const base& b (static_cast<const base&> (r));
- return root::compare (r, false) && str == b.str && nums == b.nums;
- }
- };
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, unsigned long n, const std::string& s)
- : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived))
- return false;
-
- const derived& d (static_cast<const derived&> (r));
- return base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
- }
- };
-}
-
-// Test polymorphism and callbacks.
-//
-#pragma db namespace table("t6_")
-namespace test6
-{
- #pragma db object polymorphic pointer(std::auto_ptr)
- struct root
- {
- virtual ~root () {}
- root (): id (0) {}
- root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- };
-
- #pragma db object callback(db_callback)
- struct base: root
- {
- base () {}
- base (unsigned long i, unsigned long n, const std::string& s)
- : root (i, n), str (s) {}
-
- std::string str;
-
- void
- db_callback (odb::callback_event, odb::database&);
-
- void
- db_callback (odb::callback_event, odb::database&) const;
- };
-
- #pragma db object callback(db_callback)
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, unsigned long n, const std::string& s)
- : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
-
- std::auto_ptr<root> ptr;
-
- void
- db_callback (odb::callback_event, odb::database&) const;
- };
-}
-
-// Test polymorphism and object cache (session).
-//
-#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
-#pragma db namespace table("t7_")
-namespace test7
-{
-#ifdef HAVE_CXX11
- using std::shared_ptr;
-#else
- using std::tr1::shared_ptr;
-#endif
-
- #pragma db object polymorphic pointer(shared_ptr) session
- struct root
- {
- virtual ~root () {}
- root (): id (0) {}
- root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- };
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long i, unsigned long n, const std::string& s)
- : root (i, n), str (s) {}
-
- std::string str;
- };
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, unsigned long n, const std::string& s)
- : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
- };
-}
-#endif
-
-// Test polymorphism and abstract bases.
-//
-#pragma db namespace table("t8_")
-namespace test8
-{
- #pragma db object polymorphic
- struct root
- {
- virtual ~root () = 0; // Auto-abstract.
- root () {}
- root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- std::vector<std::string> strs;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (root))
- return false;
-
- return id == r.id && num == r.num && strs == r.strs;
- }
- };
-
- inline root::
- ~root () {}
-
- inline bool
- operator== (const root& x, const root& y) {return x.compare (y);}
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long i, unsigned long n, const std::string& s)
- : root (i, n), str (s) {}
-
- std::string str;
- std::vector<unsigned long> nums;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (base))
- return false;
-
- const base& b (static_cast<const base&> (r));
- return root::compare (r, false) && str == b.str && nums == b.nums;
- }
- };
-
- #pragma db object abstract
- struct interm: base
- {
- interm () {}
- interm (unsigned long i, unsigned long n, const std::string& s, bool b)
- : base (i, n, s), bln (b) {}
-
- bool bln;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (interm))
- return false;
-
- const interm& i (static_cast<const interm&> (r));
- return base::compare (r, false) && bln == i.bln;
- }
- };
-
- #pragma db object
- struct derived1: interm
- {
- derived1 () {}
- derived1 (unsigned long i, unsigned long n, const std::string& s, bool b)
- : interm (i, n, s, b), dnum (n + 1) {}
-
- unsigned long dnum;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived1))
- return false;
-
- const derived1& d (static_cast<const derived1&> (r));
- return interm::compare (r, false) && dnum == d.dnum;
- }
- };
-
- #pragma db object
- struct derived2: interm
- {
- derived2 () {}
- derived2 (unsigned long i, unsigned long n, const std::string& s, bool b)
- : interm (i, n, s, b), dstr (s + 'd') {}
-
- std::string dstr;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived2))
- return false;
-
- const derived2& d (static_cast<const derived2&> (r));
- return interm::compare (r, false) && dstr == d.dstr;
- }
- };
-}
-
-// Test polymorphism and readonly classes.
-//
-#pragma db namespace table("t9_")
-namespace test9
-{
- //
- // ro_root, rw_base, ro_derived
- //
- #pragma db object polymorphic readonly
- struct ro_root
- {
- virtual ~ro_root () {}
- ro_root () {}
- ro_root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- std::vector<std::string> strs;
-
- virtual bool
- compare (const ro_root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (ro_root))
- return false;
-
- return id == r.id && num == r.num && strs == r.strs;
- }
- };
-
- inline bool
- operator== (const ro_root& x, const ro_root& y) {return x.compare (y);}
-
- #pragma db object
- struct rw_base: ro_root
- {
- rw_base () {}
- rw_base (unsigned long i, unsigned long n, const std::string& s)
- : ro_root (i, n), str (s) {}
-
- std::string str;
- std::vector<unsigned long> nums;
-
- virtual bool
- compare (const ro_root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (rw_base))
- return false;
-
- const rw_base& b (static_cast<const rw_base&> (r));
- return ro_root::compare (r, false) && str == b.str && nums == b.nums;
- }
- };
-
- #pragma db object readonly
- struct ro_derived: rw_base
- {
- ro_derived () {}
- ro_derived (unsigned long i, unsigned long n, const std::string& s)
- : rw_base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
-
- virtual bool
- compare (const ro_root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (ro_derived))
- return false;
-
- const ro_derived& d (static_cast<const ro_derived&> (r));
- return rw_base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
- }
- };
-
- //
- // rw_root, ro_base, rw_derived
- //
- #pragma db object polymorphic
- struct rw_root
- {
- virtual ~rw_root () {}
- rw_root () {}
- rw_root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- std::vector<std::string> strs;
-
- virtual bool
- compare (const rw_root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (rw_root))
- return false;
-
- return id == r.id && num == r.num && strs == r.strs;
- }
- };
-
- inline bool
- operator== (const rw_root& x, const rw_root& y) {return x.compare (y);}
-
- #pragma db object readonly
- struct ro_base: rw_root
- {
- ro_base () {}
- ro_base (unsigned long i, unsigned long n, const std::string& s)
- : rw_root (i, n), str (s) {}
-
- std::string str;
- std::vector<unsigned long> nums;
-
- virtual bool
- compare (const rw_root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (ro_base))
- return false;
-
- const ro_base& b (static_cast<const ro_base&> (r));
- return rw_root::compare (r, false) && str == b.str && nums == b.nums;
- }
- };
-
- #pragma db object
- struct rw_derived: ro_base
- {
- rw_derived () {}
- rw_derived (unsigned long i, unsigned long n, const std::string& s)
- : ro_base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
-
- virtual bool
- compare (const rw_root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (rw_derived))
- return false;
-
- const rw_derived& d (static_cast<const rw_derived&> (r));
- return ro_base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
- }
- };
-}
-
-// Test empty polymorphic classes.
-//
-#pragma db namespace table("t10_")
-namespace test10
-{
- #pragma db object polymorphic
- struct root
- {
- virtual ~root () = 0; // Auto-abstract.
- root () {}
- root (unsigned long i): id (i) {}
-
- #pragma db id
- unsigned long id;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (root))
- return false;
-
- return id == r.id;
- }
- };
-
- inline root::
- ~root () {}
-
- inline bool
- operator== (const root& x, const root& y) {return x.compare (y);}
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long i, unsigned long n): root (i), num (n) {}
-
- unsigned long num;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (base))
- return false;
-
- const base& b (static_cast<const base&> (r));
- return root::compare (r, false) && num == b.num;
- }
- };
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, unsigned long n): base (i, n) {}
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived))
- return false;
-
- return base::compare (r, false);
- }
- };
-}
-
-// Test mixing reuse and polymorphic inheritance.
-//
-#pragma db namespace table("t11_")
-namespace test11
-{
- #pragma db object abstract
- struct root
- {
- root () {}
- root (unsigned long i, unsigned long n): id (i), num (n) {}
-
- #pragma db id
- unsigned long id;
-
- unsigned long num;
- std::vector<std::string> strs;
- };
-
- #pragma db object polymorphic
- struct base: root
- {
- virtual ~base () {}
- base () {}
- base (unsigned long i, unsigned long n, const std::string& s)
- : root (i, n), str (s) {}
-
- std::string str;
- std::vector<unsigned long> nums;
-
- virtual bool
- compare (const base& b, bool tc = true) const
- {
- if (tc && typeid (b) != typeid (base))
- return false;
-
- return id == b.id && num == b.num && strs == b.strs &&
- str == b.str && nums == b.nums;
- }
- };
-
- inline bool
- operator== (const base& x, const base& y) {return x.compare (y);}
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long i, unsigned long n, const std::string& s)
- : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
-
- unsigned long dnum;
- std::string dstr;
-
- virtual bool
- compare (const base& b, bool tc = true) const
- {
- if (tc && typeid (b) != typeid (derived))
- return false;
-
- const derived& d (static_cast<const derived&> (b));
- return base::compare (b, false) && dnum == d.dnum && dstr == d.dstr;
- }
- };
-}
-
-// Test polymorphic classes with private auto id.
-//
-#pragma db namespace table("t12_")
-namespace test12
-{
- #pragma db object polymorphic
- struct root
- {
- virtual ~root () = 0; // Auto-abstract.
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (root))
- return false;
-
- return id_ == r.id_;
- }
-
- unsigned long id () const {return id_;}
- void id (unsigned long id) {id_ = id;}
- private:
- #pragma db id auto access(id)
- unsigned long id_;
- };
-
- inline root::
- ~root () {}
-
- inline bool
- operator== (const root& x, const root& y) {return x.compare (y);}
-
- #pragma db object
- struct base: root
- {
- base () {}
- base (unsigned long n): num (n) {}
-
- unsigned long num;
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (base))
- return false;
-
- const base& b (static_cast<const base&> (r));
- return root::compare (r, false) && num == b.num;
- }
- };
-
- #pragma db object
- struct derived: base
- {
- derived () {}
- derived (unsigned long n): base (n) {}
-
- virtual bool
- compare (const root& r, bool tc = true) const
- {
- if (tc && typeid (r) != typeid (derived))
- return false;
-
- return base::compare (r, false);
- }
- };
-}
-
-#endif // TEST_HXX
diff --git a/common/polymorphism/test1.hxx b/common/polymorphism/test1.hxx
new file mode 100644
index 0000000..e6db3f4
--- /dev/null
+++ b/common/polymorphism/test1.hxx
@@ -0,0 +1,116 @@
+// file : common/polymorphism/test1.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST1_HXX
+#define TEST1_HXX
+
+#include <string>
+#include <vector>
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test basic polymorphism functionality.
+//
+#pragma db namespace table("t1_")
+namespace test1
+{
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () {}
+ root () {}
+ root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ std::vector<std::string> strs;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (root))
+ return false;
+
+ return id == r.id && num == r.num && strs == r.strs;
+ }
+ };
+
+ inline bool
+ operator== (const root& x, const root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, unsigned long n, const std::string& s)
+ : root (i, n), str (s) {}
+
+ std::string str;
+ std::vector<unsigned long> nums;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (base))
+ return false;
+
+ const base& b (static_cast<const base&> (r));
+ return root::compare (r, false) && str == b.str && nums == b.nums;
+ }
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, unsigned long n, const std::string& s)
+ : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived))
+ return false;
+
+ const derived& d (static_cast<const derived&> (r));
+ return base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
+ }
+ };
+
+ // Views.
+ //
+ #pragma db view object(root)
+ struct root_view
+ {
+ //#pragma db column(root::typeid_)
+ std::string typeid_; // @@ tmp
+
+ unsigned long num;
+ };
+
+ #pragma db view object(base = b)
+ struct base_view
+ {
+ unsigned long id;
+ unsigned long num;
+ std::string str;
+ };
+
+ #pragma db view object(derived)
+ struct derived_view
+ {
+ unsigned long num;
+ std::string str;
+ unsigned long dnum;
+ std::string dstr;
+ };
+}
+
+#endif // TEST1_HXX
diff --git a/common/polymorphism/test10.hxx b/common/polymorphism/test10.hxx
new file mode 100644
index 0000000..be7d3c0
--- /dev/null
+++ b/common/polymorphism/test10.hxx
@@ -0,0 +1,79 @@
+// file : common/polymorphism/test10.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST10_HXX
+#define TEST10_HXX
+
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test empty polymorphic classes.
+//
+#pragma db namespace table("t10_")
+namespace test10
+{
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () = 0; // Auto-abstract.
+ root () {}
+ root (unsigned long i): id (i) {}
+
+ #pragma db id
+ unsigned long id;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (root))
+ return false;
+
+ return id == r.id;
+ }
+ };
+
+ inline root::
+ ~root () {}
+
+ inline bool
+ operator== (const root& x, const root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, unsigned long n): root (i), num (n) {}
+
+ unsigned long num;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (base))
+ return false;
+
+ const base& b (static_cast<const base&> (r));
+ return root::compare (r, false) && num == b.num;
+ }
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, unsigned long n): base (i, n) {}
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived))
+ return false;
+
+ return base::compare (r, false);
+ }
+ };
+}
+
+#endif // TEST10_HXX
diff --git a/common/polymorphism/test11.hxx b/common/polymorphism/test11.hxx
new file mode 100644
index 0000000..58a4ff4
--- /dev/null
+++ b/common/polymorphism/test11.hxx
@@ -0,0 +1,79 @@
+// file : common/polymorphism/test11.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST11_HXX
+#define TEST11_HXX
+
+#include <string>
+#include <vector>
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test mixing reuse and polymorphic inheritance.
+//
+#pragma db namespace table("t11_")
+namespace test11
+{
+ #pragma db object abstract
+ struct root
+ {
+ root () {}
+ root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ std::vector<std::string> strs;
+ };
+
+ #pragma db object polymorphic
+ struct base: root
+ {
+ virtual ~base () {}
+ base () {}
+ base (unsigned long i, unsigned long n, const std::string& s)
+ : root (i, n), str (s) {}
+
+ std::string str;
+ std::vector<unsigned long> nums;
+
+ virtual bool
+ compare (const base& b, bool tc = true) const
+ {
+ if (tc && typeid (b) != typeid (base))
+ return false;
+
+ return id == b.id && num == b.num && strs == b.strs &&
+ str == b.str && nums == b.nums;
+ }
+ };
+
+ inline bool
+ operator== (const base& x, const base& y) {return x.compare (y);}
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, unsigned long n, const std::string& s)
+ : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+
+ virtual bool
+ compare (const base& b, bool tc = true) const
+ {
+ if (tc && typeid (b) != typeid (derived))
+ return false;
+
+ const derived& d (static_cast<const derived&> (b));
+ return base::compare (b, false) && dnum == d.dnum && dstr == d.dstr;
+ }
+ };
+}
+
+#endif // TEST11_HXX
diff --git a/common/polymorphism/test12.hxx b/common/polymorphism/test12.hxx
new file mode 100644
index 0000000..5feb2bb
--- /dev/null
+++ b/common/polymorphism/test12.hxx
@@ -0,0 +1,80 @@
+// file : common/polymorphism/test12.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST12_HXX
+#define TEST12_HXX
+
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test polymorphic classes with private auto id.
+//
+#pragma db namespace table("t12_")
+namespace test12
+{
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () = 0; // Auto-abstract.
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (root))
+ return false;
+
+ return id_ == r.id_;
+ }
+
+ unsigned long id () const {return id_;}
+ void id (unsigned long id) {id_ = id;}
+ private:
+ #pragma db id auto access(id)
+ unsigned long id_;
+ };
+
+ inline root::
+ ~root () {}
+
+ inline bool
+ operator== (const root& x, const root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long n): num (n) {}
+
+ unsigned long num;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (base))
+ return false;
+
+ const base& b (static_cast<const base&> (r));
+ return root::compare (r, false) && num == b.num;
+ }
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long n): base (n) {}
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived))
+ return false;
+
+ return base::compare (r, false);
+ }
+ };
+}
+
+#endif // TEST12_HXX
diff --git a/common/polymorphism/test2.hxx b/common/polymorphism/test2.hxx
new file mode 100644
index 0000000..1b81f41
--- /dev/null
+++ b/common/polymorphism/test2.hxx
@@ -0,0 +1,106 @@
+// file : common/polymorphism/test2.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST2_HXX
+#define TEST2_HXX
+
+#include <string>
+#include <vector>
+
+#include <odb/core.hxx>
+#include <odb/lazy-ptr.hxx>
+
+// Test inverse object pointers in polymorhic bases.
+//
+#pragma db namespace table("t2_")
+namespace test2
+{
+ struct root;
+
+ #pragma db object
+ struct root_pointer
+ {
+ root_pointer (root* r = 0): p (r) {}
+
+ #pragma db id auto
+ unsigned long id;
+
+ root* p;
+ };
+
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () {}
+ root () {}
+ root (unsigned long i): id (i) {}
+
+ #pragma db id
+ unsigned long id;
+
+ #pragma db inverse(p)
+ odb::lazy_ptr<root_pointer> rp;
+ };
+
+ struct base;
+
+ #pragma db object
+ struct base_pointer
+ {
+ base_pointer (base* b = 0) {if (b != 0) vp.push_back (b);}
+
+ #pragma db id auto
+ unsigned long id;
+
+ std::vector<base*> vp;
+ };
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, const std::string& s): root (i), str (s) {}
+
+ std::string str;
+
+ #pragma db inverse(vp)
+ odb::lazy_ptr<base_pointer> bp;
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, const std::string& s, unsigned long n)
+ : base (i, s), num (n) {}
+
+ unsigned long num;
+ };
+
+ // Views.
+ //
+ #pragma db view object(root_pointer = rp) object(root)
+ struct root_view
+ {
+ #pragma db column(rp::id)
+ unsigned long rp_id;
+
+ #pragma db column(root::id)
+ unsigned long r_id;
+ };
+
+ #pragma db view object(base_pointer) object(base = b)
+ struct base_view
+ {
+ #pragma db column(base_pointer::id)
+ unsigned long bp_id;
+
+ #pragma db column(b::id)
+ unsigned long b_id;
+
+ std::string str;
+ };
+}
+
+#endif // TEST2_HXX
diff --git a/common/polymorphism/test3.hxx b/common/polymorphism/test3.hxx
new file mode 100644
index 0000000..9a9a269
--- /dev/null
+++ b/common/polymorphism/test3.hxx
@@ -0,0 +1,147 @@
+// file : common/polymorphism/test3.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST3_HXX
+#define TEST3_HXX
+
+#include <string>
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test delayed loading.
+//
+#pragma db namespace table("t3_")
+namespace test3
+{
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () {}
+ root () {}
+ root (unsigned long i): id (i) {}
+
+ #pragma db id
+ unsigned long id;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (root))
+ return false;
+
+ return id == r.id;
+ }
+ };
+
+ inline bool
+ operator== (const root& x, const root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct base: root
+ {
+ virtual ~base () {delete rptr;}
+ base (): rptr (0) {}
+ base (unsigned long i, unsigned long n): root (i), num (n), rptr (0) {}
+
+ unsigned long num;
+ root* rptr;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (base))
+ return false;
+
+ const base& b (static_cast<const base&> (r));
+ return
+ root::compare (r, false) &&
+ num == b.num &&
+ ((rptr == 0 && b.rptr == 0) || rptr->compare (*b.rptr));
+ }
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ virtual ~derived () {delete bptr;}
+ derived (): bptr (0) {}
+ derived (unsigned long i, unsigned long n, const std::string& s)
+ : base (i, n), str (s), bptr (0) {}
+
+ std::string str;
+ base* bptr;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived))
+ return false;
+
+ const derived& d (static_cast<const derived&> (r));
+ return
+ base::compare (r, false) &&
+ str == d.str &&
+ ((bptr == 0 && d.bptr == 0) || bptr->compare (*d.bptr));
+ }
+ };
+
+ // Views.
+ //
+ #pragma db view object(base) object(root = r)
+ struct base_view
+ {
+ #pragma db column(base::id)
+ unsigned long b_id;
+
+ #pragma db column(r::id)
+ unsigned long r_id;
+
+ unsigned long num;
+ };
+
+ #pragma db view \
+ object(derived = d) \
+ object(base = b) \
+ object(root = r: d::rptr)
+ struct derived_view
+ {
+ #pragma db column(d::id)
+ unsigned long d_id;
+
+ #pragma db column(b::id)
+ unsigned long b_id;
+
+ #pragma db column(r::id)
+ unsigned long r_id;
+
+ #pragma db column(d::num)
+ unsigned long d_num;
+
+ #pragma db column(b::num)
+ unsigned long b_num;
+
+ std::string str;
+ };
+
+ // This is an example of a pathological case, where the right-hand-side
+ // of the join condition comes from one of the bases. As a result, we
+ // join the base table first, which means we will get both bases and
+ // derived objects instead of just derived.
+ //
+ //#pragma db view object(root = r) object(derived = d)
+ #pragma db view object(derived = d) object(root = r)
+ struct root_view
+ {
+ #pragma db column(r::id)
+ unsigned long r_id;
+
+ #pragma db column(d::id)
+ unsigned long d_id;
+
+ std::string str;
+ };
+}
+
+#endif // TEST3_HXX
diff --git a/common/polymorphism/test4.hxx b/common/polymorphism/test4.hxx
new file mode 100644
index 0000000..d9eba86
--- /dev/null
+++ b/common/polymorphism/test4.hxx
@@ -0,0 +1,76 @@
+// file : common/polymorphism/test4.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST4_HXX
+#define TEST4_HXX
+
+#include <string>
+
+#include <odb/core.hxx>
+
+// Test views.
+//
+#pragma db namespace table("t4_")
+namespace test4
+{
+ #pragma db object polymorphic
+ struct root1
+ {
+ virtual ~root1 () {}
+ root1 () {}
+ root1 (unsigned long i): id (i) {}
+
+ #pragma db id
+ unsigned long id;
+ };
+
+ #pragma db object
+ struct base1: root1
+ {
+ base1 () {}
+ base1 (unsigned long i, unsigned long n): root1 (i), num (n) {}
+
+ unsigned long num;
+ };
+
+ #pragma db object polymorphic
+ struct root2
+ {
+ virtual ~root2 () {}
+ root2 () {}
+ root2 (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ };
+
+ #pragma db object
+ struct base2: root2
+ {
+ base2 () {}
+ base2 (unsigned long i, unsigned long n, const std::string& s)
+ : root2 (i, n), str (s) {}
+
+ std::string str;
+ };
+
+ // Test custom join condition.
+ //
+ #pragma db view object(base2) object(base1: base2::num == base1::num)
+ struct view1
+ {
+ std::string str;
+ };
+
+ #pragma db view object(base2)
+ struct view2
+ {
+ #pragma db column("min(" + base2::num + ")")
+ std::size_t min_num;
+ };
+}
+
+#endif // TEST4_HXX
diff --git a/common/polymorphism/test5.hxx b/common/polymorphism/test5.hxx
new file mode 100644
index 0000000..ede75a0
--- /dev/null
+++ b/common/polymorphism/test5.hxx
@@ -0,0 +1,93 @@
+// file : common/polymorphism/test5.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST5_HXX
+#define TEST5_HXX
+
+#include <string>
+#include <vector>
+#include <memory>
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test polymorphism and optimistic concurrency.
+//
+#pragma db namespace table("t5_")
+namespace test5
+{
+ #pragma db object polymorphic optimistic pointer(std::auto_ptr)
+ struct root
+ {
+ virtual ~root () {}
+ root () {}
+ root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ #pragma db version
+ unsigned long version;
+
+ unsigned long num;
+ std::vector<std::string> strs;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (root))
+ return false;
+
+ return id == r.id && version == r.version &&
+ num == r.num && strs == r.strs;
+ }
+ };
+
+ inline bool
+ operator== (const root& x, const root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, unsigned long n, const std::string& s)
+ : root (i, n), str (s) {}
+
+ std::string str;
+ std::vector<unsigned long> nums;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (base))
+ return false;
+
+ const base& b (static_cast<const base&> (r));
+ return root::compare (r, false) && str == b.str && nums == b.nums;
+ }
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, unsigned long n, const std::string& s)
+ : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived))
+ return false;
+
+ const derived& d (static_cast<const derived&> (r));
+ return base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
+ }
+ };
+}
+
+#endif // TEST5_HXX
diff --git a/common/polymorphism/test6.hxx b/common/polymorphism/test6.hxx
new file mode 100644
index 0000000..9ecef40
--- /dev/null
+++ b/common/polymorphism/test6.hxx
@@ -0,0 +1,65 @@
+// file : common/polymorphism/test6.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST6_HXX
+#define TEST6_HXX
+
+#include <string>
+#include <memory>
+
+#include <odb/core.hxx>
+#include <odb/callback.hxx>
+
+// Test polymorphism and callbacks.
+//
+#pragma db namespace table("t6_")
+namespace test6
+{
+ #pragma db object polymorphic pointer(std::auto_ptr)
+ struct root
+ {
+ virtual ~root () {}
+ root (): id (0) {}
+ root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ };
+
+ #pragma db object callback(db_callback)
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, unsigned long n, const std::string& s)
+ : root (i, n), str (s) {}
+
+ std::string str;
+
+ void
+ db_callback (odb::callback_event, odb::database&);
+
+ void
+ db_callback (odb::callback_event, odb::database&) const;
+ };
+
+ #pragma db object callback(db_callback)
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, unsigned long n, const std::string& s)
+ : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+
+ std::auto_ptr<root> ptr;
+
+ void
+ db_callback (odb::callback_event, odb::database&) const;
+ };
+}
+
+#endif // TEST6_HXX
diff --git a/common/polymorphism/test7.hxx b/common/polymorphism/test7.hxx
new file mode 100644
index 0000000..1d3a807
--- /dev/null
+++ b/common/polymorphism/test7.hxx
@@ -0,0 +1,67 @@
+// file : common/polymorphism/test7.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST7_HXX
+#define TEST7_HXX
+
+#include <common/config.hxx> // HAVE_CXX11, HAVE_TR1_MEMORY
+
+#include <string>
+#include <memory>
+
+#if !defined(HAVE_CXX11) && defined(HAVE_TR1_MEMORY)
+# include <odb/tr1/memory.hxx>
+#endif
+
+#include <odb/core.hxx>
+
+// Test polymorphism and object cache (session).
+//
+#if defined(HAVE_CXX11) || defined(HAVE_TR1_MEMORY)
+#pragma db namespace table("t7_")
+namespace test7
+{
+#ifdef HAVE_CXX11
+ using std::shared_ptr;
+#else
+ using std::tr1::shared_ptr;
+#endif
+
+ #pragma db object polymorphic pointer(shared_ptr) session
+ struct root
+ {
+ virtual ~root () {}
+ root (): id (0) {}
+ root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ };
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, unsigned long n, const std::string& s)
+ : root (i, n), str (s) {}
+
+ std::string str;
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived () {}
+ derived (unsigned long i, unsigned long n, const std::string& s)
+ : base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+ };
+}
+#endif
+
+#endif // TEST7_HXX
diff --git a/common/polymorphism/test8.hxx b/common/polymorphism/test8.hxx
new file mode 100644
index 0000000..adaafc2
--- /dev/null
+++ b/common/polymorphism/test8.hxx
@@ -0,0 +1,130 @@
+// file : common/polymorphism/test8.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST8_HXX
+#define TEST8_HXX
+
+#include <string>
+#include <vector>
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test polymorphism and abstract bases.
+//
+#pragma db namespace table("t8_")
+namespace test8
+{
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () = 0; // Auto-abstract.
+ root () {}
+ root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ std::vector<std::string> strs;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (root))
+ return false;
+
+ return id == r.id && num == r.num && strs == r.strs;
+ }
+ };
+
+ inline root::
+ ~root () {}
+
+ inline bool
+ operator== (const root& x, const root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct base: root
+ {
+ base () {}
+ base (unsigned long i, unsigned long n, const std::string& s)
+ : root (i, n), str (s) {}
+
+ std::string str;
+ std::vector<unsigned long> nums;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (base))
+ return false;
+
+ const base& b (static_cast<const base&> (r));
+ return root::compare (r, false) && str == b.str && nums == b.nums;
+ }
+ };
+
+ #pragma db object abstract
+ struct interm: base
+ {
+ interm () {}
+ interm (unsigned long i, unsigned long n, const std::string& s, bool b)
+ : base (i, n, s), bln (b) {}
+
+ bool bln;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (interm))
+ return false;
+
+ const interm& i (static_cast<const interm&> (r));
+ return base::compare (r, false) && bln == i.bln;
+ }
+ };
+
+ #pragma db object
+ struct derived1: interm
+ {
+ derived1 () {}
+ derived1 (unsigned long i, unsigned long n, const std::string& s, bool b)
+ : interm (i, n, s, b), dnum (n + 1) {}
+
+ unsigned long dnum;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived1))
+ return false;
+
+ const derived1& d (static_cast<const derived1&> (r));
+ return interm::compare (r, false) && dnum == d.dnum;
+ }
+ };
+
+ #pragma db object
+ struct derived2: interm
+ {
+ derived2 () {}
+ derived2 (unsigned long i, unsigned long n, const std::string& s, bool b)
+ : interm (i, n, s, b), dstr (s + 'd') {}
+
+ std::string dstr;
+
+ virtual bool
+ compare (const root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (derived2))
+ return false;
+
+ const derived2& d (static_cast<const derived2&> (r));
+ return interm::compare (r, false) && dstr == d.dstr;
+ }
+ };
+}
+
+#endif // TEST8_HXX
diff --git a/common/polymorphism/test9.hxx b/common/polymorphism/test9.hxx
new file mode 100644
index 0000000..d1496c1
--- /dev/null
+++ b/common/polymorphism/test9.hxx
@@ -0,0 +1,162 @@
+// file : common/polymorphism/test9.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST9_HXX
+#define TEST9_HXX
+
+#include <string>
+#include <vector>
+#include <typeinfo>
+
+#include <odb/core.hxx>
+
+// Test polymorphism and readonly classes.
+//
+#pragma db namespace table("t9_")
+namespace test9
+{
+ //
+ // ro_root, rw_base, ro_derived
+ //
+ #pragma db object polymorphic readonly
+ struct ro_root
+ {
+ virtual ~ro_root () {}
+ ro_root () {}
+ ro_root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ std::vector<std::string> strs;
+
+ virtual bool
+ compare (const ro_root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (ro_root))
+ return false;
+
+ return id == r.id && num == r.num && strs == r.strs;
+ }
+ };
+
+ inline bool
+ operator== (const ro_root& x, const ro_root& y) {return x.compare (y);}
+
+ #pragma db object
+ struct rw_base: ro_root
+ {
+ rw_base () {}
+ rw_base (unsigned long i, unsigned long n, const std::string& s)
+ : ro_root (i, n), str (s) {}
+
+ std::string str;
+ std::vector<unsigned long> nums;
+
+ virtual bool
+ compare (const ro_root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (rw_base))
+ return false;
+
+ const rw_base& b (static_cast<const rw_base&> (r));
+ return ro_root::compare (r, false) && str == b.str && nums == b.nums;
+ }
+ };
+
+ #pragma db object readonly
+ struct ro_derived: rw_base
+ {
+ ro_derived () {}
+ ro_derived (unsigned long i, unsigned long n, const std::string& s)
+ : rw_base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+
+ virtual bool
+ compare (const ro_root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (ro_derived))
+ return false;
+
+ const ro_derived& d (static_cast<const ro_derived&> (r));
+ return rw_base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
+ }
+ };
+
+ //
+ // rw_root, ro_base, rw_derived
+ //
+ #pragma db object polymorphic
+ struct rw_root
+ {
+ virtual ~rw_root () {}
+ rw_root () {}
+ rw_root (unsigned long i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ unsigned long id;
+
+ unsigned long num;
+ std::vector<std::string> strs;
+
+ virtual bool
+ compare (const rw_root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (rw_root))
+ return false;
+
+ return id == r.id && num == r.num && strs == r.strs;
+ }
+ };
+
+ inline bool
+ operator== (const rw_root& x, const rw_root& y) {return x.compare (y);}
+
+ #pragma db object readonly
+ struct ro_base: rw_root
+ {
+ ro_base () {}
+ ro_base (unsigned long i, unsigned long n, const std::string& s)
+ : rw_root (i, n), str (s) {}
+
+ std::string str;
+ std::vector<unsigned long> nums;
+
+ virtual bool
+ compare (const rw_root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (ro_base))
+ return false;
+
+ const ro_base& b (static_cast<const ro_base&> (r));
+ return rw_root::compare (r, false) && str == b.str && nums == b.nums;
+ }
+ };
+
+ #pragma db object
+ struct rw_derived: ro_base
+ {
+ rw_derived () {}
+ rw_derived (unsigned long i, unsigned long n, const std::string& s)
+ : ro_base (i, n, s), dnum (n + 1), dstr (s + 'd') {}
+
+ unsigned long dnum;
+ std::string dstr;
+
+ virtual bool
+ compare (const rw_root& r, bool tc = true) const
+ {
+ if (tc && typeid (r) != typeid (rw_derived))
+ return false;
+
+ const rw_derived& d (static_cast<const rw_derived&> (r));
+ return ro_base::compare (r, false) && dnum == d.dnum && dstr == d.dstr;
+ }
+ };
+}
+
+#endif // TEST9_HXX