16 if (str[0] ==
'{' && str[str.size () - 1] ==
'}')
return Vector_QVdt;
19 if(str ==
"false" || str ==
"true" ||
20 str ==
"FALSE" || str ==
"TRUE"||
21 str ==
"f" || str ==
"t")
return Int_QVdt;
24 char *error_ptr1 = 0,*error_ptr2 = 0;
25 ::strtod (str.c_str (), &error_ptr1);
30 ::strtol (str.c_str (), &error_ptr1, 10);
31 ::strtol (str.c_str (), &error_ptr2, 16);
32 if (error_ptr1 && *error_ptr1 && error_ptr2 && *error_ptr2)
return Double_QVdt;
43 char *error_ptr = NULL;
51 value_f = ::strtod (str.c_str (), &error_ptr);
53 std::string msg = std::string(
"float conversion failed for ") + str;
54 if (
value_f == 0 && error_ptr && *error_ptr) {
56 err.SetDescription(msg);
62 if(str ==
"true" || str ==
"TRUE" || str ==
"t")
value_i = 1;
63 else if(str ==
"false" || str ==
"FALSE" || str ==
"f")
value_i = 0;
64 else if(strncmp(
"0x", &(str.c_str()[str.find_first_not_of(
" \t")]), 2) == 0)
65 value_i = ::strtol (str.c_str (), &error_ptr, 16);
66 else value_i = ::strtol (str.c_str (), &error_ptr, 10);
67 if (
value_i == 0 && error_ptr && *error_ptr) {
68 std::string msg = std::string(
"integer conversion failed for ") + str;
70 err.SetDescription(msg);
78 if(str.size() > 1 && str[1] ==
'{')
79 sub_str = str.substr (2, str.size () - 4);
81 sub_str = str.substr (1, str.size () - 2);
82 std::string::size_type colon = 0;
83 while (sub_str.size ()) {
84 colon = sub_str.find (
',', 0);
86 if (colon == std::string::npos) colon = sub_str.size ();
88 std::string::size_type start_field = 0;
89 for (; start_field < colon; start_field++)
if (!isspace (sub_str[start_field]))
break;
90 std::string::size_type end_field = colon - 1;
91 for (; end_field > start_field; end_field--)
if (!isspace (sub_str[end_field]))
break;
93 std::string value = sub_str.substr (start_field, end_field - start_field + 1);
95 if (!value.size ())
break;
99 sub_str.erase (0, colon + 1);
105 "internal QVdt error: cannot call AssignValue with an "
106 "undefined type value: \"" + str +
"\"");
128 QVdt_vector::const_iterator viter =
value_v.begin();
129 while(viter !=
value_v.end()) {
130 s<<viter->GetString()<<
",";
141 err.SetDescription(
"internal QVdt error: cannot convert to string with an undefined type value");
245 std::stringstream msg;
247 msg <<
"requested " << char(new_type) <<
" while current type is " << char(
type_internal) <<
" (" << *
this <<
"); cast not allowed";
248 err.SetDescription(msg.str());
267 std::copy (v.
GetVector ().begin (), v.
GetVector ().end () - 1, std::ostream_iterator<QVdt>(out,
", "));
268 out << *(v.
GetVector ().end () - 1) <<
" ";
273 out <<
"unknown type (" << v.
GetName() <<
")";
278 template <>
int QVdt::Get<int>()
const
283 template <>
double QVdt::Get<double>()
const
288 template <>
bool QVdt::Get<bool>()
const
293 template <> std::string QVdt::Get<std::string>()
const
std::ostream & operator<<(std::ostream &out, const QVdt &v)
error class with error type and description
void CheckType(QVdt_type new_type) const
void AssignValue(const std::string &str)
const QVdt & operator=(const std::string &value)
std::string ToString() const
std::vector< QVdt > QVdt_vector
const std::string & GetString() const
std::string GetName() const
const QVdt_vector & GetVector() const
QVdt_type GetType() const
QVdt_type SearchType(const std::string &str)