From cc3bc93388925c8de112a6e8cfc412219c16cf37 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 30 Dec 2016 19:10:58 +0000 Subject: Add macros to ease declartion of formatters --- libadhocutil/compileTimeFormatter.h | 6 ++++++ libadhocutil/unittests/testCompileTimeFormatter.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index 631b0f7..7734f9c 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -213,3 +213,9 @@ namespace AdHoc { }; } +#define AdHocFormatterTypedef(name, str, id) \ + extern constexpr auto id = str; \ + typedef ::AdHoc::Formatter name +#define AdHocFormatter(name, str) \ + AdHocFormatterTypedef(name, str, name ## __COUNTER__) + diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index df0d93c..030dbc9 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -196,6 +196,13 @@ BOOST_AUTO_TEST_CASE ( typedefFormat ) BOOST_REQUIRE_EQUAL(this->str(), "custom -( expr )-"); } +AdHocFormatter(TypedefWrapper, "Typedef wrapper %?."); +BOOST_AUTO_TEST_CASE ( typedefWrapper ) +{ + TypedefWrapper::write(*this, "expr"); + BOOST_REQUIRE_EQUAL(this->str(), "Typedef wrapper expr."); +} + BOOST_AUTO_TEST_CASE ( longFormatString ) { Formatter::write(*this); -- cgit v1.2.3