27 lines
595 B
C++
27 lines
595 B
C++
#ifndef FROM_STRING_H_
|
|
#define FROM_STRING_H_
|
|
#include <cassert>
|
|
#include <core/variant.h>
|
|
#include <core/variant_parser.h>
|
|
|
|
template <class T> static inline T from_string(const String &s)
|
|
{
|
|
T ret;
|
|
VariantParser::StreamString ss;
|
|
ss.s = s;
|
|
String errs;
|
|
int line;
|
|
Variant o;
|
|
Error err = VariantParser::parse(&ss, o, errs, line);
|
|
ERR_FAIL_COND_V_MSG(err != OK, T(),
|
|
"Parse error at line " + itos(line) + ": " + errs);
|
|
ret = o;
|
|
return ret;
|
|
}
|
|
template <class T> static inline String to_string(const T &v)
|
|
{
|
|
String tmp;
|
|
VariantWriter::write_to_string(v, tmp);
|
|
return tmp;
|
|
}
|
|
#endif |