diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-14 16:13:36 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-10-14 16:13:36 +0200 |
commit | 36ba4a4f1af667682416f48c1698b1167e66e2b1 (patch) | |
tree | 806e78260bc24451be667cf5e217769ebb2f6246 | |
parent | 644c7b372ab61ad600817a4945a96f2bfb0f76e2 (diff) |
Omit _present(bool) for variable-length members
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | documentation/cxx/hybrid/guide/index.xhtml | 34 | ||||
-rw-r--r-- | examples/cxx/hybrid/compositors/compositors.xsd | 4 | ||||
-rw-r--r-- | examples/cxx/hybrid/compositors/driver.cxx | 2 | ||||
-rw-r--r-- | tests/cxx/parser/validation/built-in/any-type/driver.cxx | 4 | ||||
-rw-r--r-- | xsde/cxx/hybrid/extraction-source.cxx | 80 | ||||
-rw-r--r-- | xsde/cxx/hybrid/tree-header.cxx | 55 | ||||
-rw-r--r-- | xsde/cxx/hybrid/tree-inline.cxx | 220 |
8 files changed, 180 insertions, 225 deletions
@@ -55,6 +55,12 @@ Version 3.2.0 information, see Section 5.14, "Mapping for anyType" in the Embedded C++/Hybrid Mapping Getting Started Guide. + * The object model interface for optional members of variable-length + types now omits the _present modifier function. This is done to help + detect programming errors that result from a type becoming variable- + length due to schema changes. To reset such optional members you can + call the member modifier function with NULL as its argument. + * New configuration parameter, XSDE_STL_ITERATOR, makes iterators provided by the mapping conform to the STL requirements. This feature requires working <iterator> header and allows you to use the standard diff --git a/documentation/cxx/hybrid/guide/index.xhtml b/documentation/cxx/hybrid/guide/index.xhtml index ebb67fb..601574d 100644 --- a/documentation/cxx/hybrid/guide/index.xhtml +++ b/documentation/cxx/hybrid/guide/index.xhtml @@ -2267,8 +2267,8 @@ class person </pre> <p>Compared to the <em>one</em> cardinality class, <em>optional</em> adds - two extra functions for querying and modifying the element's presence - status. The following example shows how we can use these functions:</p> + functions for querying and modifying the member's presence status. + The following example shows how we can use these functions:</p> <pre class="c++"> person& p = ... @@ -2280,6 +2280,33 @@ if (p.middle_name_present ()) } </pre> + <p>If an optional member is of a variable-length type, then the second + <code>_present()</code> function is omitted. This is done to help + detect programming errors that result from a type becoming + variable-length due to schema changes. In this situation, before + the type becomes variable-length, calling the presence function + with <code>true</code> as its argument and then accessing the + member is valid. Once the type becomes variable-length, the + same sequence of calls would lead to a runtime error. By + omitting the second <code>_present()</code> function for + variable-length types, this kind of errors can be detected + at compile time. To reset an optional member of a variable-length + type you can call the member modifier function with <code>NULL</code> + as its argument. For example, if the <code>middle_name</code> + member was of a variable-length type, then the above code fragment + would look like this:</p> + + <pre class="c++"> +person& p = ... + +if (p.middle_name_present ()) +{ + cout << *p.middle_name () << endl; + p.middle_name (0); // Reset to the "not present" state. +} + </pre> + + <p>There are two cases in the <em>optional</em> cardinality class that are handled differently. These are optional attributes with default and fixed values. When an optional attribute declaration in XML Schema @@ -3021,9 +3048,6 @@ public: bool sequence_present () const; - void - sequence_present (bool); - const sequence_type& sequence () const; diff --git a/examples/cxx/hybrid/compositors/compositors.xsd b/examples/cxx/hybrid/compositors/compositors.xsd index 85f0db7..6a4f98e 100644 --- a/examples/cxx/hybrid/compositors/compositors.xsd +++ b/examples/cxx/hybrid/compositors/compositors.xsd @@ -13,8 +13,8 @@ copyright : not copyrighted - public domain <xsd:complexType name="simple_choice"> <xsd:choice> <xsd:element name="a" type="xsd:int"/> - <xsd:element name="b" type="xsd:string" minOccurs="0"/> - <xsd:element name="c" type="xsd:boolean" maxOccurs="unbounded"/> + <xsd:element name="b" type="xsd:int" minOccurs="0"/> + <xsd:element name="c" type="xsd:int" maxOccurs="unbounded"/> </xsd:choice> </xsd:complexType> diff --git a/examples/cxx/hybrid/compositors/driver.cxx b/examples/cxx/hybrid/compositors/driver.cxx index 5d7dd01..63205c9 100644 --- a/examples/cxx/hybrid/compositors/driver.cxx +++ b/examples/cxx/hybrid/compositors/driver.cxx @@ -40,7 +40,7 @@ main (int, char*[]) for (simple_choice::c_iterator i = s.begin (); i != s.end(); ++i) { - *i = !*i; + *i += 10; } break; diff --git a/tests/cxx/parser/validation/built-in/any-type/driver.cxx b/tests/cxx/parser/validation/built-in/any-type/driver.cxx index 3ffffa6..bfdd71d 100644 --- a/tests/cxx/parser/validation/built-in/any-type/driver.cxx +++ b/tests/cxx/parser/validation/built-in/any-type/driver.cxx @@ -117,8 +117,8 @@ struct any_simple_extension_pimpl: any_simple_extension_pskel virtual void post_any_simple_extension () { - char& v = post_any_simple_type (); - cout << "'" << b << "'" << endl; + char* v = post_any_simple_type (); + cout << "'" << v << "'" << endl; delete[] v; } #endif diff --git a/xsde/cxx/hybrid/extraction-source.cxx b/xsde/cxx/hybrid/extraction-source.cxx index 1e2a602..0bcc166 100644 --- a/xsde/cxx/hybrid/extraction-source.cxx +++ b/xsde/cxx/hybrid/extraction-source.cxx @@ -277,14 +277,23 @@ namespace CXX if (!a.default_p ()) { os << "}" - << "else" << endl - << "x." << epresent (a) << " (false);"; + << "else" << endl; + + if (fl) + os << "x." << epresent (a) << " (false);"; + else + os << "x." << name << " (0);"; + } else { os << "}" - << "else" << endl - << "x." << edefault (a) << " (true);"; + << "else" << endl; + + if (fl) + os << "x." << edefault (a) << " (true);"; + else + os << "x." << name << " (0);"; } } @@ -403,9 +412,15 @@ namespace CXX } if (e.min () == 0) + { os << "}" - << "else" << endl - << "x." << epresent (e) << " (false);"; + << "else" << endl; + + if (fl) + os << "x." << epresent (e) << " (false);"; + else + os << "x." << name << " (0);"; + } os << "}"; } @@ -486,9 +501,14 @@ namespace CXX << "return false;"; os << "}" - << "else" << endl - << "x." << present << " (false);" - << "}"; + << "else" << endl; + + if (fl) + os << "x." << present << " (false);"; + else + os << "x." << name << " (0);"; + + os << "}"; } else All::contains (a); @@ -608,9 +628,15 @@ namespace CXX } if (e.min () == 0) + { os << "}" - << "else" << endl - << "x." << epresent (e) << " (false);"; + << "else" << endl; + + if (fl) + os << "x." << epresent (e) << " (false);"; + else + os << "x." << name << " (0);"; + } } os << "break;" @@ -697,9 +723,15 @@ namespace CXX << "return false;"; if (c.min () == 0) + { os << "}" - << "else" << endl - << "x." << epresent (c) << " (false);"; + << "else" << endl; + + if (fl) + os << "x." << epresent (c) << " (false);"; + else + os << "x." << name << " (0);"; + } } os << "break;" @@ -789,9 +821,14 @@ namespace CXX << "return false;"; os << "}" - << "else" << endl - << "x." << present << " (false);" - << "}"; + << "else" << endl; + + if (fl) + os << "x." << present << " (false);"; + else + os << "x." << name << " (0);"; + + os << "}"; } else { @@ -907,9 +944,14 @@ namespace CXX << "return false;"; os << "}" - << "else" << endl - << "x." << present << " (false);" - << "}"; + << "else" << endl; + + if (fl) + os << "x." << present << " (false);"; + else + os << "x." << name << " (0);"; + + os << "}"; } else Sequence::contains (s); diff --git a/xsde/cxx/hybrid/tree-header.cxx b/xsde/cxx/hybrid/tree-header.cxx index 90bdd24..20f0328 100644 --- a/xsde/cxx/hybrid/tree-header.cxx +++ b/xsde/cxx/hybrid/tree-header.cxx @@ -1358,6 +1358,7 @@ namespace CXX String const& name (ename (a)); SemanticGraph::Type& t (a.type ()); + Boolean fl (fixed_length (t)); if (a.optional_p () && !fix) @@ -1368,9 +1369,10 @@ namespace CXX << name << " () const;" << endl; - os << "void" << endl - << name << " (bool);" - << endl; + if (fl) + os << "void" << endl + << name << " (bool);" + << endl; } // const type& @@ -1406,7 +1408,7 @@ namespace CXX // type* // detach () // - if (detach && !fixed_length (t)) + if (detach && !fl) { arg_.dispatch (t); os << endl @@ -1453,6 +1455,7 @@ namespace CXX String const& name (ename (e)); SemanticGraph::Type& t (e.type ()); + Boolean fl (fixed_length (t)); if (e.max () != 1) { @@ -1496,9 +1499,10 @@ namespace CXX << present << " () const;" << endl; - os << "void" << endl - << present << " (bool);" - << endl; + if (fl) + os << "void" << endl + << present << " (bool);" + << endl; } // const type& @@ -1530,7 +1534,7 @@ namespace CXX // type* // detach () // - if (detach && !fixed_length (t)) + if (detach && !fl) { arg_.dispatch (t); os << endl @@ -1667,9 +1671,10 @@ namespace CXX << present << " () const;" << endl; - os << "void" << endl - << present << " (bool);" - << endl; + if (fl) + os << "void" << endl + << present << " (bool);" + << endl; // const type& // name () const @@ -1967,9 +1972,10 @@ namespace CXX << present << " () const;" << endl; - os << "void" << endl - << present << " (bool);" - << endl; + if (fl) + os << "void" << endl + << present << " (bool);" + << endl; // const type& // name () const @@ -2203,9 +2209,10 @@ namespace CXX << present << " () const;" << endl; - os << "void" << endl - << present << " (bool);" - << endl; + if (fl) + os << "void" << endl + << present << " (bool);" + << endl; } // const type& @@ -2410,9 +2417,10 @@ namespace CXX << present << " () const;" << endl; - os << "void" << endl - << present << " (bool);" - << endl; + if (fl) + os << "void" << endl + << present << " (bool);" + << endl; // const type& // name () const @@ -2610,9 +2618,10 @@ namespace CXX << present << " () const;" << endl; - os << "void" << endl - << present << " (bool);" - << endl; + if (fl) + os << "void" << endl + << present << " (bool);" + << endl; } // const type& diff --git a/xsde/cxx/hybrid/tree-inline.cxx b/xsde/cxx/hybrid/tree-inline.cxx index fa55403..b28397c 100644 --- a/xsde/cxx/hybrid/tree-inline.cxx +++ b/xsde/cxx/hybrid/tree-inline.cxx @@ -414,44 +414,25 @@ namespace CXX // void // preset (bool); // - os << inl - << "void " << scope << "::" << endl - << name << " (bool x)" - << "{"; - - if (def) + if (fl) { - os << "if (x)"; + os << inl + << "void " << scope << "::" << endl + << name << " (bool x)" + << "{"; - if (fl) + if (def) { - os << endl - << "this->" << member << " = " << edefault_value (a) << - " ();"; + os << "if (x)" << endl + << "this->" << member << " = " << edefault_value (a) << " ();"; } else { - os << "{"; - delete_.dispatch (t, L"this->" + member); - os << "this->" << member << " = 0;" - << "}"; - } - } - else - { - if (fl) os << "this->" << epresent_member (a) << " = x;"; - else - { - os << "if (!x)" - << "{"; - delete_.dispatch (t, L"this->" + member); - os << "this->" << member << " = 0;" - << "}"; } - } - os << "}"; + os << "}"; + } } // const type& @@ -644,23 +625,13 @@ namespace CXX // void // preset (bool); // - os << inl - << "void " << scope << "::" << endl - << present << " (bool x)" - << "{"; - if (fl) - os << "this->" << epresent_member (e) << " = x;"; - else - { - os << "if (!x)" - << "{"; - delete_.dispatch (t, L"this->" + member); - os << "this->" << member << " = 0;" + os << inl + << "void " << scope << "::" << endl + << present << " (bool x)" + << "{" + << "this->" << epresent_member (e) << " = x;" << "}"; - } - - os << "}"; } // const type& @@ -828,31 +799,20 @@ namespace CXX // void // preset (bool); // - os << inl - << "void " << scope << "::" << endl - << present << " (bool x)" - << "{" - << "if (this->" << arm_member << " != " << tag << ")" << endl - << "this->" << arm << " (" << tag << ");"; - if (fl) { - os << endl - << "this->" << umember << "." << member << - ".data_[sizeof ("; + os << inl + << "void " << scope << "::" << endl + << present << " (bool x)" + << "{" + << "if (this->" << arm_member << " != " << tag << ")" << endl + << "this->" << arm << " (" << tag << ");" + << endl + << "this->" << umember << "." << member << ".data_[sizeof ("; var_.dispatch (t); - os << ")] = x;"; - } - else - { - os << "else if (!x)" - << "{"; - delete_.dispatch (t, L"this->" + umember + L"." + member); - os << "this->" << umember << "." << member << " = 0;" + os << ")] = x;" << "}"; } - - os << "}"; } // const type& @@ -1012,34 +972,13 @@ namespace CXX // void // present (bool); // - os << inl - << "void " << scope << "::" << endl - << present << " (bool x)" - << "{"; - if (fl) - os << "this->" << epresent_member (a) << " = x;"; - else - { - String p (L"this->" + member); - - os << "if (!x)" - << "{"; - - if (!custom_alloc) - os << "delete " << p << ";"; - else - os << "if (" << p << ")" - << "{" - << p << "->~" << type << " ();" - << "::xsde::cxx::free (" << p << ");" - << "}"; - - os << p << " = 0;" + os << inl + << "void " << scope << "::" << endl + << present << " (bool x)" + << "{" + << "this->" << epresent_member (a) << " = x;" << "}"; - } - - os << "}"; // const type& @@ -1216,34 +1155,13 @@ namespace CXX // void // preset (bool); // - os << inl - << "void " << scope << "::" << endl - << present << " (bool x)" - << "{"; - if (fl) - os << "this->" << epresent_member (c) << " = x;"; - else - { - String p (L"this->" + member); - - os << "if (!x)" - << "{"; - - if (!custom_alloc) - os << "delete " << p << ";"; - else - os << "if (" << p << ")" - << "{" - << p << "->~" << type << " ();" - << "::xsde::cxx::free (" << p << ");" - << "}"; - - os << p << " = 0;" + os << inl + << "void " << scope << "::" << endl + << present << " (bool x)" + << "{" + << "this->" << epresent_member (c) << " = x;" << "}"; - } - - os << "}"; // const type& @@ -1406,34 +1324,13 @@ namespace CXX // void // preset (bool); // - os << inl - << "void " << scope << "::" << endl - << present << " (bool x)" - << "{"; - if (fl) - os << "this->" << epresent_member (s) << " = x;"; - else - { - String p (L"this->" + member); - - os << "if (!x)" - << "{"; - - if (!custom_alloc) - os << "delete " << p << ";"; - else - os << "if (" << p << ")" - << "{" - << p << "->~" << type << " ();" - << "::xsde::cxx::free (" << p << ");" - << "}"; - - os << p << " = 0;" + os << inl + << "void " << scope << "::" << endl + << present << " (bool x)" + << "{" + << "this->" << epresent_member (s) << " = x;" << "}"; - } - - os << "}"; // const type& @@ -1610,40 +1507,17 @@ namespace CXX // void // preset (bool); // - os << inl - << "void " << scope << "::" << endl - << present << " (bool x)" - << "{" - << "if (this->" << arm_member << " != " << tag << ")" << endl - << "this->" << arm << " (" << tag << ");"; - if (fl) - { - os << endl + os << inl + << "void " << scope << "::" << endl + << present << " (bool x)" + << "{" + << "if (this->" << arm_member << " != " << tag << ")" << endl + << "this->" << arm << " (" << tag << ");" + << endl << "this->" << umember << "." << member << - ".data_[sizeof (" << type << ")] = x;"; - } - else - { - String p (L"this->" + umember + L"." + member); - - os << "else if (!x)" - << "{"; - - if (!custom_alloc) - os << "delete " << p << ";"; - else - os << "if (" << p << ")" - << "{" - << p << "->~" << type << " ();" - << "::xsde::cxx::free (" << p << ");" - << "}"; - - os << p << " = 0;" + ".data_[sizeof (" << type << ")] = x;" << "}"; - } - - os << "}"; } // const type& |