summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-05-17 14:38:37 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-05-17 14:38:37 +0100
commit882119cc603bfb6833ae42105d85df19377092ab (patch)
treeac84619bc0eee06a3de667dac4a8b5ae9c6453c1
parentRemove unrequired boost/lexical_cast include (diff)
downloadicespider-0.7.2.tar.bz2
icespider-0.7.2.tar.xz
icespider-0.7.2.zip
constexpr and member initial all/most parameter specification vars where possibleicespider-0.7.2
-rw-r--r--icespider/compile/routeCompiler.cpp47
1 files changed, 17 insertions, 30 deletions
diff --git a/icespider/compile/routeCompiler.cpp b/icespider/compile/routeCompiler.cpp
index bafc5f3..3828d46 100644
--- a/icespider/compile/routeCompiler.cpp
+++ b/icespider/compile/routeCompiler.cpp
@@ -450,33 +450,6 @@ namespace IceSpider {
fprintbf(4, output, "%s(core)", b);
}
auto proxies = initializeProxies(output, r.second);
- for (const auto & p : r.second->params) {
- if (p.second->hasUserSource) {
- if (p.second->source == ParameterSource::URL) {
- fputs(",\n", output);
- Path path(r.second->path);
- long idx = -1;
- for (const auto & pp : path.parts) {
- if (auto par = dynamic_cast<PathParameter *>(pp.get())) {
- if (par->name == *p.second->key) {
- idx = &pp - &path.parts.front();
- }
- }
- };
- fprintbf(4, output, "_pi_%s(%d)", p.first, idx);
- }
- else {
- if (p.second->key) {
- fputs(",\n", output);
- fprintbf(4, output, "_pn_%s(\"%s\")", p.first, *p.second->key);
- }
- }
- }
- if (p.second->defaultExpr) {
- fputs(",\n", output);
- fprintbf(4, output, "_pd_%s(%s)", p.first, *p.second->defaultExpr);
- }
- }
fputs("\n", output);
fprintbf(3, output, "{\n");
registerOutputSerializers(output, r.second);
@@ -545,15 +518,29 @@ namespace IceSpider {
for (const auto & p : r.second->params) {
if (p.second->hasUserSource) {
if (p.second->source == ParameterSource::URL) {
- fprintbf(3, output, "const unsigned int _pi_%s;\n", p.first);
+ Path path(r.second->path);
+ long idx = -1;
+ for (const auto & pp : path.parts) {
+ if (auto par = dynamic_cast<PathParameter *>(pp.get())) {
+ if (par->name == *p.second->key) {
+ idx = &pp - &path.parts.front();
+ }
+ }
+ }
+ fprintbf(3, output, "static constexpr unsigned int _pi_%s{%ld};\n", p.first, idx);
}
else {
- fprintbf(3, output, "const std::string _pn_%s;\n", p.first);
+ fprintbf(3, output, "static constexpr std::string_view _pn_%s{", p.first);
+ if (p.second->key) {
+ fprintbf(output, "\"%s\"", *p.second->key);
+ }
+ fputs("};\n", output);
}
}
if (p.second->defaultExpr) {
auto ip = ps.find(p.first)->second;
- fprintbf(3, output, "const %s _pd_%s;\n", Slice::typeToString(ip->type()), p.first);
+ fprintbf(3, output, "static const %s _pd_%s{%s};\n", Slice::typeToString(ip->type()), p.first,
+ *p.second->defaultExpr);
}
}
fprintbf(1, output, "};\n\n");