aboutsummaryrefslogtreecommitdiff
path: root/xsd/cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-01-22 15:40:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-01-22 15:40:12 +0200
commitf60df03e3cedb86508645357e17003eb9281f31a (patch)
treed65c9cd62a6500b7d0f8303caf64797d08f508c0 /xsd/cxx
parent55ffb84acf75d3fa475dfe21d053e404eb753e5a (diff)
Add support for detaching subtrees in C++/Tree
New option: --generate-detach. New test: cxx/tree/detach.
Diffstat (limited to 'xsd/cxx')
-rw-r--r--xsd/cxx/tree/cli.hxx2
-rw-r--r--xsd/cxx/tree/elements.cxx3
-rw-r--r--xsd/cxx/tree/elements.hxx9
-rw-r--r--xsd/cxx/tree/generator.cxx5
-rw-r--r--xsd/cxx/tree/name-processor.cxx47
-rw-r--r--xsd/cxx/tree/tree-header.cxx52
-rw-r--r--xsd/cxx/tree/tree-inline.cxx24
7 files changed, 131 insertions, 11 deletions
diff --git a/xsd/cxx/tree/cli.hxx b/xsd/cxx/tree/cli.hxx
index c4294b6..171711d 100644
--- a/xsd/cxx/tree/cli.hxx
+++ b/xsd/cxx/tree/cli.hxx
@@ -36,6 +36,7 @@ namespace CXX
extern Key generate_comparison;
extern Key generate_default_ctor;
extern Key generate_from_base_ctor;
+ extern Key generate_detach;
extern Key generate_wildcard;
extern Key generate_insertion;
extern Key generate_extraction;
@@ -134,6 +135,7 @@ namespace CXX
generate_comparison, Boolean,
generate_default_ctor, Boolean,
generate_from_base_ctor, Boolean,
+ generate_detach, Boolean,
generate_wildcard, Boolean,
generate_insertion, Cult::Containers::Vector<NarrowString>,
generate_extraction, Cult::Containers::Vector<NarrowString>,
diff --git a/xsd/cxx/tree/elements.cxx b/xsd/cxx/tree/elements.cxx
index 0072e07..aafc442 100644
--- a/xsd/cxx/tree/elements.cxx
+++ b/xsd/cxx/tree/elements.cxx
@@ -86,6 +86,7 @@ namespace CXX
doxygen (doxygen_),
polymorphic (ops.value<CLI::generate_polymorphic> ()),
polymorphic_all (ops.value<CLI::polymorphic_type_all> ()),
+ detach (ops.value<CLI::generate_detach> ()),
fwd_expr (fe),
hxx_expr (he),
ixx_expr (ie),
@@ -324,6 +325,7 @@ namespace CXX
doxygen (c.doxygen),
polymorphic (c.polymorphic),
polymorphic_all (c.polymorphic_all),
+ detach (c.detach),
fwd_expr (c.fwd_expr),
hxx_expr (c.hxx_expr),
ixx_expr (c.ixx_expr),
@@ -364,6 +366,7 @@ namespace CXX
doxygen (c.doxygen),
polymorphic (c.polymorphic),
polymorphic_all (c.polymorphic_all),
+ detach (c.detach),
fwd_expr (c.fwd_expr),
hxx_expr (c.hxx_expr),
ixx_expr (c.ixx_expr),
diff --git a/xsd/cxx/tree/elements.hxx b/xsd/cxx/tree/elements.hxx
index 2160baf..d081139 100644
--- a/xsd/cxx/tree/elements.hxx
+++ b/xsd/cxx/tree/elements.hxx
@@ -213,6 +213,14 @@ namespace CXX
return a.context ().get<String> ("mname");
}
+ // Detach name.
+ //
+ static String const&
+ edname (SemanticGraph::Member const& m)
+ {
+ return m.context ().get<String> ("dname");
+ }
+
//
//
static String const&
@@ -413,6 +421,7 @@ namespace CXX
Boolean& doxygen;
Boolean polymorphic;
Boolean polymorphic_all;
+ Boolean detach;
Regex const* fwd_expr;
Regex const* hxx_expr;
diff --git a/xsd/cxx/tree/generator.cxx b/xsd/cxx/tree/generator.cxx
index a70214c..ae86767 100644
--- a/xsd/cxx/tree/generator.cxx
+++ b/xsd/cxx/tree/generator.cxx
@@ -129,6 +129,7 @@ namespace CXX
extern Key generate_comparison = "generate-comparison";
extern Key generate_default_ctor = "generate-default-ctor";
extern Key generate_from_base_ctor = "generate-from-base-ctor";
+ extern Key generate_detach = "generate-detach";
extern Key generate_wildcard = "generate-wildcard";
extern Key generate_insertion = "generate-insertion";
extern Key generate_extraction = "generate-extraction";
@@ -283,6 +284,10 @@ namespace CXX
<< " Generate from-base constructors."
<< endl;
+ e << "--generate-detach" << endl
+ << " Generate detach functions for required members."
+ << endl;
+
e << "--generate-wildcard" << endl
<< " Generate accessors/modifiers as well as parsing\n"
<< " and serialization code for XML Schema wildcards."
diff --git a/xsd/cxx/tree/name-processor.cxx b/xsd/cxx/tree/name-processor.cxx
index 1949c5d..a9427a6 100644
--- a/xsd/cxx/tree/name-processor.cxx
+++ b/xsd/cxx/tree/name-processor.cxx
@@ -31,9 +31,6 @@ namespace CXX
//
typedef Cult::Containers::Set<String> NameSet;
-
-
-
class Context: public Tree::Context
{
public:
@@ -57,6 +54,7 @@ namespace CXX
0),
global_type_names (global_type_names_),
global_element_names (global_element_names_),
+ detach (options.value<CLI::generate_detach> ()),
type_regex (type_regex_),
accessor_regex (accessor_regex_),
one_accessor_regex (one_accessor_regex_),
@@ -189,6 +187,7 @@ namespace CXX
//
modifier_regex.push_back ("/([^,]+),([^,]+)/set\\u$1\\u$2/");
modifier_regex.push_back ("/([^,]+)/set\\u$1/");
+ modifier_regex.push_back ("/detach,([^,]+)/detach\\u$1/");
}
compile_regex (options.value<CLI::modifier_regex> (),
@@ -271,6 +270,7 @@ namespace CXX
: Tree::Context (c),
global_type_names (c.global_type_names),
global_element_names (c.global_element_names),
+ detach (c.detach),
type_regex (c.type_regex),
accessor_regex (c.accessor_regex),
one_accessor_regex (c.one_accessor_regex),
@@ -537,6 +537,8 @@ namespace CXX
Cult::Containers::Map<String, NameSet>& global_type_names;
Cult::Containers::Map<String, NameSet>& global_element_names;
+ Boolean detach;
+
RegexVector& type_regex;
RegexVector& accessor_regex;
RegexVector& one_accessor_regex;
@@ -670,8 +672,8 @@ namespace CXX
Boolean def_attr (m.default_ () &&
m.is_a<SemanticGraph::Attribute> ());
- // Accessors/modifiers. Note that we postpone inserting the
- // names into the name_set to avoid over-escaping.
+ // Accessors/modifiers. Note that we postpone inserting
+ // the names into the name_set to avoid over-escaping.
//
String an, mn;
@@ -741,6 +743,19 @@ namespace CXX
if (mn != b && mn != an)
name_set_.insert (mn);
+ // Detach.
+ //
+ if (detach && max == 1 && (min == 1 || def_attr))
+ {
+ String dn (find_name (
+ escape (process_regex (L"detach," + s,
+ one_modifier_regex,
+ modifier_regex,
+ L"one modifier")),
+ name_set_));
+
+ m.context ().set ("dname", dn);
+ }
// Types.
//
@@ -1281,21 +1296,21 @@ namespace CXX
escape (process_regex (L"value,traits", type_regex, L"type")),
set));
- String an = Context::find_name (
+ String an (Context::find_name (
escape (process_regex ("value",
one_accessor_regex,
accessor_regex,
L"one accessor")),
set,
- false);
+ false));
- String mn = Context::find_name (
+ String mn (Context::find_name (
escape (process_regex ("value",
one_modifier_regex,
modifier_regex,
L"one modifier")),
set,
- false);
+ false));
ec.set ("aname", an);
ec.set ("mname", mn);
@@ -1305,6 +1320,20 @@ namespace CXX
if (an != mn)
set.insert (mn);
+ // Detach.
+ //
+ if (detach)
+ {
+ String dn (Context::find_name (
+ escape (process_regex (L"detach,value",
+ one_modifier_regex,
+ modifier_regex,
+ L"one modifier")),
+ set));
+
+ ec.set ("dname", dn);
+ }
+
// Assign name() and namespace_() names.
//
ec.set (
diff --git a/xsd/cxx/tree/tree-header.cxx b/xsd/cxx/tree/tree-header.cxx
index 7e884c8..100a81c 100644
--- a/xsd/cxx/tree/tree-header.cxx
+++ b/xsd/cxx/tree/tree-header.cxx
@@ -1332,14 +1332,39 @@ namespace CXX
<< " * @param p A new value to use." << endl
<< " *" << endl
<< " * This function will try to use the passed value " <<
- "directly instead" << endl
- << " * of making a copy." << endl
+ "directly" << endl
+ << " * instead of making a copy." << endl
<< " */" << endl;
}
os << "void" << endl
<< mname << " (::std::auto_ptr< " << type << " > p);"
<< endl;
+
+ }
+
+ // auto_ptr<type>
+ // detach_name ();
+ //
+ if (detach && !fund)
+ {
+ if (doxygen)
+ {
+ os << "/**" << endl
+ << " * @brief Detach the " << kind << " value from " <<
+ "the object model." << endl
+ << " *" << endl
+ << " * @return A pointer to the " << kind << " value." << endl
+ << " *" << endl
+ << " * Note that this function leaves the required " <<
+ kind << " in " << endl
+ << " * the original object model uninitialized." << endl
+ << " */" << endl;
+ }
+
+ os << "::std::auto_ptr< " << type << " >" << endl
+ << edname (m) << " ();"
+ << endl;
}
}
}
@@ -3247,6 +3272,29 @@ namespace CXX
<< endl;
}
+ // auto_ptr<type>
+ // detach_name ();
+ //
+ if (detach && !fund)
+ {
+ if (doxygen)
+ {
+ os << "/**" << endl
+ << " * @brief Detach the element value from " <<
+ "the object." << endl
+ << " *" << endl
+ << " * @return A pointer to the element value." << endl
+ << " *" << endl
+ << " * Note that this function leaves the element " <<
+ "object uninitialized." << endl
+ << " */" << endl;
+ }
+
+ os << "::std::auto_ptr< " << type << " >" << endl
+ << edname (e) << " ();"
+ << endl;
+ }
+
if (doxygen)
{
os << "/**" << endl
diff --git a/xsd/cxx/tree/tree-inline.cxx b/xsd/cxx/tree/tree-inline.cxx
index a075d3f..6a983af 100644
--- a/xsd/cxx/tree/tree-inline.cxx
+++ b/xsd/cxx/tree/tree-inline.cxx
@@ -593,6 +593,18 @@ namespace CXX
<< "{"
<< "this->" << member << ".set (x);"
<< "}";
+
+ // auto_ptr<type>
+ // detach_name ();
+ //
+ if (detach && !fund)
+ os << inl
+ << "::std::auto_ptr< " << q_type << " > " <<
+ scope_ << "::" << endl
+ << edname (m) << " ()"
+ << "{"
+ << "return this->" << member << ".detach ();"
+ << "}";
}
}
@@ -979,6 +991,18 @@ namespace CXX
<< "return this->" << member << ".set (p);"
<< "}";
}
+
+ // auto_ptr<type>
+ // detach_name ();
+ //
+ if (detach && !fund)
+ os << inl
+ << "::std::auto_ptr< " << name << "::" << type << " > " <<
+ name << "::" << endl
+ << edname (e) << " ()"
+ << "{"
+ << "return this->" << member << ".detach ();"
+ << "}";
}
};
}