summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slicer/slicer/modelParts.h27
-rw-r--r--slicer/slicer/parser.cpp26
2 files changed, 34 insertions, 19 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index b845348..9c2bf45 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -160,40 +160,55 @@ namespace Slicer {
class HookBase : public IceUtil::Shared {
public:
virtual ModelPartPtr Get(T * t) const = 0;
+
+ virtual std::string PartName() const = 0;
};
typedef IceUtil::Handle<HookBase> HookPtr;
template <typename MT, MT T::*M, typename MP>
class Hook : public HookBase {
public:
+ Hook(const std::string & n) :
+ name(n)
+ {
+ }
+
ModelPartPtr Get(T * t) const override
{
return t ? new MP(t->*M) : NULL;
}
+
+ std::string PartName() const override
+ {
+ return name;
+ }
+
+ private:
+ const std::string name;
};
virtual void OnEachChild(const ChildHandler & ch)
{
- for (auto h = hooks.begin(); h != hooks.end(); h++) {
- auto modelPart = h->second->Get(GetModel());
- ch(h->first, modelPart && modelPart->HasValue() ? modelPart : ModelPartPtr());
+ BOOST_FOREACH (const auto & h, hooks) {
+ auto modelPart = h->Get(GetModel());
+ ch(h->PartName(), modelPart && modelPart->HasValue() ? modelPart : ModelPartPtr());
}
}
ModelPartPtr GetChild(const std::string & name) override
{
auto childitr = std::find_if(hooks.begin(), hooks.end(), [&name](const typename Hooks::value_type & h) {
- return h.first == name;
+ return h->PartName() == name;
});
if (childitr != hooks.end()) {
- return childitr->second->Get(GetModel());
+ return (*childitr)->Get(GetModel());
}
return NULL;
}
virtual T * GetModel() = 0;
- typedef std::vector<std::pair<const std::string, HookPtr> > Hooks;
+ typedef std::vector<HookPtr> Hooks;
private:
static Hooks hooks;
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp
index 680ca2f..c874f57 100644
--- a/slicer/slicer/parser.cpp
+++ b/slicer/slicer/parser.cpp
@@ -55,8 +55,7 @@ namespace Slicer {
modulePath().c_str(), c->name().c_str());
BOOST_FOREACH (const auto & dm, c->allDataMembers()) {
auto name = metaDataValue("slicer:name:", dm->getMetaData());
- fprintf(cpp, "\t\t{ \"%s\", ",
- name ? name->c_str() : dm->name().c_str());
+ fprintf(cpp, "\t\t{ ");
auto type = dm->type();
fprintf(cpp, "new ModelPartForClass< %s::%sPtr >::Hook< ",
modulePath().c_str(), c->name().c_str());
@@ -79,7 +78,8 @@ namespace Slicer {
if (dm->optional()) {
fprintf(cpp, " > ");
}
- fprintf(cpp, " > >() },\n");
+ fprintf(cpp, " > >(\"%s\") },\n",
+ name ? name->c_str() : dm->name().c_str());
}
fprintf(cpp, "\t};\n");
@@ -104,16 +104,16 @@ namespace Slicer {
modulePath().c_str(), c->name().c_str());
BOOST_FOREACH (const auto & dm, c->dataMembers()) {
auto name = metaDataValue("slicer:name:", dm->getMetaData());
- fprintf(cpp, "\t\t{ \"%s\", ",
- name ? name->c_str() : dm->name().c_str());
+ fprintf(cpp, "\t\t{ ");
auto type = dm->type();
fprintf(cpp, "new ModelPartForStruct< %s::%s >::Hook< %s, &%s::%s::%s, ",
modulePath().c_str(), c->name().c_str(),
Slice::typeToString(type).c_str(),
modulePath().c_str(), c->name().c_str(), dm->name().c_str());
createNewModelPartPtrFor(type);
- fprintf(cpp, " < %s > >() },\n",
- Slice::typeToString(type).c_str());
+ fprintf(cpp, "< %s > >(\"%s\") },\n",
+ Slice::typeToString(type).c_str(),
+ name ? name->c_str() : dm->name().c_str());
}
fprintf(cpp, "\t};\n\n");
@@ -179,25 +179,25 @@ namespace Slicer {
modulePath().c_str(), d->name().c_str());
auto kname = metaDataValue("slicer:key:", d->getMetaData());
auto vname = metaDataValue("slicer:value:", d->getMetaData());
- fprintf(cpp, "\t\t{ \"%s\", ",
- kname ? kname->c_str() : "key");
+ fprintf(cpp, "\t\t{ ");
auto ktype = d->keyType();
fprintf(cpp, "new ModelPartForDictionaryElement< %s::%s >::Hook< %s*, &ModelPartForDictionaryElement< %s::%s >::key, ",
modulePath().c_str(), d->name().c_str(),
Slice::typeToString(ktype).c_str(),
modulePath().c_str(), d->name().c_str());
createNewModelPartPtrFor(ktype);
- fprintf(cpp, "< %s > >() },\n\t\t{ \"%s\", ",
+ fprintf(cpp, "< %s > >(\"%s\") },\n\t\t{ ",
Slice::typeToString(ktype).c_str(),
- vname ? vname->c_str() : "value");
+ kname ? kname->c_str() : "key");
auto vtype = d->valueType();
fprintf(cpp, "new ModelPartForDictionaryElement< %s::%s >::Hook< %s*, &ModelPartForDictionaryElement< %s::%s >::value, ",
modulePath().c_str(), d->name().c_str(),
Slice::typeToString(vtype).c_str(),
modulePath().c_str(), d->name().c_str());
createNewModelPartPtrFor(vtype);
- fprintf(cpp, "< %s > >() },\n",
- Slice::typeToString(vtype).c_str());
+ fprintf(cpp, "< %s > >(\"%s\") },\n",
+ Slice::typeToString(vtype).c_str(),
+ vname ? vname->c_str() : "value");
fprintf(cpp, "\t};\n");
fprintf(cpp, "\n");
}