12 #ifndef ECL_CONVERTERS_TO_BYTE_ARRAY_HPP_ 13 #define ECL_CONVERTERS_TO_BYTE_ARRAY_HPP_ 55 template<
typename ByteArray,
typename Integral>
56 class IntegralToByteArray :
public ConverterBase
91 std::cout <<
"Failed size check" << std::endl;
93 StandardException(LOC,
ConversionError,
"The specified byte array size does not match the byte size of the integral type."));
101 for (
unsigned int i = 0; i < ecl::numeric_limits<Integral>::bytes; ++i)
103 byte_array[i] =
static_cast<typename ByteArray::value_type
>(input >> 8 * i);
112 virtual ~IntegralToByteArray() {}
127 class Converter<std::vector<char>, int> :
public converters::IntegralToByteArray<std::vector<char>, int>
135 class Converter<std::vector<unsigned char>, int> :
public converters::IntegralToByteArray<std::vector<unsigned char>,
144 class Converter<std::vector<signed char>, int> :
public converters::IntegralToByteArray<std::vector<signed char>, int>
152 class Converter<std::vector<char>, unsigned int> :
public converters::IntegralToByteArray<std::vector<char>,
161 class Converter<std::vector<unsigned char>, unsigned int> :
public converters::IntegralToByteArray<
162 std::vector<unsigned char>, unsigned int>
170 class Converter<std::vector<signed char>, unsigned int> :
public converters::IntegralToByteArray<
171 std::vector<signed char>, unsigned int>
179 class Converter<std::vector<char>, long> :
public converters::IntegralToByteArray<std::vector<char>, long>
187 class Converter<std::vector<unsigned char>, long> :
public converters::IntegralToByteArray<std::vector<unsigned char>,
196 class Converter<std::vector<signed char>, long> :
public converters::IntegralToByteArray<std::vector<signed char>, long>
204 class Converter<std::vector<char>, unsigned long> :
public converters::IntegralToByteArray<std::vector<char>,
213 class Converter<std::vector<unsigned char>, unsigned long> :
public converters::IntegralToByteArray<
214 std::vector<unsigned char>, unsigned long>
222 class Converter<std::vector<signed char>, unsigned long> :
public converters::IntegralToByteArray<
223 std::vector<signed char>, unsigned long>
231 class Converter<std::vector<char>, long long> :
public converters::IntegralToByteArray<std::vector<char>, long long>
239 class Converter<std::vector<unsigned char>, long long> :
public converters::IntegralToByteArray<std::vector<unsigned char>,
248 class Converter<std::vector<signed char>, long long> :
public converters::IntegralToByteArray<std::vector<signed char>, long long>
263 class Converter<std::vector<char>, char*> :
public converters::ConverterBase
286 std::vector<char> bytes;
287 state = waiting_zero;
289 while (*input !=
'\0')
299 else if (*input ==
' ')
316 state = waiting_first_digit;
327 case (waiting_first_digit):
329 if ((*input >=
'0') && (*input <=
'9'))
331 byte = (*input -
'0') << 4;
332 state = waiting_second_digit;
334 else if ((*input >=
'a') && (*input <=
'f'))
336 byte = ((*input -
'a') + 0x0A) << 4;
337 state = waiting_second_digit;
339 else if ((*input >=
'A') && (*input <=
'F'))
341 byte = ((*input -
'A') + 0x0A) << 4;
342 state = waiting_second_digit;
353 case (waiting_second_digit):
355 if ((*input >=
'0') && (*input <=
'9'))
357 byte += *input -
'0';
358 bytes.push_back(byte);
360 else if ((*input >=
'a') && (*input <=
'f'))
362 byte += (*input -
'a') + 0x0A;
363 bytes.push_back(byte);
365 else if ((*input >=
'A') && (*input <=
'F'))
367 byte += (*input -
'A') + 0x0A;
368 bytes.push_back(byte);
377 state = waiting_zero;
382 state = waiting_zero;
398 static const unsigned int waiting_zero = 0;
399 static const unsigned int waiting_x = 1;
400 static const unsigned int waiting_first_digit = 2;
401 static const unsigned int waiting_second_digit = 3;
412 std::vector<char>, int>,
414 std::vector<char>, long>,
415 public Converter<std::vector<char>, unsigned long>
433 class Converter<std::vector<unsigned char>, void> :
public Converter<std::vector<unsigned char>, int>,
434 public Converter<std::vector<unsigned char>, unsigned int>,
435 public Converter<std::vector<unsigned char>, long>,
436 public Converter<std::vector<unsigned char>, unsigned long>
454 public Converter<std::vector<signed char>, unsigned int>,
455 public Converter<std::vector<signed char>, long>,
456 public Converter<std::vector<signed char>, unsigned long>
#define ecl_compile_time_assert(logical_expression)
Primary templates for the family of converter classes.
std::vector< unsigned char > ByteArray
Primary template and general fallback for converter classes.
#define ecl_compile_time_concept_check(Model)
#define ecl_debug_throw_decl(exception)
#define ecl_debug_throw(exception)