35 #ifndef _BLAZE_UTIL_CONVERT_H_
36 #define _BLAZE_UTIL_CONVERT_H_
65 template<
typename To,
typename From,
int IsBase >
86 template<
typename To,
typename From >
87 struct CastConverter<To*,From*,0> :
private NonCreatable
93 static inline To*
convert( From* from );
108 template<
typename To,
typename From >
111 return dynamic_cast<To*
>( from );
130 template<
typename To,
typename From >
131 struct CastConverter<To*,From*,1> :
private NonCreatable
137 static inline To*
convert( From* from );
152 template<
typename To,
typename From >
155 return static_cast<To*
>( from );
174 template<
typename To,
typename From >
175 struct Converter :
private NonCreatable
181 static inline To
convert(
const From& from );
196 template<
typename To,
typename From >
199 return static_cast<To
>( from );
218 template<
typename To,
typename From >
219 struct Converter<To*,From*> :
private NonCreatable
225 static inline To*
convert( From* from );
240 template<
typename To,
typename From >
243 return CastConverter<To*,From*,blaze::IsBaseOf<To,From>::yes>
::convert( from );
262 template<
typename To >
263 struct Converter<To,
std::string> :
private NonCreatable
269 static inline To
convert(
const std::string& from );
284 template<
typename To >
288 std::istringstream iss( from );
290 std::ostringstream
error;
291 error <<
"Invalid cast from std::string to " <<
typeid(to).name() <<
"\n";
313 template<
typename From >
314 struct Converter<
std::string,From> :
private NonCreatable
320 static inline std::string
convert(
const From& from );
335 template<
typename From >
338 std::ostringstream oss;
339 if( !(oss << from) ) {
340 std::ostringstream
error;
341 error <<
"Invalid cast from " <<
typeid(from).name() <<
" to std::string\n";
366 struct Converter<
std::string,std::string> :
private NonCreatable
372 static inline std::string
convert(
const std::string& from );
417 template<
typename To,
typename From >
433 inline int convert<int,std::string>(
const std::string& from )
435 return std::atoi( from.c_str() );
449 inline unsigned int convert<unsigned int,std::string>(
const std::string& from )
451 return static_cast<unsigned int>( std::atoi( from.c_str() ) );
465 inline float convert<float,std::string>(
const std::string& from )
467 return static_cast<float>( std::atof( from.c_str() ) );
481 inline double convert<double,std::string>(
const std::string& from )
483 return std::atof( from.c_str() );
498 template<
typename To >
499 inline To
convert(
const char*
const from )
515 inline int convert<int>(
const char*
const from )
517 return std::atoi( from );
531 inline unsigned int convert<unsigned int>(
const char*
const from )
533 return static_cast<unsigned int>( std::atof( from ) );
547 inline float convert<float>(
const char*
const from )
549 return static_cast<float>( std::atof( from ) );
563 inline double convert<double>(
const char*
const from )
565 return std::atof( from );
580 template<
typename To >
581 inline To
convert(
char*
const from )
597 inline int convert<int>(
char*
const from )
599 return std::atoi( from );
613 inline unsigned int convert<unsigned int>(
char*
const from )
615 return static_cast<unsigned int>( std::atoi( from ) );
629 inline float convert<float>(
char*
const from )
631 return static_cast<float>( std::atof( from ) );
645 inline double convert<double>(
char*
const from )
647 return std::atof( from );
Log level for (sever) errors.
Definition: LogLevel.h:78
#define BLAZE_THROW_RUNTIME_ERROR(MESSAGE)
Macro for the emission of a std::runtime_error exceptionThis macro encapsulates the default way of Bl...
Definition: Exception.h:379
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Header file for the IsBaseOf type trait.
Header file for exception macros.
Base class for non-creatable (static) classes.
To convert(const From &from)
Conversion from type From to type To.
Definition: Convert.h:418