diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-30 18:26:34 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-30 18:26:34 +0000 | 
| commit | 4a7eaceea8faaad11c12d7450d080321074dbed3 (patch) | |
| tree | fccb797d306aea1af7e9278b9195f3e8dc796a6b | |
| parent | Return stream to ease inlining (diff) | |
| download | libadhocutil-4a7eaceea8faaad11c12d7450d080321074dbed3.tar.bz2 libadhocutil-4a7eaceea8faaad11c12d7450d080321074dbed3.tar.xz libadhocutil-4a7eaceea8faaad11c12d7450d080321074dbed3.zip  | |
Add doxygen comments for compile time formatter
| -rw-r--r-- | libadhocutil/compileTimeFormatter.h | 59 | 
1 files changed, 39 insertions, 20 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index aeff488..631b0f7 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -4,6 +4,7 @@  #include <boost/preprocessor/variadic/size.hpp>  namespace AdHoc { +	/// @cond  	constexpr int WRAP_AT = 120;  	template <int, char...> struct Buffer { }; @@ -169,28 +170,46 @@ namespace AdHoc {  	template <const char * const & S, int offset, int roffset, char ... sn>  	struct Parser<S, offset, roffset, 0, sn...> : public ParserBase<S, false, sn..., 0>{ }; +	/// @endcond +	/** +	 * Compile time string formatter. +	 * @param S the format string. +	 */  	template <const char * const & S> -	struct Formatter { -		template<typename ... Pn> -		static std::string get(const Pn & ... pn) -		{ -			std::stringstream s; -			return run(Parser<S, 0, 0, *S>::parse(), s, pn...).str(); -		} - -		template<typename stream, typename ... Pn> -		static stream & write(stream & s, const Pn & ... pn) -		{ -			return run(Parser<S, 0, 0, *S>::parse(), s, pn...); -		} - -		template<typename stream, char...ssn, template<bool, char...> class ParserBuffer, typename ... Pn> -		static stream & run(const ParserBuffer<false, ssn...> &, stream & s, const Pn & ... pn) -		{ -			StreamWriter<S, 0, stream, ssn...>::write(s, pn...); -			return s; -		} +	class Formatter { +		public: +			/** +			 * Get a string containing the result of formatting. +			 * @param pn the format arguments. +			 * @return the formatted string. +			 */ +			template<typename ... Pn> +			static std::string get(const Pn & ... pn) +			{ +				std::stringstream s; +				return run(Parser<S, 0, 0, *S>::parse(), s, pn...).str(); +			} + +			/** +			 * Write the result of formatting to the given stream. +			 * @param s the stream to write to. +			 * @param pn the format arguments. +			 * @return the stream. +			 */ +			template<typename stream, typename ... Pn> +			static stream & write(stream & s, const Pn & ... pn) +			{ +				return run(Parser<S, 0, 0, *S>::parse(), s, pn...); +			} + +		private: +			template<typename stream, char...ssn, template<bool, char...> class ParserBuffer, typename ... Pn> +			static stream & run(const ParserBuffer<false, ssn...> &, stream & s, const Pn & ... pn) +			{ +				StreamWriter<S, 0, stream, ssn...>::write(s, pn...); +				return s; +			}  	};  }  | 
