aboutsummaryrefslogtreecommitdiff
path: root/xsde/cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-03-28 18:58:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-03-28 18:58:03 +0200
commitf5b85ddc9a0e3ac4bb8a200d2ab1a05d5ca9f41b (patch)
tree8364cbe3ccd627fab9db7bd857d2e325d3dfed49 /xsde/cxx
parentb2ad4a54b5436ea57205595dbb6322952eb06318 (diff)
Validate facets in C++/Hybrid enum parser/serializer implementations
Diffstat (limited to 'xsde/cxx')
-rw-r--r--xsde/cxx/hybrid/parser-header.cxx29
-rw-r--r--xsde/cxx/hybrid/parser-source.cxx113
-rw-r--r--xsde/cxx/hybrid/serializer-source.cxx28
3 files changed, 114 insertions, 56 deletions
diff --git a/xsde/cxx/hybrid/parser-header.cxx b/xsde/cxx/hybrid/parser-header.cxx
index d3ba4b4..a09375a 100644
--- a/xsde/cxx/hybrid/parser-header.cxx
+++ b/xsde/cxx/hybrid/parser-header.cxx
@@ -113,17 +113,38 @@ namespace CXX
// pre
//
- os << "virtual void" << endl
- << "pre ();"
- << endl;
+ if (!fl || !base_enum)
+ os << "virtual void" << endl
+ << "pre ();"
+ << endl;
- // _characters
+ // _pre
//
if (!base_enum)
os << "virtual void" << endl
+ << "_pre ();"
+ << endl;
+
+ if (!base_enum)
+ {
+ // _characters
+ //
+ os << "virtual void" << endl
<< "_characters (const " << string_type << "&);"
<< endl;
+ // _post
+ //
+ if (!options.value<CLI::suppress_validation> () &&
+ !options.value<CLI::suppress_parser_val> ())
+ {
+ os << "virtual void" << endl
+ << "_post ();"
+ << endl;
+ }
+ }
+
+
// post
//
String const& ret (pret_type (e));
diff --git a/xsde/cxx/hybrid/parser-source.cxx b/xsde/cxx/hybrid/parser-source.cxx
index a1f28e2..7d8c434 100644
--- a/xsde/cxx/hybrid/parser-source.cxx
+++ b/xsde/cxx/hybrid/parser-source.cxx
@@ -245,27 +245,13 @@ namespace CXX
// pre
//
- os << "void " << name << "::" << endl
- << "pre ()"
- << "{";
-
- if (fl)
+ if (!fl || !base_enum)
{
- if (base_enum)
- {
- // Our base is also fixed-length so call its pre()
- //
- if (tiein)
- os << "this->base_impl_.";
- else
- os << epimpl (b) << "::"; //@@ fq-name.
-
- os << "pre ();";
- }
+ os << "void " << name << "::" << endl
+ << "pre ()"
+ << "{";
- // Clear the string buffer.
- //
- if (!base_enum)
+ if (fl)
{
if (stl)
os << "this->" << state << ".str_.clear ();";
@@ -281,25 +267,34 @@ namespace CXX
}
}
}
- }
- else
- {
- if (exceptions)
- os << "this->" << pre_impl_name (e) << " (new " << type << ");";
else
- os << type << "* x = new " << type << ";"
- << "if (x)" << endl
- << "this->" << pre_impl_name (e) << " (x);"
- << "else" << endl
- << "this->_sys_error (::xsde::cxx::sys_error::no_memory);";
- }
+ {
+ if (exceptions)
+ os << "this->" << pre_impl_name (e) << " (new " << type << ");";
+ else
+ os << type << "* x = new " << type << ";"
+ << "if (x)" << endl
+ << "this->" << pre_impl_name (e) << " (x);"
+ << "else" << endl
+ << "this->_sys_error (::xsde::cxx::sys_error::no_memory);";
+ }
- os << "}";
+ os << "}";
+ }
- // _characters
- //
if (!base_enum)
{
+ // _pre
+ //
+ os << "void " << name << "::" << endl
+ << "_pre ()"
+ << "{"
+ // Override it to cut off our base.
+ //
+ << "}";
+
+ // _characters
+ //
os << "void " << name << "::" << endl
<< "_characters (const " << string_type << "& s)"
<< "{";
@@ -319,6 +314,31 @@ namespace CXX
}
os << "}";
+
+ // _post
+ //
+ if (!options.value<CLI::suppress_validation> () &&
+ !options.value<CLI::suppress_parser_val> ())
+ {
+ // Do facet validation.
+ //
+ os << "void " << name << "::" << endl
+ << "_post ()"
+ << "{"
+ << "::xsde::cxx::parser::validating::string_common::" <<
+ "validate_facets (" << endl;
+
+ if (stl)
+ os << "this->" << state << ".str_.c_str ()," << endl
+ << "this->" << state << ".str_.size ()," << endl;
+ else
+ os << "this->" << state << ".str_.data ()," << endl
+ << "this->" << state << ".str_.size ()," << endl;
+
+ os << "this->_facets ()," << endl
+ << "this->_context ());"
+ << "}";
+ }
}
// post
@@ -371,10 +391,6 @@ namespace CXX
os << ";";
}
-
- //
- // @@ TODO: check enumerators (switch)
- //
}
else
{
@@ -388,19 +404,6 @@ namespace CXX
names<Enumeration> (e, names_, 0, 0, 0, &Enumeration::comma);
-
- /*
- // @@ Cannot do error checking in post.
-
- if (!options.value<CLI::suppress_validation> () &&
- !options.value<CLI::suppress_parser_val> ())
- {
- os << "else" << endl
- << "this->_schema_error (" <<
- "::xsde::cxx::schema_error::invalid_enumeration_value);";
- }
- */
-
os << endl;
if (fl)
@@ -1787,6 +1790,16 @@ namespace CXX
Void
generate_parser_source (Context& ctx)
{
+ if (ctx.enum_ &&
+ !ctx.options.value<CLI::suppress_validation> () &&
+ !ctx.options.value<CLI::suppress_parser_val> ())
+ {
+ // We need this functionality for enum mapping.
+ //
+ ctx.os << "#include <xsde/cxx/parser/validating/string-common.hxx>" << endl
+ << endl;
+ }
+
{
// Emit "weak" header includes for the object model types.
// Otherwise we cannot delete the objects of forward-declared
diff --git a/xsde/cxx/hybrid/serializer-source.cxx b/xsde/cxx/hybrid/serializer-source.cxx
index 87004fa..b15a3bf 100644
--- a/xsde/cxx/hybrid/serializer-source.cxx
+++ b/xsde/cxx/hybrid/serializer-source.cxx
@@ -204,8 +204,22 @@ namespace CXX
os << "void " << name << "::" << endl
<< "_serialize_content ()"
- << "{"
- << "this->_characters (this->" << state << "->" <<
+ << "{";
+
+ if (!options.value<CLI::suppress_validation> () &&
+ !options.value<CLI::suppress_serializer_val> ())
+ {
+ // Do facet validation.
+ //
+ os << "::xsde::cxx::serializer::validating::string_common::" <<
+ "validate_facets (" << endl
+ << "this->" << state << "->" << string << " ()," << endl
+ << "this->_facets ()," << endl
+ << "this->_context ());"
+ << endl;
+ }
+
+ os << "this->_characters (this->" << state << "->" <<
string << " ());"
<< "}";
}
@@ -1377,6 +1391,16 @@ namespace CXX
ctx.os << "#include <string.h>" << endl
<< endl;
+ if (ctx.enum_ &&
+ !ctx.options.value<CLI::suppress_validation> () &&
+ !ctx.options.value<CLI::suppress_serializer_val> ())
+ {
+ // We need this functionality for enum mapping.
+ //
+ ctx.os << "#include <xsde/cxx/serializer/validating/string-common.hxx>" << endl
+ << endl;
+ }
+
Traversal::Schema schema;
Traversal::Sources sources;