Browse Source

Use ToString for printing and dumping ObjectSimple classes.

ObjPtr
Michael Uleysky 9 years ago
parent
commit
c3c6f4643d
  1. 29
      include/common.h

29
include/common.h

@ -19,6 +19,19 @@ EXPORT std::ostream& COUT(debug_level dl);
typedef std::set<std::string> UsedType;
// We use different format for conversion of double to string
template<class T>
inline std::string ToString(T n) { return std::to_string(n); }
template<>
inline std::string ToString<double>(double n)
{
char buffer[32];
int i;
i=snprintf(buffer,32,"%.*G",DBL_DIG,n);
return std::string(buffer,i);
}
template<>
inline std::string ToString<std::string>(std::string s) {return s;}
// Base class for all objects
class EXPORT ObjectBase
@ -159,7 +172,7 @@ public:
bool Print() const override
{
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl;
COUT(NORMAL)<<"Value: "<<val<<std::endl;
COUT(NORMAL)<<"Value: "<<ToString(val)<<std::endl;
return true;
}
std::string Type() const override {return type;}
@ -171,7 +184,7 @@ public:
if(std::type_index(typeid(T))==std::type_index(typeid(std::string)))
s<<"\""<<val<<"\"";
else
s<<val;
s<<ToString(val);
return s.str();
}
@ -414,16 +427,4 @@ inline WordList Split(const char* str, const std::string& delims) {return Split(
inline WordList Split(const std::string& str, const char* delims) {return Split(str,std::string(delims),false);}
inline WordList Split(const char* str, const char* delims) {return Split(std::string(str),std::string(delims),false);}
// We use different format for conversion of double to string
template<class T>
inline std::string ToString(T n) { return std::to_string(n); }
template<>
inline std::string ToString<double>(double n)
{
char buffer[32];
int i;
i=snprintf(buffer,32,"%.*G",DBL_DIG,n);
return std::string(buffer,i);
}
#endif

Loading…
Cancel
Save