From 046cdae1a14a686238ab91b1f883335b2de5a78c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 1 Jun 2021 00:17:38 +0100 Subject: Generate DbStmt templates from .sql files m4 generator and related code. Reshuffles some CTF stuff to avoid pulling in all of CTF and iostream for its fixed_string. Moves CTF out of AdHoc namespace. Add some initial SQL statements. --- lib/fixedString.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lib/fixedString.h (limited to 'lib/fixedString.h') diff --git a/lib/fixedString.h b/lib/fixedString.h new file mode 100644 index 0000000..df0529a --- /dev/null +++ b/lib/fixedString.h @@ -0,0 +1,59 @@ +#ifndef MYGRATE_SUPPORT_FIXEDSTRING_H +#define MYGRATE_SUPPORT_FIXEDSTRING_H + +#include +#include +#include + +namespace MyGrate::Support { + template class basic_fixed_string { + public: + // cppcheck-suppress noExplicitConstructor + constexpr basic_fixed_string(const CharT (&str)[N + 1]) + { + for (decltype(N) x = 0; x < N; x++) { + arr.at(x) = str[x]; + } + arr.at(N) = '\0'; + } + constexpr basic_fixed_string(const CharT * str, decltype(N) len) + { + for (decltype(N) x = 0; x < len; x++) { + arr.at(x) = str[x]; + } + arr.at(N) = '\0'; + } + constexpr const char * + s() const + { + return arr.data(); + } + constexpr operator const char *() const + { + return s(); + } + constexpr std::string_view + v() const + { + return {arr.data(), arr.size() - 1}; + } + constexpr auto & + operator[](std::size_t n) const + { + return arr[n]; + } + constexpr auto + size() const + { + return arr.size() - 1; + } + + std::array arr; + }; + + template + basic_fixed_string(const CharT (&str)[N]) -> basic_fixed_string; + +} + +#endif -- cgit v1.2.3