aboutsummaryrefslogtreecommitdiff
path: root/xsde/cxx/serializer
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-25 14:54:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-25 14:54:24 +0200
commitc5e3c6ee3e291a5dfc6670160677f4962d526dc4 (patch)
tree2b3440a35d7174719d096ddb868ec4529a94af43 /xsde/cxx/serializer
parentb7c3f32ea4e68a0865761f65d68a011ab9606363 (diff)
Add the {parser,serializer}_maps functions to set polymorphic maps
Use that in the generated aggregate classes in C++/Hybrid instead of the individual setters since their names are unknown for included and imported schemas.
Diffstat (limited to 'xsde/cxx/serializer')
-rw-r--r--xsde/cxx/serializer/elements.hxx109
-rw-r--r--xsde/cxx/serializer/serializer-header.cxx29
-rw-r--r--xsde/cxx/serializer/serializer-inline.cxx82
3 files changed, 199 insertions, 21 deletions
diff --git a/xsde/cxx/serializer/elements.hxx b/xsde/cxx/serializer/elements.hxx
index 7d2bf80..c429a64 100644
--- a/xsde/cxx/serializer/elements.hxx
+++ b/xsde/cxx/serializer/elements.hxx
@@ -336,20 +336,44 @@ namespace CXX
//
struct ParticleParamDecl: Traversal::Element, Context
{
- ParticleParamDecl (Context& c, Boolean& first, Boolean name_arg)
- : Context (c), first_ (first), name_arg_ (name_arg)
+ ParticleParamDecl (Context& c,
+ Boolean& first,
+ Boolean name_arg,
+ Boolean poly)
+ : Context (c),
+ first_ (first),
+ name_arg_ (name_arg),
+ poly_ (poly),
+ result_ (0)
+ {
+ }
+
+ ParticleParamDecl (Context& c, Boolean* result, Boolean poly)
+ : Context (c), first_ (name_arg_), poly_ (poly), result_ (result)
{
}
virtual Void
traverse (SemanticGraph::Element& e)
{
+ if (poly_ && anonymous (e.type ()))
+ return;
+
+ if (result_ != 0)
+ {
+ *result_ = true;
+ return;
+ }
+
if (!first_)
os << "," << endl;
else
first_ = false;
- os << fq_name (e.type ()) << "&";
+ if (poly_)
+ os << serializer_map << "&";
+ else
+ os << fq_name (e.type ()) << "&";
if (name_arg_)
os << " " << ename (e);
@@ -360,18 +384,34 @@ namespace CXX
private:
Boolean& first_;
Boolean name_arg_;
+ Boolean poly_;
+ Boolean* result_;
};
struct AttributeParamDecl: Traversal::Attribute, Context
{
AttributeParamDecl (Context& c, Boolean& first, Boolean name_arg)
- : Context (c), first_ (first), name_arg_ (name_arg)
+ : Context (c),
+ first_ (first),
+ name_arg_ (name_arg),
+ result_ (0)
+ {
+ }
+
+ AttributeParamDecl (Context& c, Boolean* result)
+ : Context (c), first_ (name_arg_), result_ (result)
{
}
virtual Void
traverse (Type& a)
{
+ if (result_ != 0)
+ {
+ *result_ = true;
+ return;
+ }
+
if (!first_)
os << "," << endl;
else
@@ -388,18 +428,38 @@ namespace CXX
private:
Boolean& first_;
Boolean name_arg_;
+ Boolean* result_;
};
struct SerializerParamDecl : Traversal::Complex,
- Traversal::List,
- Context
+ Traversal::List,
+ Context
{
- SerializerParamDecl (Context& c, Boolean name_arg)
+ SerializerParamDecl (Context& c, Boolean name_arg, Boolean poly)
: Context (c),
- particle_ (c, first_, name_arg),
+ particle_ (c, first_, name_arg, poly),
attribute_ (c, first_, name_arg),
first_ (true),
- name_arg_ (name_arg)
+ name_arg_ (name_arg),
+ poly_ (poly),
+ result_ (0)
+ {
+ inherits_ >> *this;
+
+ contains_compositor_ >> compositor_ >> contains_particle_;
+ contains_particle_ >> particle_;
+ contains_particle_ >> compositor_;
+
+ if (!poly_)
+ names_ >> attribute_;
+ }
+
+ SerializerParamDecl (Context& c, Boolean* result, Boolean poly)
+ : Context (c),
+ particle_ (c, result, poly),
+ attribute_ (c, result),
+ poly_ (poly),
+ result_ (result)
{
inherits_ >> *this;
@@ -407,7 +467,8 @@ namespace CXX
contains_particle_ >> particle_;
contains_particle_ >> compositor_;
- names_ >> attribute_;
+ if (!poly_)
+ names_ >> attribute_;
}
virtual Void
@@ -425,6 +486,15 @@ namespace CXX
virtual Void
traverse (SemanticGraph::List& l)
{
+ if (poly_)
+ return;
+
+ if (result_ != 0)
+ {
+ *result_ = true;
+ return;
+ }
+
if (!first_)
os << "," << endl;
else
@@ -451,6 +521,25 @@ namespace CXX
Boolean first_;
Boolean name_arg_;
+ Boolean poly_;
+ Boolean* result_;
+ };
+
+ struct SerializerParamTest
+ {
+ SerializerParamTest (Context& c, Boolean& result, Boolean poly)
+ : impl_ (c, &result, poly)
+ {
+ }
+
+ Void
+ traverse (SemanticGraph::Complex& c)
+ {
+ impl_.traverse (c);
+ }
+
+ private:
+ SerializerParamDecl impl_;
};
//
diff --git a/xsde/cxx/serializer/serializer-header.cxx b/xsde/cxx/serializer/serializer-header.cxx
index a849946..9321482 100644
--- a/xsde/cxx/serializer/serializer-header.cxx
+++ b/xsde/cxx/serializer/serializer-header.cxx
@@ -1147,17 +1147,44 @@ namespace CXX
os << "// Serializer construction API." << endl
<< "//" << endl;
+ // serializers ()
+ //
os << "void" << endl
<< "serializers (";
{
- SerializerParamDecl decl (*this, false);
+ SerializerParamDecl decl (*this, false, false);
decl.traverse (c);
}
os << ");"
<< endl;
+ // serializer_maps ()
+ //
+ if (poly_code && he)
+ {
+ Boolean r (false);
+ SerializerParamTest test (*this, r, true);
+ test.traverse (c);
+
+ // Have potentially polymorphic elements.
+ //
+ if (r)
+ {
+ os << "void" << endl
+ << "serializer_maps (";
+
+ {
+ SerializerParamDecl decl (*this, false, true);
+ decl.traverse (c);
+ }
+
+ os << ");"
+ << endl;
+ }
+ }
+
if (ha)
{
os << "// Individual attribute serializers." << endl
diff --git a/xsde/cxx/serializer/serializer-inline.cxx b/xsde/cxx/serializer/serializer-inline.cxx
index 621f8b2..bfc16e2 100644
--- a/xsde/cxx/serializer/serializer-inline.cxx
+++ b/xsde/cxx/serializer/serializer-inline.cxx
@@ -365,16 +365,22 @@ namespace CXX
//
struct ParticleMemberSet: Traversal::Element, Context
{
- ParticleMemberSet (Context& c)
- : Context (c)
+ ParticleMemberSet (Context& c, Boolean poly)
+ : Context (c), poly_ (poly)
{
}
virtual Void
traverse (SemanticGraph::Element& e)
{
- os << "this->" << emember (e) << " = &" << ename (e) << ";";
+ if (poly_)
+ os << "this->" << emember_map (e) << " = &" << ename (e) << ";";
+ else
+ os << "this->" << emember (e) << " = &" << ename (e) << ";";
}
+
+ private:
+ Boolean poly_;
};
struct AttributeMemberSet: Traversal::Attribute, Context
@@ -395,8 +401,8 @@ namespace CXX
Traversal::List,
Context
{
- BaseMemberSet (Context& c)
- : Context (c)
+ BaseMemberSet (Context& c, Boolean poly)
+ : Context (c), poly_ (poly)
{
inherits_ >> *this;
}
@@ -416,6 +422,9 @@ namespace CXX
virtual Void
traverse (SemanticGraph::List& l)
{
+ if (poly_)
+ return;
+
String const& name (ename (l));
String item (unclash (name, "item"));
@@ -424,6 +433,7 @@ namespace CXX
private:
Traversal::Inherits inherits_;
+ Boolean poly_;
};
//
@@ -493,9 +503,11 @@ namespace CXX
: Context (c),
particle_accessor_ (c),
attribute_accessor_ (c),
- base_set_ (c),
- particle_set_ (c),
- attribute_set_ (c)
+ base_set_ (c, false),
+ particle_set_ (c, false),
+ attribute_set_ (c),
+ base_set_poly_ (c, true),
+ particle_set_poly_ (c, true)
{
// Accessor.
//
@@ -518,6 +530,16 @@ namespace CXX
contains_particle_set_ >> particle_set_;
names_attribute_set_ >> attribute_set_;
+
+ // Member set polymorphic.
+ //
+ inherits_base_set_poly_ >> base_set_poly_;
+ base_set_poly_ >> contains_compositor_set_poly_;
+
+ contains_compositor_set_poly_ >> compositor_set_poly_;
+ compositor_set_poly_ >> contains_particle_set_poly_;
+ contains_particle_set_poly_ >> compositor_set_poly_;
+ contains_particle_set_poly_ >> particle_set_poly_;
}
virtual Void
@@ -550,13 +572,12 @@ namespace CXX
// serializer ()
//
-
os << inl
<< "void " << name << "::" << endl
<< "serializers (";
{
- SerializerParamDecl decl (*this, true);
+ SerializerParamDecl decl (*this, true, false);
decl.traverse (c);
}
@@ -572,6 +593,37 @@ namespace CXX
contains_compositor (c, contains_compositor_set_);
os << "}";
+
+ // serializer_maps ()
+ //
+ if (poly_code && he)
+ {
+ Boolean r (false);
+ SerializerParamTest test (*this, r, true);
+ test.traverse (c);
+
+ // Have potentially polymorphic elements.
+ //
+ if (r)
+ {
+ os << inl
+ << "void " << name << "::" << endl
+ << "serializer_maps (";
+
+ {
+ SerializerParamDecl decl (*this, true, true);
+ decl.traverse (c);
+ }
+
+ os << ")"
+ << "{";
+
+ inherits (c, inherits_base_set_poly_);
+ contains_compositor (c, contains_compositor_set_poly_);
+
+ os << "}";
+ }
+ }
}
String fq_base;
@@ -726,6 +778,16 @@ namespace CXX
AttributeMemberSet attribute_set_;
Traversal::Names names_attribute_set_;
+
+ //
+ //
+ BaseMemberSet base_set_poly_;
+ Traversal::Inherits inherits_base_set_poly_;
+
+ Traversal::Compositor compositor_set_poly_;
+ ParticleMemberSet particle_set_poly_;
+ Traversal::ContainsCompositor contains_compositor_set_poly_;
+ Traversal::ContainsParticle contains_particle_set_poly_;
};
}