aboutsummaryrefslogtreecommitdiff
path: root/odb/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:29:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-04 13:29:43 +0200
commit14392d7ca625facaf509b354f19ece627b81a4b0 (patch)
treee422c02227501f2e7e29a20f69dcac4b8d82ba40 /odb/context.cxx
parentc7a98034ccc3425090dddade05fd09d54d1f940f (diff)
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.
Diffstat (limited to 'odb/context.cxx')
-rw-r--r--odb/context.cxx127
1 files changed, 110 insertions, 17 deletions
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<bool> ("wrapper"))
+ {
+ // First see if it is null by default.
+ //
+ if (t.get<bool> ("wrapper-null-handler") &&
+ t.get<bool> ("wrapper-null-default"))
+ return true;
+
+ // Otherwise, check the wrapped type.
+ //
+ if (t.get<semantics::type*> ("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<bool> ("wrapper"))
+ {
+ // First see if it is null by default.
+ //
+ if (t.get<bool> ("wrapper-null-handler") &&
+ t.get<bool> ("wrapper-null-default"))
+ return true;
+
+ // Otherwise, check the wrapped type.
+ //
+ if (t.get<semantics::type*> ("wrapper-type")->count ("null"))
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
}
string context::