aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-04-25 15:02:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-04-25 15:02:43 +0200
commit804603f33868af0450f179f66e2ddb16b84bdb80 (patch)
treecd5665bb838b6e7df1cd9ab7d08ce11d10144f4c
parent5f821d47f0ee08a3a08962d0dc641326618dbf50 (diff)
Add support for abstract object types
-rw-r--r--common/inheritance/driver.cxx30
-rw-r--r--common/inheritance/test.hxx59
2 files changed, 82 insertions, 7 deletions
diff --git a/common/inheritance/driver.cxx b/common/inheritance/driver.cxx
index 99dc1c5..9bb8477 100644
--- a/common/inheritance/driver.cxx
+++ b/common/inheritance/driver.cxx
@@ -64,9 +64,33 @@ main (int argc, char* argv[])
o2.strs_.push_back ("base o2o2o2 one");
o2.strs_.push_back ("base o2o2o2 two");
+ object3 o3;
+ o3.comp_.bools.push_back (false);
+ o3.comp_.bools.push_back (false);
+ o3.comp_.num = 13;
+ o3.comp_.str = "comp o3o3o3";
+ o3.comp_.nums.push_back (131);
+ o3.comp_.nums.push_back (132);
+ o3.num_ = 3;
+ o3.str_ = "base o3o3o3";
+ o3.strs_.push_back ("base o3o3o3 one");
+ o3.strs_.push_back ("base o3o3o3 two");
+
reference r;
r.o1_ = &o1;
+ empty e;
+ e.comp_.bools.push_back (true);
+ e.comp_.bools.push_back (true);
+ e.comp_.num = 14;
+ e.comp_.str = "comp eee";
+ e.comp_.nums.push_back (141);
+ e.comp_.nums.push_back (142);
+ e.num_ = 4;
+ e.str_ = "base eee";
+ e.strs_.push_back ("base eee one");
+ e.strs_.push_back ("base eee two");
+
// persist
//
{
@@ -74,7 +98,9 @@ main (int argc, char* argv[])
db->persist (b);
db->persist (o1);
db->persist (o2);
+ db->persist (o3);
db->persist (r);
+ db->persist (e);
t.commit ();
}
@@ -85,13 +111,17 @@ main (int argc, char* argv[])
auto_ptr<base> lb (db->load<base> (b.id_));
auto_ptr<object1> lo1 (db->load<object1> (o1.id_));
auto_ptr<object2> lo2 (db->load<object2> (o2.id_));
+ auto_ptr<object3> lo3 (db->load<object3> (o3.id_));
+ auto_ptr<empty> le (db->load<empty> (e.id_));
auto_ptr<reference> lr (db->load<reference> (r.id_));
t.commit ();
assert (b == *lb);
assert (o1 == *lo1);
assert (o2 == *lo2);
+ assert (o3 == *lo3);
assert (lr->o1_->id_ == r.o1_->id_);
+ assert (e == *le);
delete lr->o1_;
}
diff --git a/common/inheritance/test.hxx b/common/inheritance/test.hxx
index 31ef9c1..5ef2ea4 100644
--- a/common/inheritance/test.hxx
+++ b/common/inheritance/test.hxx
@@ -42,12 +42,9 @@ struct comp: comp_base
}
};
-#pragma db object
-struct base
+#pragma db object abstract
+struct abstract_base
{
- #pragma db id auto
- unsigned long id_;
-
comp comp_;
unsigned int num_;
@@ -56,10 +53,9 @@ struct base
std::vector<std::string> strs_;
bool
- operator== (const base& y) const
+ operator== (const abstract_base& y) const
{
return
- id_ == y.id_ &&
comp_ == y.comp_ &&
num_ == y.num_ &&
str_ == y.str_ &&
@@ -68,6 +64,19 @@ struct base
};
#pragma db object
+struct base: abstract_base
+{
+ #pragma db id auto
+ unsigned long id_;
+
+ bool
+ operator== (const base& y) const
+ {
+ return id_ == y.id_ && static_cast<const abstract_base&> (*this) == y;
+ }
+};
+
+#pragma db object
struct object1: base
{
unsigned int num1_;
@@ -92,6 +101,8 @@ struct object2: base
}
};
+// Reference to derived object.
+//
#pragma db object
struct reference
{
@@ -101,4 +112,38 @@ struct reference
object1* o1_;
};
+// Multiple inheritance.
+//
+#pragma db object abstract
+struct id_base
+{
+ #pragma db id auto
+ unsigned long id_;
+
+ bool
+ operator== (const id_base& y) const
+ {
+ return id_ == y.id_;
+ }
+};
+
+#pragma db object
+struct object3: abstract_base, id_base
+{
+ bool
+ operator== (const object3& y) const
+ {
+ return
+ static_cast<const abstract_base&> (*this) == y &&
+ static_cast<const id_base&> (*this) == y;
+ }
+};
+
+// Empty derived object.
+//
+#pragma db object
+struct empty: base
+{
+};
+
#endif // TEST_HXX