diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-16 08:19:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-16 08:19:25 +0200 |
commit | b92d2fd35052373476fd392238695fe145ef49c2 (patch) | |
tree | af4c12eac442ab3e54b20f53d2ffeb7f44ffe1cb /common/inverse/test.hxx | |
parent | ae6efed243e2ba2a611014707368de6a86d74940 (diff) |
Implement support for nested members in inverse pragma
Diffstat (limited to 'common/inverse/test.hxx')
-rw-r--r-- | common/inverse/test.hxx | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/common/inverse/test.hxx b/common/inverse/test.hxx index 52a525d..6dfedda 100644 --- a/common/inverse/test.hxx +++ b/common/inverse/test.hxx @@ -311,4 +311,92 @@ namespace test3 } }; +// Test inverse with nested data members. +// +#pragma db namespace table("t4_") +namespace test4 +{ + // Inverse pointer. + // + struct obj1; + struct obj2; + + #pragma db value + struct obj2_id + { + #pragma db points_to(obj1) + int i; + int j; + }; + + inline bool + operator< (obj2_id x, obj2_id y) + {return x.i < y.i || (x.i == y.i && x.j < y.j);} + + #pragma db object + struct obj1 + { + #pragma db id auto + int id; + + #pragma db inverse(id.i) + obj2* o2; + + obj1 (): o2 (0) {} + ~obj1 (); + }; + + #pragma db object + struct obj2 + { + #pragma db id + obj2_id id; + }; + + inline obj1:: + ~obj1 () {delete o2;} + + // Inverse container of pointers. + // + struct obj3; + struct obj4; + + #pragma db value + struct obj4_id + { + #pragma db points_to(obj3) + int i; + int j; + }; + + inline bool + operator< (obj4_id x, obj4_id y) + {return x.i < y.i || (x.i == y.i && x.j < y.j);} + + #pragma db object + struct obj3 + { + #pragma db id auto + int id; + + #pragma db inverse(id.i) + std::vector<obj4*> o4; + + ~obj3 (); + }; + + #pragma db object + struct obj4 + { + #pragma db id + obj4_id id; + }; + + inline obj3:: + ~obj3 () + { + for (std::vector<obj4*>::iterator i (o4.begin ()); i != o4.end (); ++i) + delete *i; + } +}; #endif // TEST_HXX |