#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 GetPglabCppTypeMappings() { auto tm = std::make_shared(); *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 buildPglabStructureTemplate() { auto t = std::make_shared(); t->m_structTemplate = R"__(class /%structname%/ { public: /%structfields%/ }; using /%structname%/Lst = std::vector; )__"; t->m_fieldTemplate = "/%typename%/ /%varname%/;"; //st_templ->m_fieldSeparator; return t; } std::shared_ptr buildPglabResultLoopTemplate() { auto t = std::make_shared(); 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 buildPglabCppLanguageConfig() { auto config = std::make_shared(); config->setTypeMappings(GetPglabCppTypeMappings()); config->setNameManglingRules(std::make_shared()); config->setStructureTemplate(buildPglabStructureTemplate()); config->setIndentationConfig(std::make_shared()); config->setResultLoopTemplate(buildPglabResultLoopTemplate()); return config; } std::shared_ptr getPglabCppLanguageConfig() { static auto config = buildPglabCppLanguageConfig(); return config; }