summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-10-18 14:55:23 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-10-18 14:55:23 +0100
commitfe33a067f81e5239ef17ac88868392a87b0b5fe0 (patch)
treefe6be12022a4736871bcb35647deaa2110b474f6
parentRemove duplication adding dictionary element hooks (diff)
downloadslicer-fe33a067f81e5239ef17ac88868392a87b0b5fe0.tar.bz2
slicer-fe33a067f81e5239ef17ac88868392a87b0b5fe0.tar.xz
slicer-fe33a067f81e5239ef17ac88868392a87b0b5fe0.zip
Simplify addition of hooks further with addHook helper
-rw-r--r--slicer/slicer/modelPartsTypes.h3
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h7
-rw-r--r--slicer/tool/parser.cpp22
3 files changed, 21 insertions, 11 deletions
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index 1af328f..630eec7 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -176,6 +176,9 @@ namespace Slicer {
typedef std::vector<HookPtr> Hooks;
+ template<typename H, typename ... P>
+ static void addHook(Hooks &, const P & ...);
+
static const Hooks hooks;
static const Metadata metadata;
};
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index 282418c..a1a963a 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -363,6 +363,13 @@ namespace Slicer {
}
template<typename T>
+ template<typename H, typename ... P>
+ void ModelPartForComplex<T>::addHook(Hooks & h, const P & ... p)
+ {
+ h.push_back(std::make_unique<H>(p...));
+ }
+
+ template<typename T>
ModelPartForComplex<T>::HookBase::HookBase(const std::string & n) :
HookCommon(n)
{
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index f3c4a2c..ce89e2f 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -261,9 +261,9 @@ namespace Slicer {
if (!t) {
t = Slice::ClassDefPtr::dynamicCast(dm->container())->declaration();
}
- auto name = metaDataValue("slicer:name:", dm->getMetaData());
- fprintbf(cpp, "\t\tr.push_back(std::make_unique<C%d::",
- components);
+ auto name = metaDataValue("slicer:name:", dm->getMetaData()).value_or_eval(std::bind(&Slice::DataMember::name, dm));
+ fprintbf(cpp, "\t\tC%d::addHook<C%d::",
+ components, components);
auto type = dm->type();
if (hasMetadata(dm->getMetaData())) {
fprintbf(cpp, "HookMetadata<");
@@ -274,14 +274,14 @@ namespace Slicer {
fprintbf(cpp, " %s, ",
Slice::typeToString(type, dm->optional()));
createNewModelPartPtrFor(type, dm, getAllMetadata(dm));
- fprintbf(cpp, " > >(&%s, \"%s\"",
+ fprintbf(cpp, " > >(r, &%s, \"%s\"",
dm->scoped(),
- name ? *name : dm->name());
+ name);
if (hasMetadata(dm->getMetaData())) {
fprintbf(cpp, ", Metadata ");
copyMetadata(dm->getMetaData());
}
- fprintbf(cpp, " ));\n");
+ fprintbf(cpp, ");\n");
}
fprintbf(cpp, "\t\treturn r;\n");
fprintbf(cpp, "\t}());\n\n");
@@ -385,13 +385,13 @@ namespace Slicer {
fprintbf(cpp, "\t\tC%d::Hooks r;\n",
components);
auto addHook = [&](const std::string & name, const char * element, const Slice::TypePtr & t) {
- fprintbf(cpp, "\t\t");
- fprintbf(cpp, "r.push_back(std::make_unique< C%d::Hook< const %s, ",
- components,
+ fprintbf(cpp, "\t\t");
+ fprintbf(cpp, "C%d::addHook< C%d::Hook< const %s, ",
+ components, components,
Slice::typeToString(t));
createNewModelPartPtrFor(t);
- fprintbf(cpp, " > >(&%s::value_type::%s, \"%s\"));\n",
- d->scoped(),
+ fprintbf(cpp, " > >(r, &%s::value_type::%s, \"%s\");\n",
+ d->scoped(),
element,
name);
};