char.hpp
Go to the documentation of this file.
1 
12 /*****************************************************************************
13 ** Ifdefs
14 *****************************************************************************/
15 
16 #ifndef ECL_CONVERTERS_CHAR_HPP_
17 #define ECL_CONVERTERS_CHAR_HPP_
18 
19 /*****************************************************************************
20 ** Includes
21 *****************************************************************************/
22 
23 #include "converter.hpp"
24 #include <ecl/exceptions/standard_exception.hpp>
25 
26 /*****************************************************************************
27 ** Namespaces
28 *****************************************************************************/
29 
30 namespace ecl {
31 
32 /*****************************************************************************
33 ** Character Converter Interface
34 *****************************************************************************/
40 template <>
41 class Converter<char,unsigned int> : public converters::ConverterBase {
42 public:
43  virtual ~Converter() {}
44 
57  char operator()(const unsigned int &input) ecl_debug_throw_decl(StandardException) {
58  if ( input > 9 ) {
59  ecl_debug_throw(StandardException(LOC,ConversionError));
60  error_handler = ConversionError;
61  }
62  return ('0'+ input%10); // Copy the char back.
63  }
64 };
70 template <>
71 class Converter<char,int> : public converters::ConverterBase {
72 public:
73  virtual ~Converter() {}
74 
87  char operator()(const int &input) ecl_debug_throw_decl(StandardException) {
88  if ( ( input < 0 ) || (input > 9) ) {
89  ecl_debug_throw(StandardException(LOC,OutOfRangeError));
90  error_handler = OutOfRangeError;
91  }
92  return ('0'+ input%10); // Copy the char back.
93  }
94 };
95 
96 /*****************************************************************************
97  * Char Converter Family
98  ****************************************************************************/
107 template <>
108 class Converter<char,void> :
109  public Converter<char,int>,
110  public Converter<char,unsigned int>
111 {
112  public:
113  virtual ~Converter() {}
114 
115  using Converter<char,int>::operator();
116  using Converter<char,unsigned int>::operator();
117 };
118 
119 }; // Namespace ecl
120 
121 
122 #endif /*ECL_CONVERTERS_CHAR_HPP_*/
virtual ~Converter()
#define LOC
Stringify the line of code you are at.
ConversionError
OutOfRangeError
Output operator()(const Input &input)
Definition: converter.hpp:91
#define ecl_debug_throw_decl(exception)
Debug mode throw exception declaration.
#define ecl_debug_throw(exception)
Debug mode exception throw.


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13