aboutsummaryrefslogtreecommitdiff
path: root/common/polymorphism/test.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-04-25 09:04:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-04-25 09:04:35 +0200
commita93ad74833e3a99a1421fd695a01a1fb15d1f2dd (patch)
treef6ca24bc002c141fe7f9b9ae7bbe54d7772ad95b /common/polymorphism/test.hxx
parent2cd5cd2f706d0e76784bc297a02f9d655843f699 (diff)
Fix auto id handling in polymorphic objects
Diffstat (limited to 'common/polymorphism/test.hxx')
-rw-r--r--common/polymorphism/test.hxx67
1 files changed, 66 insertions, 1 deletions
diff --git a/common/polymorphism/test.hxx b/common/polymorphism/test.hxx
index 5e72b77..99711b5 100644
--- a/common/polymorphism/test.hxx
+++ b/common/polymorphism/test.hxx
@@ -887,7 +887,7 @@ namespace test10
struct base: root
{
base () {}
- base (unsigned long i, unsigned long n) : root (i), num (n) {}
+ base (unsigned long i, unsigned long n): root (i), num (n) {}
unsigned long num;
@@ -984,4 +984,69 @@ namespace test11
};
}
+// Test polymorphic classes with auto id.
+//
+#pragma db namespace table("t12_")
+namespace test12
+{
+ #pragma db object polymorphic
+ struct root
+ {
+ virtual ~root () = 0; // Auto-abstract.
+
+ #pragma db id auto
+ 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 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