This commit is contained in:
niczkx
2012-07-18 00:03:46 +02:00
parent 02f89dd8be
commit 28825a3298
9 changed files with 62 additions and 68 deletions

View File

@@ -120,7 +120,6 @@ R unsafe_cast(const T& t, R def) {
return def;
}
}
}
#endif

View File

@@ -214,10 +214,20 @@ inline std::string utf8StringToLatin1(uchar *utf8) {
}
// Convert string to lower case
inline std::string tolower(std::string& str) { return boost::algorithm::to_lower_copy(str); }
inline std::string tolower(const std::string& str)
{
std::string _str = str;
boost::algorithm::to_lower(_str);
return _str;
}
// Convert string to upper case
inline std::string toupper(std::string& str) { return boost::algorithm::to_upper_copy(str); }
inline std::string toupper(const std::string& str)
{
std::string _str = str;
boost::algorithm::to_upper(_str);
return _str;
}
// utility for printing messages into stdout
template<class... T>

View File

@@ -596,16 +596,10 @@ const std::string* TiXmlElement::Attribute( const std::string& name ) const
const char* TiXmlElement::Attribute( const char* name, int* i ) const
{
const TiXmlAttribute* attrib = attributeSet.Find( name );
const char* result = 0;
if ( attrib ) {
result = attrib->Value();
if ( i ) {
attrib->QueryIntValue( i );
}
}
return result;
int p = readType<int>(name);
if(i)
*i = p;
return Attribute(name);
}
@@ -625,19 +619,12 @@ const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) co
}
#endif
const char* TiXmlElement::Attribute( const char* name, double* d ) const
const char* TiXmlElement::Attribute(const char *name, double *d) const
{
const TiXmlAttribute* attrib = attributeSet.Find( name );
const char* result = 0;
if ( attrib ) {
result = attrib->Value();
if ( d ) {
attrib->QueryDoubleValue( d );
}
}
return result;
double p = readType<double>(name);
if(d)
*d = p;
return Attribute(name);
}

View File

@@ -40,6 +40,10 @@ distribution.
#include <string.h>
#include <assert.h>
#include <framework/global.h>
#include <otclient/position.h>
#include <framework/stdext/cast.h>
// Help out windows:
#if defined( _DEBUG ) && !defined( DEBUG )
#define DEBUG
@@ -200,6 +204,9 @@ class TiXmlBase
friend class TiXmlDocument;
public:
TiXmlBase( const TiXmlBase& ) = delete;
void operator=( const TiXmlBase& base ) = delete;
TiXmlBase() : userData(0) {}
virtual ~TiXmlBase() {}
@@ -396,9 +403,6 @@ protected:
static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
private:
TiXmlBase( const TiXmlBase& ); // not implemented.
void operator=( const TiXmlBase& base ); // not allowed.
struct Entity
{
const char* str;
@@ -428,6 +432,9 @@ class TiXmlNode : public TiXmlBase
friend class TiXmlElement;
public:
TiXmlNode( const TiXmlNode& ) = delete;
void operator=( const TiXmlNode& base ) = delete;
#ifdef TIXML_USE_STL
/** An input stream operator, for every class. Tolerant of newlines and
@@ -764,10 +771,6 @@ protected:
TiXmlNode* prev;
TiXmlNode* next;
private:
TiXmlNode( const TiXmlNode& ); // not implemented.
void operator=( const TiXmlNode& base ); // not allowed.
};
@@ -977,6 +980,18 @@ public:
*/
const char* Attribute( const char* name, double* d ) const;
template<typename T = std::string>
inline T readType(const std::string& str) const { return stdext::unsafe_cast<T>(Attribute(str)); }
Position readPos(const std::string& base = std::string()) const
{
return Position(readType<uint16>(base + "x"), readType<uint16>(base + "y"), readType<uint8>(base + "z"));
}
Point readPoint() const
{
return Point(readType<int>("x"), readType<int>("y"));
}
/** QueryIntAttribute examines the attribute - it is an alternative to the
Attribute() method with richer error checking.
If the attribute is an integer, it is stored in 'value' and