diff options
author | Patrick Williams <iawillia@us.ibm.com> | 2013-09-23 14:55:10 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2013-10-07 10:02:28 -0500 |
commit | b8d7070d329b3a6577ae6c11ae7b1afb27db7a22 (patch) | |
tree | 0e93546356b039af78869b5edc86d8d4d1ff08a9 /src/include/util | |
parent | 4dc8e90ef55cb15b6a36a8d27ae43a6b2261521b (diff) | |
download | talos-hostboot-b8d7070d329b3a6577ae6c11ae7b1afb27db7a22.tar.gz talos-hostboot-b8d7070d329b3a6577ae6c11ae7b1afb27db7a22.zip |
Make sprintf-class functions comply with standard.
Change-Id: I6a04179bb2c339668450bcbcf608ebef477c5bfe
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/6399
Tested-by: Jenkins Server
Reviewed-by: Brian H. Horton <brianh@linux.ibm.com>
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/util')
-rw-r--r-- | src/include/util/functor.H | 122 | ||||
-rw-r--r-- | src/include/util/sprintf.H | 326 |
2 files changed, 6 insertions, 442 deletions
diff --git a/src/include/util/functor.H b/src/include/util/functor.H deleted file mode 100644 index b5bf1f9de..000000000 --- a/src/include/util/functor.H +++ /dev/null @@ -1,122 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/include/util/functor.H $ */ -/* */ -/* IBM CONFIDENTIAL */ -/* */ -/* COPYRIGHT International Business Machines Corp. 2011,2013 */ -/* */ -/* p1 */ -/* */ -/* Object Code Only (OCO) source materials */ -/* Licensed Internal Code Source Materials */ -/* IBM HostBoot Licensed Internal Code */ -/* */ -/* The source code for this program is not published or otherwise */ -/* divested of its trade secrets, irrespective of what has been */ -/* deposited with the U.S. Copyright Office. */ -/* */ -/* Origin: 30 */ -/* */ -/* IBM_PROLOG_END_TAG */ -#ifndef __UTIL_FUNCTOR_H -#define __UTIL_FUNCTOR_H - -#include <builtins.h> - -namespace Util -{ - template <typename _ARG, typename _RESULT> - class unary_functor - { - public: - typedef _ARG argument_type; - typedef _RESULT result_type; - - public: - virtual ~unary_functor() {}; - virtual result_type operator()(argument_type) = 0; - }; - - template <typename _ARG1, typename _ARG2, typename _RESULT> - class binary_functor - { - public: - typedef _ARG1 first_argument_type; - typedef _ARG2 second_argument_type; - typedef _RESULT result_type; - - public: - virtual ~binary_functor() {}; - virtual result_type operator() - (first_argument_type, second_argument_type) = 0; - }; - - // Function pointer wrappers for functors. - - template <typename _ARG, typename _RESULT> - class ptr_to_unary_function : public unary_functor<_ARG, _RESULT> - { - public: - typedef _RESULT(*function_type)(_ARG); - - private: - function_type function; - - public: - ptr_to_unary_function(function_type f) : function(f) {}; - - - _RESULT operator()(_ARG t) - { - return function(t); - } - }; - - template <typename _ARG, typename _RESULT> - ALWAYS_INLINE inline - ptr_to_unary_function<_ARG, _RESULT> ptr_fun(_RESULT (*f)(_ARG)) - { - return ptr_to_unary_function<_ARG,_RESULT>(f); - } - -#define PTR_FUN1_T(ARG_T, RESULT_T) \ - ptr_to_unary_function<_ARG, _RESULT> - - - template <typename _ARG, typename _RESULT, typename _CLASS> - class mem_ptr_to_unary_function : public unary_functor<_ARG, _RESULT> - { - public: - typedef _CLASS member_type; - typedef _RESULT(member_type::*function_type)(_ARG); - - private: - member_type& object; - function_type function; - - public: - mem_ptr_to_unary_function(member_type& o, function_type f) - : object(o), function(f) {}; - - _RESULT operator()(_ARG t) - { - return (object.*function)(t); - } - }; - - template <typename _ARG, typename _RESULT, typename _CLASS> - ALWAYS_INLINE inline - mem_ptr_to_unary_function<_ARG, _RESULT, _CLASS> - mem_ptr_fun(_CLASS& o, _RESULT (_CLASS::*f)(_ARG)) - { - return mem_ptr_to_unary_function<_ARG,_RESULT,_CLASS>(o, f); - } - -#define MEM_PTR_FUN1_T(CLASS_T, ARG_T, RESULT_T) \ - mem_ptr_to_unary_function<ARG_T, RESULT_T, CLASS_T> - -}; - -#endif diff --git a/src/include/util/sprintf.H b/src/include/util/sprintf.H index 1385e9b17..f03ea6228 100644 --- a/src/include/util/sprintf.H +++ b/src/include/util/sprintf.H @@ -25,332 +25,18 @@ #include <stdarg.h> #include <stdint.h> -#include <builtins.h> - -class Console; namespace Util { - - class ConsoleTraits + class ConsoleBufferInterface { - public: - enum trait { NONE, HEX, DEC, }; + public: + virtual ~ConsoleBufferInterface() {}; + virtual size_t operator() (int) = 0; }; - template <typename _T, ConsoleTraits::trait _S = ConsoleTraits::NONE> - class ConsoleDisplay - { - public: - template <typename _F> - ALWAYS_INLINE - static size_t display(_F& c, _T value) { return 0; }; - }; - - template <ConsoleTraits::trait _S> - class ConsoleDisplay<char*, _S> - { - public: - template <typename _F> - ALWAYS_INLINE - static size_t display(_F& c, char* value) - { - size_t count = 0; - while(*value != '\0') - { - c(*value); - value++; - count++; - } - return count; - } - }; - - template <> - class ConsoleDisplay<char, ConsoleTraits::NONE> - { - public: - template <typename _F> - ALWAYS_INLINE - static size_t display(_F& c, char value) - { - c(value); - return 1; - } - }; - - template <typename _T> - class ConsoleDisplay<_T, ConsoleTraits::DEC> - { - public: - template <typename _F> - ALWAYS_INLINE - static size_t display(_F& c, _T value) - { - size_t count = 0; - if (value == 0) - { - c('0'); count++; - } - else if (value < 0) - { - c('-'); count++; - value *= -1; - count += subdisplay(c, value); - } - else - count += subdisplay(c, value); - return count; - } - - template <typename _F> - static size_t subdisplay(_F& c, _T value) - { - size_t count = 0; - if (value != 0) - { - count += subdisplay(c, value / 10); - c('0' + (value % 10)); - count++; - } - return count; - } - }; - - template<typename _T> - class ConsoleDisplay<_T, ConsoleTraits::HEX> - { - public: - template <typename _F> - ALWAYS_INLINE - static size_t display(_F& c, _T value) - { - size_t count = 0; - if (value == 0) - { - c('0'); count++; - } - else - { - count += subdisplay(c, value); - } - return count; - } - - template <typename _F> - static size_t subdisplay(_F& c, _T value) - { - size_t count = 0; - if (value != 0) - { - count += subdisplay(c, value / 16); - char nibble = value % 16; - if (nibble >= 0x0a) - c('A' + (nibble - 0x0a)); - else - c('0' + nibble); - count++; - } - return count; - } - }; - - template<typename _F> - size_t vasprintf(_F output_func, const char* fmt_str, va_list& args) - { - size_t count = 0; - - bool format = false; - int size = 0; - - while('\0' != *fmt_str) - { - if (('%' == *fmt_str) || (format)) - switch (*fmt_str) - { - case '%': - { - if (format) - { - count += - ConsoleDisplay<char>::display(output_func, - '%'); - format = false; - } - else - { - format = true; - size = 2; - } - break; - } - case 'c': - { - format = false; - count += ConsoleDisplay<char> - ::display(output_func, (char)va_arg(args,int)); - break; - } - case 'h': - { - size--; - break; - } - case 'l': - { - size++; - break; - } - case 'z': // size_t or ssize_t - { - size = 4; - break; - } - case 'd': // decimal - { - format = false; - switch(size) - { - case 0: - count += ConsoleDisplay<char, - ConsoleTraits::DEC> - ::display(output_func, - (char)va_arg(args,int)); - break; - - case 1: - count += ConsoleDisplay<short, - ConsoleTraits::DEC> - ::display(output_func, - (short)va_arg(args,int)); - break; - - case 2: - count += ConsoleDisplay<int, - ConsoleTraits::DEC> - ::display(output_func, - va_arg(args,int)); - break; - - case 3: - case 4: - count += ConsoleDisplay<long, - ConsoleTraits::DEC> - ::display(output_func, - va_arg(args,long)); - break; - } - break; - } - case 'u': // unsigned decimal - { - format = false; - switch(size) - { - case 0: - count += ConsoleDisplay<unsigned char, - ConsoleTraits::DEC> - ::display(output_func, - (unsigned char) - va_arg(args,unsigned int)); - break; - - case 1: - count += ConsoleDisplay<unsigned short, - ConsoleTraits::DEC> - ::display(output_func, - (unsigned short) - va_arg(args,unsigned int)); - break; - - case 2: - count += ConsoleDisplay<unsigned int, - ConsoleTraits::DEC> - ::display(output_func, - va_arg(args,unsigned int)); - break; - - case 3: - case 4: - count += ConsoleDisplay<unsigned long, - ConsoleTraits::DEC> - ::display(output_func, - va_arg(args,unsigned long)); - break; - } - break; - } - case 'x': // unsigned hex - case 'X': - { - format = false; - switch(size) - { - case 0: - count += ConsoleDisplay<unsigned char, - ConsoleTraits::HEX> - ::display(output_func, - (unsigned char) - va_arg(args,unsigned int)); - break; - - case 1: - count += ConsoleDisplay<unsigned short, - ConsoleTraits::HEX> - ::display(output_func, - (unsigned short) - va_arg(args,unsigned int)); - break; - - case 2: - count += ConsoleDisplay<unsigned int, - ConsoleTraits::HEX> - ::display(output_func, - va_arg(args,unsigned int)); - break; - - case 3: - case 4: - count += ConsoleDisplay<unsigned long, - ConsoleTraits::HEX> - ::display(output_func, - va_arg(args,unsigned long)); - break; - } - break; - } - case 's': // string - { - format = false; - count += ConsoleDisplay<char*> - ::display(output_func, - (char*) va_arg(args,void*)); - break; - } - case 'p': // pointer - { - format = false; - count += ConsoleDisplay<char> - ::display(output_func, - '0'); - count += ConsoleDisplay<char> - ::display(output_func, - 'x'); - count += ConsoleDisplay<unsigned long, - ConsoleTraits::HEX> - ::display(output_func, - va_arg(args,unsigned long)); - break; - } - } - else - count += ConsoleDisplay<char>::display(output_func, *fmt_str); - - fmt_str++; - } - - return count; - } + size_t vasprintf(ConsoleBufferInterface& output_func, + const char* fmt_str, va_list& args); }; |