From 4c87055fbbf4b36224cc4003cc9ae38023390400 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 7 Oct 2015 10:03:56 +0200 Subject: Add support for using object pointers as map keys Also remove the restriction for map keys and set values to be NOT NULL. Not clear why it was there in the first place and it could be useful if the key or value is an object pointer. --- odb/pragma.cxx | 26 +++++++++++++++++++- odb/processor.cxx | 56 +++++++++++++++++++------------------------- odb/relational/processor.cxx | 2 +- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 9bf38c5..0c925ca 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -624,6 +624,8 @@ check_spec_decl_type (declaration const& d, } else if (p == "null" || p == "not_null" || + p == "key_null" || + p == "key_not_null" || p == "value_null" || p == "value_not_null") { @@ -2252,11 +2254,15 @@ handle_pragma (cxx_lexer& l, } else if (p == "null" || p == "not_null" || + p == "key_null" || + p == "key_not_null" || p == "value_null" || p == "value_not_null") { // null // not_null + // key_null + // key_not_null // value_null // value_not_null // @@ -2851,7 +2857,9 @@ handle_pragma (cxx_lexer& l, name == "index-type" || name == "key-type" || - name == "value-null" || + name == "key-null" || + name == "key-not-null" || + name == "value-null" || name == "value-not-null" || name == "value-column" || @@ -3826,6 +3834,8 @@ handle_pragma_qualifier (cxx_lexer& l, string p) p == "table" || p == "null" || p == "not_null" || + p == "key_null" || + p == "key_not_null" || p == "value_null" || p == "value_not_null" || p == "default" || @@ -4175,6 +4185,18 @@ handle_pragma_db_value_not_null (cpp_reader* r) } extern "C" void +handle_pragma_db_key_null (cpp_reader* r) +{ + handle_pragma_qualifier (r, "key_null"); +} + +extern "C" void +handle_pragma_db_key_not_null (cpp_reader* r) +{ + handle_pragma_qualifier (r, "key_not_null"); +} + +extern "C" void handle_pragma_db_default (cpp_reader* r) { handle_pragma_qualifier (r, "default"); @@ -4323,6 +4345,8 @@ register_odb_pragmas (void*, void*) c_register_pragma_with_expansion ("db", "table", handle_pragma_db_table); c_register_pragma_with_expansion ("db", "null", handle_pragma_db_null); c_register_pragma_with_expansion ("db", "not_null", handle_pragma_db_not_null); + c_register_pragma_with_expansion ("db", "key_null", handle_pragma_db_key_null); + c_register_pragma_with_expansion ("db", "key_not_null", handle_pragma_db_key_not_null); c_register_pragma_with_expansion ("db", "value_null", handle_pragma_db_value_null); c_register_pragma_with_expansion ("db", "value_not_null", handle_pragma_db_value_not_null); c_register_pragma_with_expansion ("db", "default", handle_pragma_db_default); diff --git a/odb/processor.cxx b/odb/processor.cxx index f671e68..0b1ba36 100644 --- a/odb/processor.cxx +++ b/odb/processor.cxx @@ -1549,25 +1549,8 @@ namespace t.set ("value-tree-hint", vh); vt = &utype (m, vh, "value"); // Map. - // If we have a set container, automatically mark the value - // column as not null. If we already have an explicit null for - // this column, issue an error. - // - if (ck == ck_set) - { - if (t.count ("value-null")) - { - os << t.file () << ":" << t.line () << ":" << t.column () << ":" - << " error: set container cannot contain null values" << endl; - - throw operation_failed (); - } - else - t.set ("value-not-null", true); - } - - // Issue a warning if we are relaxing null-ness in the - // container type. + // Issue a warning if we are relaxing null-ness in the container + // type. // if (t.count ("value-null") && vt->count ("not-null")) { @@ -1640,10 +1623,19 @@ namespace throw; } - t.set ("key-not-null", true); t.set ("key-tree-type", kt); t.set ("key-tree-hint", kh); kt = &utype (m, kh, "key"); // Map. + + // Issue a warning if we are relaxing null-ness in the container + // type. + // + if (t.count ("key-null") && kt->count ("not-null")) + { + os << t.file () << ":" << t.line () << ":" << t.column () << ":" + << " warning: container key declared null while its type " + << "is declared not null" << endl; + } } // Check if we are versioned. For now we are not allowing for @@ -1708,7 +1700,7 @@ namespace process_container_value (*it, m, "index", false); if (kt != 0) - process_container_value (*kt, m, "key", false); + process_container_value (*kt, m, "key", true); // A map cannot be an inverse container. // @@ -1736,17 +1728,6 @@ namespace throw operation_failed (); } - // Issue an error if we have a null column in a set container. - // This can only happen if the value is declared as null in - // the member. - // - if (ck == ck_set && m.count ("value-null")) - { - os << m.file () << ":" << m.line () << ":" << m.column () << ":" - << " error: set container cannot contain null values" << endl; - throw operation_failed (); - } - // Issue a warning if we are relaxing null-ness in the member. // if (m.count ("value-null") && @@ -1757,6 +1738,17 @@ namespace << "type or value type declares it as not null" << endl; } + if (ck == ck_map || ck == ck_multimap) + { + if (m.count ("key-null") && + (t.count ("key-not-null") || kt->count ("not-null"))) + { + os << m.file () << ":" << m.line () << ":" << m.column () << ":" + << " warning: container key declared null while the container " + << "type or key type declares it as not null" << endl; + } + } + return true; } diff --git a/odb/relational/processor.cxx b/odb/relational/processor.cxx index 48ddba4..cf0a776 100644 --- a/odb/relational/processor.cxx +++ b/odb/relational/processor.cxx @@ -421,7 +421,7 @@ namespace relational process_container_value (*it, ih, m, "index", false); if (kt != 0) - process_container_value (*kt, kh, m, "key", false); + process_container_value (*kt, kh, m, "key", true); } }; -- cgit v1.1