string.hpp
Go to the documentation of this file.
00001 
00016 /*****************************************************************************
00017 ** Ifdefs
00018 *****************************************************************************/
00019 
00020 #ifndef ECL_CONVERTERS_STRINGS_HPP_
00021 #define ECL_CONVERTERS_STRINGS_HPP_
00022 
00023 /*****************************************************************************
00024 ** Includes
00025 *****************************************************************************/
00026 
00027 #include <string>
00028 #include "converter.hpp"
00029 #include "char.hpp"
00030 
00031 /*****************************************************************************
00032 ** Namespaces
00033 *****************************************************************************/
00034 
00035 namespace ecl {
00036 
00037 /*****************************************************************************
00038 ** String Converter Interface
00039 *****************************************************************************/
00050 template <>
00051 class Converter<std::string,int> : public converters::ConverterBase {
00052 public:
00063         std::string operator ()(const int &input)
00064         {
00065                 std::string s;
00066                 bool negative = false;
00067                 char *char_string;
00068                 #if ECL_SIZE_OF_INT == 4
00069                         char_string = buffer + 11;
00070                 #elif ECL_SIZE_OF_INT == 8
00071                         char_string = buffer + 20;
00072                 #else // just make sure we have lots of space
00073                         char_string = buffer + 30;
00074                 #endif
00075                 *char_string = '\0';
00076                 int remaining = input;
00077                 unsigned int lsd;
00078                 /*********************
00079                 ** Fix sign
00080                 **********************/
00081                 if (remaining < 0 ) {
00082                         negative = true;
00083                         remaining *= -1;
00084                 }
00085                 do
00086                 {
00087                         --char_string;
00088                         lsd = remaining%10;
00089                         remaining /= 10;
00090                         *char_string = Converter<char,unsigned int>()(lsd);
00091                 } while ( remaining > 0);
00092                 if ( negative ) {
00093                         --char_string;
00094                         *char_string = '-';
00095                 }
00096                 return s.assign(char_string);
00097         };
00098 
00099     virtual ~Converter() {}
00100 
00101 private:
00102         #if ECL_SIZE_OF_INT == 4
00103                 char buffer[12];
00104         #elif ECL_SIZE_OF_INT == 8
00105                 char buffer[21];
00106         #else // just make sure we have lots of space
00107                 char buffer[31];
00108 #endif
00109 };
00110 
00120 template <>
00121 class Converter<std::string,void>  :
00122         public Converter<std::string,int>
00123 {
00124 public:
00125     virtual ~Converter() {}
00126 
00127         using Converter<std::string,int>::operator();
00128 };
00129 
00130 
00131 }; // Namespace ecl
00132 
00133 
00134 #endif /*ECL_CONVERTERS_STRINGS_HPP_*/


ecl_converters
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:28