From c04f7d6ed04d62efafa79a87bcde6c5f62e95327 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 20 Jun 2012 11:54:24 +0200 Subject: Completion of the CLI port --- xsd/cxx/elements.cxx | 82 +++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) (limited to 'xsd/cxx/elements.cxx') diff --git a/xsd/cxx/elements.cxx b/xsd/cxx/elements.cxx index e83f661..927e74d 100644 --- a/xsd/cxx/elements.cxx +++ b/xsd/cxx/elements.cxx @@ -5,6 +5,7 @@ #include +#include #include // std::toupper #include #include @@ -14,6 +15,8 @@ using std::wcerr; using std::endl; +typedef std::vector NarrowStrings; + namespace CXX { // @@ -112,55 +115,45 @@ namespace CXX Context (std::wostream& o, SemanticGraph::Schema& root, SemanticGraph::Path const& path, - StringLiteralMap const* string_literal_map_, - NarrowString const& char_type__, - NarrowString const& char_encoding__, - Boolean include_with_brackets__, - NarrowString const& include_prefix__, - NarrowString const& esymbol, - Containers::Vector const& nsm, - Containers::Vector const& nsr, - Boolean trace_namespace_regex_, - Containers::Vector const& ir, - Boolean trace_include_regex_, - Boolean inline_, - Containers::Vector const& reserved_name) + options_type const& ops, + StringLiteralMap const* string_literal_map_) : os (o), schema_root (root), schema_path (schema_path_), + options (ops), char_type (char_type_), char_encoding (char_encoding_), L (L_), string_type (string_type_), string_literal_map (string_literal_map_), - include_with_brackets (include_with_brackets_), - include_prefix (include_prefix_), type_exp (type_exp_), inst_exp (inst_exp_), inl (inl_), ns_mapping_cache (ns_mapping_cache_), schema_path_ (path), xs_ns_ (0), - char_type_ (char_type__), - char_encoding_ (char_encoding__), + char_type_ (ops.char_type ()), + char_encoding_ (ops.char_encoding ()), L_ (char_type == L"wchar_t" ? L"L" : L""), - include_with_brackets_ (include_with_brackets__), - include_prefix_ (include_prefix__), - type_exp_ (esymbol ? esymbol + " " : esymbol), - inst_exp_ (esymbol ? esymbol + "\n" : esymbol), - inl_ (inline_ ? L"inline\n" : L""), + inl_ (ops.generate_inline () ? L"inline\n" : L""), cxx_id_expr_ (L"^(::)?([a-zA-Z_]\\w*)(::[a-zA-Z_]\\w*)*$"), cxx_id_expr (cxx_id_expr_), - trace_namespace_regex (trace_namespace_regex_), urn_mapping_ (L"#^urn.*:([a-zA-Z_].*)$#$1#"), urn_mapping (urn_mapping_), nsr_mapping (nsr_mapping_), nsm_mapping (nsm_mapping_), include_mapping (include_mapping_), - trace_include_regex (trace_include_regex_), reserved_name_map (reserved_name_map_), keyword_set (keyword_set_) { + // Export symbol. + // + { + String es (ops.export_symbol ()); + type_exp_ = es ? es + L" " : es; + inst_exp_ = es ? es + L"\n" : es; + } + // Resolve and cache XML Schema namespace. // { @@ -213,16 +206,16 @@ namespace CXX // Custom regex mapping. // - for (Containers::Vector::ConstIterator - i (nsr.begin ()), e (nsr.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (ops.namespace_regex ().begin ()), + e (ops.namespace_regex ().end ()); i != e; ++i) { nsr_mapping_.push_back (Regex (String (*i))); } // Custom direct mapping. // - for (Containers::Vector::ConstIterator - i (nsm.begin ()), e (nsm.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (ops.namespace_map ().begin ()), + e (ops.namespace_regex ().end ()); i != e; ++i) { String s (*i); @@ -246,16 +239,16 @@ namespace CXX // Include path regex // - for (Containers::Vector::ConstIterator - i (ir.begin ()), e (ir.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (ops.include_regex ().begin ()), + e (ops.include_regex ().end ()); i != e; ++i) { include_mapping_.push_back (Regex (String (*i))); } // Reserved names. // - for (Containers::Vector::ConstIterator - i (reserved_name.begin ()), e (reserved_name.end ()); i != e; ++i) + for (NarrowStrings::const_iterator i (ops.reserved_name ().begin ()), + e (ops.reserved_name ().end ()); i != e; ++i) { String s (*i); @@ -340,7 +333,9 @@ namespace CXX } else { - if (trace_namespace_regex) + bool trace (options.namespace_regex_trace ()); + + if (trace) wcerr << "namespace: '" << pair << "'" << endl; Boolean found (false); @@ -349,7 +344,7 @@ namespace CXX for (RegexMapping::ConstReverseIterator e (nsr_mapping.rbegin ()); e != nsr_mapping.rend (); ++e) { - if (trace_namespace_regex) + if (trace) wcerr << "try: '" << e->regex () << "' : "; if (e->match (pair)) @@ -361,11 +356,11 @@ namespace CXX // found = cxx_id_expr.match (tmp); - if (trace_namespace_regex) + if (trace) wcerr << "'" << tmp << "' : "; } - if (trace_namespace_regex) + if (trace) wcerr << (found ? '+' : '-') << endl; if (found) @@ -1195,9 +1190,10 @@ namespace CXX String Context:: process_include_path (String const& name) const { - String path (include_prefix + name); + String path (String (options.include_prefix ()) + name); + bool trace (options.include_regex_trace ()); - if (trace_include_regex) + if (trace) wcerr << "include: '" << path << "'" << endl; String r; @@ -1206,7 +1202,7 @@ namespace CXX for (RegexMapping::ConstReverseIterator e (include_mapping.rbegin ()); e != include_mapping.rend (); ++e) { - if (trace_include_regex) + if (trace) wcerr << "try: '" << e->regex () << "' : "; if (e->match (path)) @@ -1214,11 +1210,11 @@ namespace CXX r = e->replace (path); found = true; - if (trace_include_regex) + if (trace) wcerr << "'" << r << "' : "; } - if (trace_include_regex) + if (trace) wcerr << (found ? '+' : '-') << endl; if (found) @@ -1230,8 +1226,8 @@ namespace CXX if (!r.empty () && r[0] != L'"' && r[0] != L'<') { - WideChar op (include_with_brackets ? L'<' : L'"'); - WideChar cl (include_with_brackets ? L'>' : L'"'); + WideChar op (options.include_with_brackets () ? L'<' : L'"'); + WideChar cl (options.include_with_brackets () ? L'>' : L'"'); r = op + r + cl; } -- cgit v1.1