From d884cf1a9a6c5abee4ff9bef6a2bac15996bfbad Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 10 Apr 2015 12:50:48 +0200 Subject: [PATCH] base: unify ascii_to conversion functions This patch addresses the first point of the issue #1477, namely replacing the function-template magic by plain function overloads. Issue #1477 --- repos/base/include/util/string.h | 35 ++++++-------------------------- repos/os/include/util/color.h | 7 ++----- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/repos/base/include/util/string.h b/repos/base/include/util/string.h index 9c7eb73dd..e6b749d8d 100644 --- a/repos/base/include/util/string.h +++ b/repos/base/include/util/string.h @@ -264,28 +264,10 @@ namespace Genode { } - /** - * Convert ASCII string to another type - * - * \param T destination type of conversion - * \param s null-terminated source string - * \param result destination pointer to conversion result - * \param base base, autodetected if set to 0 - * \return number of consumed characters - * - * Please note that 'base' and 's_max_len' are not evaluated by all - * template specializations. - */ - template - inline size_t ascii_to(const char *s, T *result, unsigned base = 0); - - /** * Read unsigned long value from string */ - template <> - inline size_t ascii_to(const char *s, unsigned long *result, - unsigned base) + inline size_t ascii_to(const char *s, unsigned long *result, unsigned base = 0) { unsigned long i = 0, value = 0; @@ -320,12 +302,10 @@ namespace Genode { /** * Read unsigned int value from string */ - template <> - inline size_t ascii_to(const char *s, unsigned int *result, - unsigned base) + inline size_t ascii_to(const char *s, unsigned int *result, unsigned base = 10) { unsigned long result_long = 0; - size_t ret = ascii_to(s, &result_long, base); + size_t ret = ascii_to(s, &result_long, base); *result = result_long; return ret; } @@ -334,8 +314,7 @@ namespace Genode { /** * Read signed long value from string */ - template <> - inline size_t ascii_to(const char *s, long *result, unsigned base) + inline size_t ascii_to(const char *s, long *result, unsigned base = 10) { int i = 0; @@ -362,8 +341,7 @@ namespace Genode { * This function scales the resulting size value according to the suffixes * for G (2^30), M (2^20), and K (2^10) if present. */ - template <> - inline size_t ascii_to(const char *s, Number_of_bytes *result, unsigned) + inline size_t ascii_to(const char *s, Number_of_bytes *result, unsigned base = 0) { unsigned long res = 0; @@ -387,8 +365,7 @@ namespace Genode { /** * Read double float value from string */ - template <> - inline size_t ascii_to(const char *s, double *result, unsigned) + inline size_t ascii_to(const char *s, double *result, unsigned base = 0) { double v = 0.0; /* decimal part */ double d = 0.1; /* power of fractional digit */ diff --git a/repos/os/include/util/color.h b/repos/os/include/util/color.h index 153e69b79..18a1c0afd 100644 --- a/repos/os/include/util/color.h +++ b/repos/os/include/util/color.h @@ -19,8 +19,7 @@ namespace Genode { struct Color; - template <> - inline size_t ascii_to(const char *, Color *, unsigned); + inline size_t ascii_to(const char *, Color *, unsigned base = 0); } @@ -46,9 +45,7 @@ struct Genode::Color * \return number of consumed characters, or 0 if the string contains * no valid color */ -template <> -inline Genode::size_t -Genode::ascii_to(const char *s, Genode::Color *result, unsigned) +inline Genode::size_t Genode::ascii_to(const char *s, Genode::Color *result, unsigned) { /* validate string */ if (strlen(s) < 7 || *s != '#') return 0;