2018-09-09 18:52:32 +02:00
|
|
|
|
#include "DefaultConfigs.h"
|
2018-09-18 11:53:19 +02:00
|
|
|
|
#include "IndentationConfig.h"
|
2018-09-09 18:52:32 +02:00
|
|
|
|
#include "LanguageConfig.h"
|
2018-09-18 11:53:19 +02:00
|
|
|
|
#include "NameManglingRules.h"
|
2018-09-19 09:55:43 +02:00
|
|
|
|
#include "ResultLoopTemplate.h"
|
2018-09-18 11:53:19 +02:00
|
|
|
|
#include "StructureTemplate.h"
|
2018-09-09 18:52:32 +02:00
|
|
|
|
#include "TypeMappings.h"
|
|
|
|
|
|
#include "Pgsql_oids.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Pgsql;
|
|
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
std::shared_ptr<const TypeMappings> GetPglabCppTypeMappings()
|
2018-09-09 18:52:32 +02:00
|
|
|
|
{
|
2018-09-18 11:53:19 +02:00
|
|
|
|
auto tm = std::make_shared<TypeMappings>();
|
|
|
|
|
|
*tm = {
|
2018-09-09 18:52:32 +02:00
|
|
|
|
{ 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" }
|
|
|
|
|
|
};
|
2018-09-18 11:53:19 +02:00
|
|
|
|
tm->setDefaultStringType("std::string");
|
|
|
|
|
|
tm->setDefaultContainerType("std::vector<%1>");
|
|
|
|
|
|
return tm;
|
2018-09-09 18:52:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
std::shared_ptr<StructureTemplate> buildPglabStructureTemplate()
|
2018-09-09 18:52:32 +02:00
|
|
|
|
{
|
2018-09-19 09:55:43 +02:00
|
|
|
|
auto t = std::make_shared<StructureTemplate>();
|
|
|
|
|
|
t->m_structTemplate =
|
|
|
|
|
|
R"__(class /%structname%/ {
|
|
|
|
|
|
public:
|
|
|
|
|
|
/%structfields%/
|
|
|
|
|
|
};
|
|
|
|
|
|
using /%structname%/Lst = std::vector</%structname%/>;
|
|
|
|
|
|
)__";
|
2018-09-18 11:53:19 +02:00
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
t->m_fieldTemplate = "/%typename%/ /%varname%/;";
|
2018-09-18 11:53:19 +02:00
|
|
|
|
//st_templ->m_fieldSeparator;
|
|
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
return t;
|
2018-09-09 18:52:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
std::shared_ptr<ResultLoopTemplate> buildPglabResultLoopTemplate()
|
2018-09-09 18:52:32 +02:00
|
|
|
|
{
|
2018-09-19 09:55:43 +02:00
|
|
|
|
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);
|
2018-09-09 18:52:32 +02:00
|
|
|
|
}
|
2018-09-19 09:55:43 +02:00
|
|
|
|
)__";
|
|
|
|
|
|
t->m_retrieveValueTemplate = " >> v./%varname%/";
|
2018-09-09 18:52:32 +02:00
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
return t;
|
|
|
|
|
|
}
|
2018-09-09 18:52:32 +02:00
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
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;
|
2018-09-09 18:52:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-19 09:55:43 +02:00
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<const LanguageConfig> getPglabCppLanguageConfig()
|
2018-09-09 18:52:32 +02:00
|
|
|
|
{
|
2018-09-19 09:55:43 +02:00
|
|
|
|
static auto config = buildPglabCppLanguageConfig();
|
2018-09-09 18:52:32 +02:00
|
|
|
|
return config;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|