22 #ifndef _BLAZE_UTIL_CONVERT_H_
23 #define _BLAZE_UTIL_CONVERT_H_
52 template<
typename To,
typename From,
int IsBase >
73 template<
typename To,
typename From >
74 struct CastConverter<To*,From*,0> :
private NonCreatable
80 static inline To*
convert( From* from );
95 template<
typename To,
typename From >
98 return dynamic_cast<To*
>( from );
117 template<
typename To,
typename From >
118 struct CastConverter<To*,From*,1> :
private NonCreatable
124 static inline To*
convert( From* from );
139 template<
typename To,
typename From >
142 return static_cast<To*
>( from );
161 template<
typename To,
typename From >
162 struct Converter :
private NonCreatable
168 static inline To
convert(
const From& from );
183 template<
typename To,
typename From >
186 return static_cast<To
>( from );
205 template<
typename To,
typename From >
206 struct Converter<To*,From*> :
private NonCreatable
212 static inline To*
convert( From* from );
227 template<
typename To,
typename From >
230 return CastConverter<To*,From*,blaze::IsBaseOf<To,From>::yes>
::convert( from );
249 template<
typename To >
250 struct Converter<To,std::string> :
private NonCreatable
256 static inline To
convert(
const std::string& from );
271 template<
typename To >
275 std::istringstream iss( from );
277 std::ostringstream
error;
278 error <<
"Invalid cast from std::string to " <<
typeid(to).name() <<
"\n";
279 throw std::runtime_error( error.str() );
300 template<
typename From >
301 struct Converter<std::string,From> :
private NonCreatable
307 static inline std::string
convert(
const From& from );
322 template<
typename From >
325 std::ostringstream oss;
326 if( !(oss << from) ) {
327 std::ostringstream
error;
328 error <<
"Invalid cast from " <<
typeid(from).name() <<
" to std::string\n";
329 throw std::runtime_error( error.str() );
353 struct Converter<std::string,std::string> :
private NonCreatable
359 static inline std::string
convert(
const std::string& from );
404 template<
typename To,
typename From >
420 inline int convert<int,std::string>(
const std::string& from )
422 return std::atoi( from.c_str() );
436 inline unsigned int convert<unsigned int,std::string>(
const std::string& from )
438 return static_cast<unsigned int>( std::atoi( from.c_str() ) );
452 inline float convert<float,std::string>(
const std::string& from )
454 return static_cast<float>( std::atof( from.c_str() ) );
468 inline double convert<double,std::string>(
const std::string& from )
470 return std::atof( from.c_str() );
485 template<
typename To >
486 inline To
convert(
const char*
const from )
502 inline int convert<int>(
const char*
const from )
504 return std::atoi( from );
518 inline unsigned int convert<unsigned int>(
const char*
const from )
520 return static_cast<unsigned int>( std::atof( from ) );
534 inline float convert<float>(
const char*
const from )
536 return static_cast<float>( std::atof( from ) );
550 inline double convert<double>(
const char*
const from )
552 return std::atof( from );
567 template<
typename To >
568 inline To
convert(
char*
const from )
584 inline int convert<int>(
char*
const from )
586 return std::atoi( from );
600 inline unsigned int convert<unsigned int>(
char*
const from )
602 return static_cast<unsigned int>( std::atoi( from ) );
616 inline float convert<float>(
char*
const from )
618 return static_cast<float>( std::atof( from ) );
632 inline double convert<double>(
char*
const from )
634 return std::atof( from );