pgLab/pglablib/codebuilder/DefaultConfigs.cpp
eelke 0c3bb27e58 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.
2018-09-19 09:55:43 +02:00

86 lines
2.1 KiB
C++

#include "DefaultConfigs.h"
#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> GetPglabCppTypeMappings()
{
auto tm = std::make_shared<TypeMappings>();
*tm = {
{ bool_oid, "bool" },
{ char_oid, "char" },
{ name_oid, "std::string" },
{ int8_oid, "int64_t" },
{ int2_oid, "int16_t" },
{ int4_oid, "int32_t" },
{ text_oid, "std::string" },
{ oid_oid, "Oid" },
{ float4_oid, "float" },
{ float8_oid, "double" }
};
tm->setDefaultStringType("std::string");
tm->setDefaultContainerType("std::vector<%1>");
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%/>;
)__";
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(GetPglabCppTypeMappings());
config->setNameManglingRules(std::make_shared<NameManglingRules>());
config->setStructureTemplate(buildPglabStructureTemplate());
config->setIndentationConfig(std::make_shared<IndentationConfig>());
config->setResultLoopTemplate(buildPglabResultLoopTemplate());
return config;
}
std::shared_ptr<const LanguageConfig> getPglabCppLanguageConfig()
{
static auto config = buildPglabCppLanguageConfig();
return config;
}