From 5adda85ed10d9196f4d68cc4b8fee12f6ba9cfec Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Dec 2010 10:36:15 +0200 Subject: Add lazy pointer support Built-in support is provided for raw, auto, and tr1 shared/weak pointers. New test: common/lazy-ptr. --- odb/context.hxx | 131 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 44 deletions(-) (limited to 'odb/context.hxx') diff --git a/odb/context.hxx b/odb/context.hxx index 47375a3..6f5e89e 100644 --- a/odb/context.hxx +++ b/odb/context.hxx @@ -25,6 +25,16 @@ using std::cerr; class generation_failed {}; +// Keep this enum synchronized with the one in libodb/odb/pointer-traits.hxx. +// +enum pointer_kind +{ + pk_naked, + pk_unique, + pk_shared, + pk_weak +}; + // Keep this enum synchronized with the one in libodb/odb/container-traits.hxx. // enum container_kind @@ -43,6 +53,15 @@ public: typedef std::string string; typedef ::options options_type; +public: + static semantics::type& + member_type (semantics::data_member& m, string const& key_prefix) + { + return key_prefix.empty () + ? m.type () + : *m.type ().get ("tree-" + key_prefix + "-type"); + } + // Predicates. // public: @@ -78,50 +97,9 @@ public: } static semantics::class_* - object_pointer (semantics::data_member& m, - string const& key_prefix = string ()) + object_pointer (semantics::type& t) { - using semantics::class_; - - return key_prefix.empty () - ? m.get ("object-pointer", 0) - : m.get (key_prefix + "-object-pointer", 0); - } - - static bool - null_pointer (semantics::data_member& m) - { - return !(m.count ("not-null") || m.type ().count ("not-null")); - } - - static bool - null_pointer (semantics::data_member& m, string const& key_prefix) - { - if (key_prefix.empty ()) - return null_pointer (m); - - return !(m.count (key_prefix + "-not-null") || - m.type ().count ("not-null") || - m.type ().get ( - "tree-" + key_prefix +"-type")->count ("not-null")); - } - - static semantics::data_member* - inverse (semantics::data_member& m, string const& key_prefix = string ()) - { - using semantics::data_member; - - return object_pointer (m, key_prefix) - ? (key_prefix.empty () - ? m.get ("inverse", 0) - : m.get (key_prefix + "-inverse", 0)) - : 0; - } - - static bool - unordered (semantics::data_member& m) - { - return m.count ("unordered") || m.type ().count ("unordered"); + return t.get ("element-type", 0); } // Database names and types. @@ -187,6 +165,65 @@ public: semantics::data_member& id_member (semantics::class_&); + // Object pointer information. + // +public: + typedef ::pointer_kind pointer_kind_type; + + static pointer_kind_type + pointer_kind (semantics::type& p) + { + return p.get ("pointer-kind"); + } + + static bool + lazy_pointer (semantics::type& p) + { + return p.get ("pointer-lazy"); + } + + static bool + weak_pointer (semantics::type& p) + { + return pointer_kind (p) == pk_weak; + } + + static bool + null_pointer (semantics::data_member& m) + { + return !(m.count ("not-null") || m.type ().count ("not-null")); + } + + static bool + null_pointer (semantics::data_member& m, string const& key_prefix) + { + if (key_prefix.empty ()) + return null_pointer (m); + + return !(m.count (key_prefix + "-not-null") || + m.type ().count ("not-null") || + member_type (m, key_prefix).count ("not-null")); + } + + static semantics::data_member* + inverse (semantics::data_member& m) + { + return object_pointer (m.type ()) + ? m.get ("inverse", 0) + : 0; + } + + static semantics::data_member* + inverse (semantics::data_member& m, string const& key_prefix) + { + if (key_prefix.empty ()) + return inverse (m); + + return object_pointer (member_type (m, key_prefix)) + ? m.get (key_prefix + "-inverse", 0) + : 0; + } + // Container information. // public: @@ -216,10 +253,16 @@ public: return *c.get ("tree-key-type"); } + static bool + unordered (semantics::data_member& m) + { + return m.count ("unordered") || m.type ().count ("unordered"); + } + // The 'is a' and 'has a' tests. The has_a test currently does not // cross the container boundaries. // - +public: static unsigned short const test_pointer = 0x01; static unsigned short const test_eager_pointer = 0x02; static unsigned short const test_lazy_pointer = 0x04; -- cgit v1.1