Update otml and casts

Improve casts performance
OTML can now understand value escaped sequences
Use long instead of int for lua integer
This commit is contained in:
Eduardo Bart
2012-07-23 01:33:08 -03:00
parent 253a22db3d
commit c9dce51458
6 changed files with 103 additions and 28 deletions

View File

@@ -150,7 +150,7 @@ bool OTMLNode::replaceChild(const OTMLNodePtr& oldChild, const OTMLNodePtr& newC
void OTMLNode::copy(const OTMLNodePtr& node)
{
setTag(node->tag());
setValue(node->value());
setValue(node->rawValue());
setUnique(node->isUnique());
setNull(node->isNull());
setSource(node->source());

View File

@@ -37,6 +37,7 @@ public:
int size() { return m_children.size(); }
OTMLNodePtr parent() { return m_parent.lock(); }
std::string source() { return m_source; }
std::string rawValue() { return m_value; }
bool isUnique() { return m_unique; }
bool isNull() { return m_null; }
@@ -104,11 +105,25 @@ protected:
#include "otmlexception.h"
template<>
inline std::string OTMLNode::value<std::string>() {
std::string value = m_value;
if(boost::starts_with(value, "\"") && boost::ends_with(value, "\"")) {
value = value.substr(1, value.length()-2);
boost::replace_all(value, "\\\\", "\\");
boost::replace_all(value, "\\\"", "\"");
boost::replace_all(value, "\\t", "\t");
boost::replace_all(value, "\\n", "\n");
boost::replace_all(value, "\\'", "\'");
}
return value;
}
template<typename T>
T OTMLNode::value() {
T ret;
if(!stdext::cast(m_value, ret))
throw OTMLException(shared_from_this(), stdext::mkstr("failed to cast node value to type '%s'", stdext::demangle_type<T>()));
throw OTMLException(shared_from_this(), stdext::format("failed to cast node value '%s' to type '%s'", m_value, stdext::demangle_type<T>()));
return ret;
}