Further improvements to codegeneration the defaultcpp config is now called the PgLab

config as it is very specific to the PgLab codebase.

More hard programmed templates moved out of codebuilder to the language config.
This commit is contained in:
eelke 2018-09-19 09:55:43 +02:00
parent 0ba632afd1
commit 0c3bb27e58
10 changed files with 143 additions and 91 deletions

View file

@ -2,13 +2,14 @@
#include "IndentationConfig.h"
#include "LanguageConfig.h"
#include "NameManglingRules.h"
#include "ResultLoopTemplate.h"
#include "StructureTemplate.h"
#include "TypeMappings.h"
#include "Pgsql_oids.h"
using namespace Pgsql;
std::shared_ptr<const TypeMappings> GetDefaultCppTypeMappings()
std::shared_ptr<const TypeMappings> GetPglabCppTypeMappings()
{
auto tm = std::make_shared<TypeMappings>();
*tm = {
@ -28,40 +29,57 @@ std::shared_ptr<const TypeMappings> GetDefaultCppTypeMappings()
return tm;
}
std::shared_ptr<StructureTemplate> buildPglabStructureTemplate()
{
auto t = std::make_shared<StructureTemplate>();
t->m_structTemplate =
R"__(class /%structname%/ {
public:
/%structfields%/
};
using /%structname%/Lst = std::vector</%structname%/>;
)__";
std::shared_ptr<LanguageConfig> buildDefaultCppLanguageConfig()
t->m_fieldTemplate = "/%typename%/ /%varname%/;";
//st_templ->m_fieldSeparator;
return t;
}
std::shared_ptr<ResultLoopTemplate> buildPglabResultLoopTemplate()
{
auto t = std::make_shared<ResultLoopTemplate>();
t->m_loopTemplate =
R"__(Pgsql::Result result = conn.query(/%queryliteral%/);
/%structname%/Lst lst;
for (auto row: result) {
Pgsql::Col col(row);
/%structname%/ v;
col
/%assignfields%/;
lst.push_back(v);
}
)__";
t->m_retrieveValueTemplate = " >> v./%varname%/";
return t;
}
std::shared_ptr<LanguageConfig> buildPglabCppLanguageConfig()
{
auto config = std::make_shared<LanguageConfig>();
config->setTypeMappings(GetDefaultCppTypeMappings());
config->setTypeMappings(GetPglabCppTypeMappings());
config->setNameManglingRules(std::make_shared<NameManglingRules>());
auto st_templ = std::make_shared<StructureTemplate>();
st_templ->m_startTemplate = "class /%structname%/ {\npublic:\n";
st_templ->m_endTemplate = "};\n"; // };
st_templ->m_fieldTemplate = "/%typename%/ /%varname%/;";
//st_templ->m_fieldSeparator;
config->setStructureTemplate(st_templ);
config->setStructureTemplate(buildPglabStructureTemplate());
config->setIndentationConfig(std::make_shared<IndentationConfig>());
return config;
}
std::shared_ptr<const LanguageConfig> getDefaultCppLanguageConfig()
{
static auto config = buildDefaultCppLanguageConfig();
return config;
}
std::shared_ptr<const LanguageConfig> buildPgLabCppLanguageConfig()
{
auto cfg = buildDefaultCppLanguageConfig();
return cfg;
}
std::shared_ptr<const LanguageConfig> getPgLabCppLanguageConfig()
{
static auto config = buildPgLabCppLanguageConfig();
config->setResultLoopTemplate(buildPglabResultLoopTemplate());
return config;
}
std::shared_ptr<const LanguageConfig> getPglabCppLanguageConfig()
{
static auto config = buildPglabCppLanguageConfig();
return config;
}