string.hpp
Go to the documentation of this file.
1 
16 /*****************************************************************************
17 ** Ifdefs
18 *****************************************************************************/
19 
20 #ifndef ECL_CONVERTERS_STRINGS_HPP_
21 #define ECL_CONVERTERS_STRINGS_HPP_
22 
23 /*****************************************************************************
24 ** Includes
25 *****************************************************************************/
26 
27 #include <string>
28 #include "converter.hpp"
29 #include "char.hpp"
30 
31 /*****************************************************************************
32 ** Namespaces
33 *****************************************************************************/
34 
35 namespace ecl {
36 
37 /*****************************************************************************
38 ** String Converter Interface
39 *****************************************************************************/
50 template <>
51 class Converter<std::string,int> : public converters::ConverterBase {
52 public:
63  std::string operator ()(const int &input)
64  {
65  std::string s;
66  bool negative = false;
67  char *char_string;
68  #if ECL_SIZE_OF_INT == 4
69  char_string = buffer + 11;
70  #elif ECL_SIZE_OF_INT == 8
71  char_string = buffer + 20;
72  #else // just make sure we have lots of space
73  char_string = buffer + 30;
74  #endif
75  *char_string = '\0';
76  int remaining = input;
77  unsigned int lsd;
78  /*********************
79  ** Fix sign
80  **********************/
81  if (remaining < 0 ) {
82  negative = true;
83  remaining *= -1;
84  }
85  do
86  {
87  --char_string;
88  lsd = remaining%10;
89  remaining /= 10;
90  *char_string = Converter<char,unsigned int>()(lsd);
91  } while ( remaining > 0);
92  if ( negative ) {
93  --char_string;
94  *char_string = '-';
95  }
96  return s.assign(char_string);
97  };
98 
99  virtual ~Converter() {}
100 
101 private:
102  #if ECL_SIZE_OF_INT == 4
103  char buffer[12];
104  #elif ECL_SIZE_OF_INT == 8
105  char buffer[21];
106  #else // just make sure we have lots of space
107  char buffer[31];
108 #endif
109 };
110 
120 template <>
121 class Converter<std::string,void> :
122  public Converter<std::string,int>
123 {
124 public:
125  virtual ~Converter() {}
126 
128 };
129 
130 
131 }; // Namespace ecl
132 
133 
134 #endif /*ECL_CONVERTERS_STRINGS_HPP_*/
ecl::Converter< char, unsigned int >
Converts unsigned ints into readable (ascii) characters.
Definition: char.hpp:47
ecl::Converter::operator()
Output operator()(const Input &input)
Definition: converter.hpp:97
converter.hpp
Primary templates for the family of converter classes.
ecl::Converter::~Converter
virtual ~Converter()
Definition: converter.hpp:72
char.hpp
Type conversions to a readable (ascii) char type.
ecl
ecl::Converter
Primary template and general fallback for converter classes.
Definition: converter.hpp:62


ecl_converters
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:25