diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-18 14:24:37 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-10-18 14:24:37 +0100 |
commit | 9d42d62da33f796b6d56f721169fc533450a1d21 (patch) | |
tree | a03598e79a83033441cbae6e864f82590cf669be | |
parent | Simplify generated hook code with typedefs (diff) | |
download | slicer-9d42d62da33f796b6d56f721169fc533450a1d21.tar.bz2 slicer-9d42d62da33f796b6d56f721169fc533450a1d21.tar.xz slicer-9d42d62da33f796b6d56f721169fc533450a1d21.zip |
Remove duplication adding dictionary element hooks
-rw-r--r-- | slicer/tool/parser.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index a6c68d0..f3c4a2c 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -384,25 +384,19 @@ namespace Slicer { components); fprintbf(cpp, "\t\tC%d::Hooks r;\n", components); - auto kname = metaDataValue("slicer:key:", d->getMetaData()); - auto vname = metaDataValue("slicer:value:", d->getMetaData()); + auto addHook = [&](const std::string & name, const char * element, const Slice::TypePtr & t) { fprintbf(cpp, "\t\t"); - auto ktype = d->keyType(); fprintbf(cpp, "r.push_back(std::make_unique< C%d::Hook< const %s, ", components, - Slice::typeToString(ktype)); - createNewModelPartPtrFor(ktype); - fprintbf(cpp, " > >(&%s::value_type::first, \"%s\"));\n\t\t", + Slice::typeToString(t)); + createNewModelPartPtrFor(t); + fprintbf(cpp, " > >(&%s::value_type::%s, \"%s\"));\n", d->scoped(), - kname ? *kname : "key"); - auto vtype = d->valueType(); - fprintbf(cpp, "r.push_back(std::make_unique< C%d::Hook< const %s, ", - components, - Slice::typeToString(vtype)); - createNewModelPartPtrFor(vtype); - fprintbf(cpp, " > >(&%s::value_type::second, \"%s\"));\n", - d->scoped(), - vname ? *vname : "value"); + element, + name); + }; + addHook(metaDataValue("slicer:key:", d->getMetaData()).value_or("key"), "first", d->keyType()); + addHook(metaDataValue("slicer:value:", d->getMetaData()).value_or("value"), "second", d->valueType()); fprintbf(cpp, "\t\treturn r;\n"); fprintbf(cpp, "\t}());\n"); fprintbf(cpp, "\n"); |