diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-12-06 14:15:43 -0800 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-12-06 14:15:49 -0800 |
commit | 3eea219548e84efdbc3148ce378fcba865f97a01 (patch) | |
tree | 6ece594f60ddff038cf9c1d94b99d8d66a00bc20 /src/io/cxxstdio.hpp | |
parent | 1458563f00deebbbcf3e8049dc90157fb825fae3 (diff) | |
download | tmwa-3eea219548e84efdbc3148ce378fcba865f97a01.tar.gz tmwa-3eea219548e84efdbc3148ce378fcba865f97a01.tar.bz2 tmwa-3eea219548e84efdbc3148ce378fcba865f97a01.tar.xz tmwa-3eea219548e84efdbc3148ce378fcba865f97a01.zip |
Add basic source formatting tools
Diffstat (limited to 'src/io/cxxstdio.hpp')
-rw-r--r-- | src/io/cxxstdio.hpp | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/src/io/cxxstdio.hpp b/src/io/cxxstdio.hpp index 0d0bdba..b4b4c79 100644 --- a/src/io/cxxstdio.hpp +++ b/src/io/cxxstdio.hpp @@ -19,16 +19,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. -#include "../sanity.hpp" +# include "../sanity.hpp" -#include <cstdarg> -#include <cstdio> +# include <cstdarg> +# include <cstdio> // TODO get rid of these header order violations -#include "../common/const_array.hpp" -#include "../common/utils2.hpp" +# include "../common/const_array.hpp" +# include "../common/utils2.hpp" -#include "fwd.hpp" +# include "fwd.hpp" namespace cxxstdio @@ -46,16 +46,16 @@ namespace cxxstdio return vfscanf(in, fmt, ap); } -#if 0 +# if 0 inline __attribute__((format(scanf, 2, 0))) int do_vscan(const char *in, const char *fmt, va_list ap) { return vsscanf(in, fmt, ap); } -#else +# else inline int do_vscan(const char *, const char *, va_list) = delete; -#endif +# endif template<class T> inline __attribute__((format(printf, 2, 3))) @@ -101,7 +101,7 @@ namespace cxxstdio return v; } -#if 0 +# if 0 template<class E> constexpr E get_enum_min_value(decltype(E::min_value)) @@ -127,7 +127,7 @@ namespace cxxstdio { return def; } -#else +# else template<class E> constexpr E get_enum_min_value(E) @@ -140,24 +140,24 @@ namespace cxxstdio { return E::max_value; } -#endif +# endif template<class E> class EnumConverter { E& out; typedef typename underlying_type<E>::type U; -#if 0 +# if 0 constexpr static U min_value = U(get_enum_min_value<E>(E(std::numeric_limits<U>::min()))); constexpr static U max_value = U(get_enum_max_value<E>(E(std::numeric_limits<U>::max()))); -#else +# else constexpr static U min_value = U(get_enum_min_value(E())); constexpr static U max_value = U(get_enum_max_value(E())); -#endif +# endif U mid; public: EnumConverter(E& e) @@ -165,10 +165,10 @@ namespace cxxstdio {} ~EnumConverter() { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wtype-limits" if (min_value <= mid && mid <= max_value) -#pragma GCC diagnostic pop +# pragma GCC diagnostic pop out = E(mid); } U *operator &() @@ -213,49 +213,49 @@ namespace cxxstdio } }; -#define XPRINTF(out, fmt, ...) \ - (/*[&]() -> int*/ \ - { \ - struct format_impl \ - { \ - constexpr static \ - const char *print_format() { return fmt; } \ - }; \ +# define XPRINTF(out, fmt, ...) \ + (/*[&]() -> int*/ \ + { \ + struct format_impl \ + { \ + constexpr static \ + const char *print_format() { return fmt; } \ + }; \ /*return*/ cxxstdio::PrintFormatter<format_impl>::print(out, ## __VA_ARGS__); \ }/*()*/) -#define XSCANF(out, fmt, ...) \ - (/*[&]() -> int*/ \ - { \ - struct format_impl \ - { \ - constexpr static \ - const char *scan_format() { return fmt; } \ - }; \ - /*return*/ cxxstdio::ScanFormatter<format_impl>::scan(out, ## __VA_ARGS__); \ +# define XSCANF(out, fmt, ...) \ + (/*[&]() -> int*/ \ + { \ + struct format_impl \ + { \ + constexpr static \ + const char *scan_format() { return fmt; } \ + }; \ + /*return*/ cxxstdio::ScanFormatter<format_impl>::scan(out, ## __VA_ARGS__); \ }/*()*/) -#define FPRINTF(file, fmt, ...) XPRINTF(/*no_cast<FILE *>*/(file), fmt, ## __VA_ARGS__) -#define FSCANF(file, fmt, ...) XSCANF(no_cast<FILE *>(file), fmt, ## __VA_ARGS__) -#define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__) -#define SPRINTF(str, fmt, ...) XPRINTF(base_cast<FString&>(str), fmt, ## __VA_ARGS__) -#define SNPRINTF(str, n, fmt, ...) XPRINTF(base_cast<VString<n-1>&>(str), fmt, ## __VA_ARGS__) -#define SCANF(fmt, ...) FSCANF(stdin, fmt, ## __VA_ARGS__) -#define SSCANF(str, fmt, ...) XSCANF(/*ZString or compatible*/str, fmt, ## __VA_ARGS__) +# define FPRINTF(file, fmt, ...) XPRINTF(/*no_cast<FILE *>*/(file), fmt, ## __VA_ARGS__) +# define FSCANF(file, fmt, ...) XSCANF(no_cast<FILE *>(file), fmt, ## __VA_ARGS__) +# define PRINTF(fmt, ...) FPRINTF(stdout, fmt, ## __VA_ARGS__) +# define SPRINTF(str, fmt, ...) XPRINTF(base_cast<FString&>(str), fmt, ## __VA_ARGS__) +# define SNPRINTF(str, n, fmt, ...) XPRINTF(base_cast<VString<n-1>&>(str), fmt, ## __VA_ARGS__) +# define SCANF(fmt, ...) FSCANF(stdin, fmt, ## __VA_ARGS__) +# define SSCANF(str, fmt, ...) XSCANF(/*ZString or compatible*/str, fmt, ## __VA_ARGS__) -#define STRPRINTF(fmt, ...) \ +# define STRPRINTF(fmt, ...) \ (/*[&]() -> FString*/ \ - { \ - FString _out_impl; \ - SPRINTF(_out_impl, fmt, ## __VA_ARGS__);\ + { \ + FString _out_impl; \ + SPRINTF(_out_impl, fmt, ## __VA_ARGS__); \ /*return*/ _out_impl; \ }/*()*/) -#define STRNPRINTF(n, fmt, ...) \ +# define STRNPRINTF(n, fmt, ...) \ (/*[&]() -> VString<n - 1>*/ \ - { \ - VString<n - 1> _out_impl; \ - SNPRINTF(_out_impl, n, fmt, ## __VA_ARGS__);\ + { \ + VString<n - 1> _out_impl; \ + SNPRINTF(_out_impl, n, fmt, ## __VA_ARGS__); \ /*return*/ _out_impl; \ }/*()*/) |