From 14392d7ca625facaf509b354f19ece627b81a4b0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 4 Aug 2011 13:29:43 +0200 Subject: Add support for value wrappers Wrapper is a class that wraps another type. Examples of wrappers are various smart pointers, holders, etc. A wrapper can be transparent or it can handle the NULL semantics. The new odb::nullable class template is a NULL wrapper that helps to add the NULL semantics to a value type. New test: common/wrapper. --- odb/context.cxx | 127 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 17 deletions(-) (limited to 'odb/context.cxx') diff --git a/odb/context.cxx b/odb/context.cxx index 3b684ea..0280c28 100644 --- a/odb/context.cxx +++ b/odb/context.cxx @@ -150,17 +150,60 @@ null (semantics::data_member& m) { semantics::type& t (m.type ()); - // By default pointers can be null. - // if (object_pointer (t)) - return m.count ("null") || - (!m.count ("not-null") && - (t.count ("null") || !t.count ("not-null"))); + { + // By default pointers can be null. + // + if (m.count ("null")) + return true; + + if (!m.count ("not-null")) + { + if (t.count ("null")) + return true; + + if (!t.count ("not-null")) + { + return true; + } + } + + return false; + } else + { // Everything else by default is not null. // - return m.count ("null") || - (!m.count ("not-null") && t.count ("null")); + if (m.count ("null")) + return true; + + if (!m.count ("not-null")) + { + if (t.count ("null")) + return true; + + if (!t.count ("not-null")) + { + // Check if this type is a wrapper. + // + if (t.get ("wrapper")) + { + // First see if it is null by default. + // + if (t.get ("wrapper-null-handler") && + t.get ("wrapper-null-default")) + return true; + + // Otherwise, check the wrapped type. + // + if (t.get ("wrapper-type")->count ("null")) + return true; + } + } + } + + return false; + } } bool context:: @@ -173,17 +216,67 @@ null (semantics::data_member& m, string const& kp) semantics::type& t (member_type (m, kp)); if (object_pointer (t)) - return m.count (kp + "-null") || - (!m.count (kp + "-not-null") && - (c.count (kp + "-null") || - (!c.count (kp + "-not-null") && - (t.count ("null") || !t.count ("not-null"))))); + { + if (m.count (kp + "-null")) + return true; + + if (!m.count (kp + "-not-null")) + { + if (c.count (kp + "-null")) + return true; + + if (!c.count (kp + "-not-null")) + { + if (t.count ("null")) + return true; + + if (!t.count ("not-null")) + { + return true; + } + } + } + + return false; + } else - return m.count (kp + "-null") || - (!m.count (kp + "-not-null") && - (c.count (kp + "-null") || - (!c.count (kp + "-not-null") && - t.count ("null")))); + { + if (m.count (kp + "-null")) + return true; + + if (!m.count (kp + "-not-null")) + { + if (c.count (kp + "-null")) + return true; + + if (!c.count (kp + "-not-null")) + { + if (t.count ("null")) + return true; + + if (!t.count ("not-null")) + { + // Check if this type is a wrapper. + // + if (t.get ("wrapper")) + { + // First see if it is null by default. + // + if (t.get ("wrapper-null-handler") && + t.get ("wrapper-null-default")) + return true; + + // Otherwise, check the wrapped type. + // + if (t.get ("wrapper-type")->count ("null")) + return true; + } + } + } + } + + return false; + } } string context:: -- cgit v1.1