cemplateSimple C++ template engine |
git clone git://git.dimitrijedobrota.com/cemplate.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | |
commit | 8af41f111c5fd88053b3276b7c6de4e8da9fa40e |
parent | 0f85cc52df5322f9dc9cfdf6db2b1d912338575e |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Sat, 22 Feb 2025 21:44:03 +0100 |
Extract .hpp and .cpp files
Diffstat:M | .clang-tidy | | | ++- |
M | CMakeLists.txt | | | +- |
M | example/example.cpp | | | +---------------------------------------------------------- |
M | include/cemplate/cemplate.hpp | | | +++++++++++++++++++++--------- |
M | source/cemplate.cpp | | | +++++++++++++++++++++++++++++++++++++++++++++----- |
5 files changed, 70 insertions(+), 74 deletions(-)
diff --git a/.clang-tidy b/.clang-tidy
@@ -13,9 +13,10 @@ Checks: "*,\
-llvm-header-guard,\
-llvm-include-order,\
-llvmlibc-*,\
-modernize-use-designated-initializers,\
-modernize-use-nodiscard,\
-modernize-use-trailing-return-type,\
-modernize-use-ranges,\
-modernize-use-trailing-return-type,\
-misc-include-cleaner,\
"
WarningsAsErrors: ''
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)
project(
cemplate
VERSION 0.1.1
VERSION 0.1.2
DESCRIPTION "Simple C++ template engine"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/cemplate.git"
LANGUAGES CXX
diff --git a/example/example.cpp b/example/example.cpp
@@ -1,63 +1,6 @@
#include <format>
#include <iostream>
#include <string>
#include <vector>
namespace cemplate
{
std::string pragma_once()
{
return "#pragma once\n\n";
}
std::string include(const std::string& header, bool local = false)
{
return local ? std::format("#include \"{}\"\n", header)
: std::format("#include <{}>\n", header);
}
std::string nspace(const std::string& name)
{
return std::format("namespace {}\n{{\n\n\n", name);
}
std::string nspace_close(const std::string& name)
{
return std::format("\n}} // namespace {}\n\n", name);
}
struct param_t
{
std::string type;
std::string name;
};
std::string func(const std::string& ret,
const std::string& name,
std::vector<param_t> params)
{
std::string res;
res += ret + ' ';
res += name + '(';
if (!params.empty()) {
res += params[0].type + ' ' + params[0].name;
for (std::size_t i = 1; i < params.size(); i++) {
res += ", " + params[i].type + ' ' + params[i].name;
}
}
res += ") {\n";
return res;
}
std::string func_close()
{
return "}\n\n";
}
} // namespace cemplate
#include "cemplate/cemplate.hpp"
int main()
{
diff --git a/include/cemplate/cemplate.hpp b/include/cemplate/cemplate.hpp
@@ -1,17 +1,29 @@
#pragma once
#include <string>
#include <vector>
#include "cemplate/cemplate_export.hpp"
class CEMPLATE_EXPORT exported_class
namespace cemplate
{
public:
exported_class();
auto name() const -> char const*;
std::string pragma_once();
std::string include(const std::string& header, bool local = false);
std::string nspace(const std::string& name);
std::string nspace_close(const std::string& name);
private:
CEMPLATE_SUPPRESS_C4251
std::string m_name;
struct param_t
{
std::string type;
std::string name;
};
std::string func(const std::string& ret,
const std::string& name,
std::vector<param_t> params);
std::string func_close();
} // namespace cemplate
diff --git a/source/cemplate.cpp b/source/cemplate.cpp
@@ -1,13 +1,53 @@
#include <string>
#include <format>
#include "cemplate/cemplate.hpp"
exported_class::exported_class()
: m_name {"cemplate"}
namespace cemplate
{
std::string pragma_once()
{
return "#pragma once\n\n";
}
std::string include(const std::string& header, bool local)
{
return local ? std::format("#include \"{}\"\n", header)
: std::format("#include <{}>\n", header);
}
char const* exported_class::name() const
std::string nspace(const std::string& name)
{
return m_name.c_str();
return std::format("namespace {}\n{{\n\n\n", name);
}
std::string nspace_close(const std::string& name)
{
return std::format("\n}} // namespace {}\n\n", name);
}
std::string func(const std::string& ret,
const std::string& name,
std::vector<param_t> params)
{
std::string res;
res += ret + ' ';
res += name + '(';
if (!params.empty()) {
res += params[0].type + ' ' + params[0].name;
for (std::size_t i = 1; i < params.size(); i++) {
res += ", " + params[i].type + ' ' + params[i].name;
}
}
res += ") {\n";
return res;
}
std::string func_close()
{
return "}\n\n";
}
} // namespace cemplate