diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index 357fd8197c..af9272d8e5 100755 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -180,7 +180,7 @@ bool CObjectEntry::Load(const char* filename) XMBElement child = children.item(i); int element_name = child.getNodeName(); - CStr element_value=tocstr(child.getText()); + CStr element_value (child.getText()); if (element_name == el_name) m_Name=element_value; @@ -201,9 +201,9 @@ bool CObjectEntry::Load(const char* filename) if (attributes.Count) { Anim anim; - anim.m_AnimName=tocstr(attributes.getNamedItem(at_name)); - anim.m_FileName=tocstr(attributes.getNamedItem(at_file)); - CStr16 speedstr=attributes.getNamedItem(at_speed); + anim.m_AnimName = (CStr)attributes.getNamedItem(at_name); + anim.m_FileName = (CStr)attributes.getNamedItem(at_file); + CStr speedstr = (CStr)attributes.getNamedItem(at_speed); anim.m_Speed=float(speedstr.ToInt())/100.0f; if (anim.m_Speed<=0.0) anim.m_Speed=1.0f; @@ -222,8 +222,8 @@ bool CObjectEntry::Load(const char* filename) if (attributes.Count) { Prop prop; - prop.m_PropPointName=tocstr(attributes.getNamedItem(at_attachpoint)); - prop.m_ModelName=tocstr(attributes.getNamedItem(at_model)); + prop.m_PropPointName = (CStr)attributes.getNamedItem(at_attachpoint); + prop.m_ModelName = (CStr)attributes.getNamedItem(at_model); m_Props.push_back(prop); } diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 061aff0607..f0f969786c 100755 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -997,17 +997,17 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec XMBAttributeList attributes = Element.getAttributes(); // Well first of all we need to determine the type - std::wstring type = attributes.getNamedItem( pFile->getAttributeID("type") ); + std::utf16string type = attributes.getNamedItem( pFile->getAttributeID("type") ); // Construct object from specified type // henceforth, we need to do a rollback before aborting. // i.e. releasing this object - object = ConstructObject(tocstr(type)); + object = ConstructObject((CStr)type); if (!object) { // Report error that object was unsuccessfully loaded - ReportParseError(CStr("Unrecognized type: ") + tocstr(type)); + ReportParseError(CStr("Unrecognized type: ") + CStr(type)); delete object; return; @@ -1031,7 +1031,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec // // Always load default (if it's available) first! // - CStr argStyle = tocstr(attributes.getNamedItem(attr_style)); + CStr argStyle = (CStr)attributes.getNamedItem(attr_style); if (m_Styles.count(CStr("default")) == 1) object->LoadStyle(*this, CStr("default")); @@ -1060,7 +1060,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec XMBAttribute attr = attributes.item(i); // If value is "null", then it is equivalent as never being entered - if (attr.Value == L"null") + if ((CStr8)attr.Value == (CStr8)"null") continue; // Ignore "type" and "style", we've already checked it @@ -1070,7 +1070,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec // Also the name needs some special attention if (attr.Name == attr_name) { - object->SetName(tocstr(attr.Value)); + object->SetName((CStr)attr.Value); NameSet = true; continue; } @@ -1081,12 +1081,12 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec // Try setting the value try { - object->SetSetting(pFile->getAttributeString(attr.Name), tocstr(attr.Value)); + object->SetSetting(pFile->getAttributeString(attr.Name), (CStr)attr.Value); } catch (PS_RESULT e) { UNUSED(e); - ReportParseError(CStr("Can't set \"") + pFile->getAttributeString(attr.Name) + CStr("\" to \"") + tocstr(attr.Value) + CStr("\"")); + ReportParseError(CStr("Can't set \"") + pFile->getAttributeString(attr.Name) + CStr("\" to \"") + (CStr)attr.Value + CStr("\"")); // This is not a fatal error } @@ -1100,7 +1100,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec } - CStr caption = tocstr(Element.getText()); + CStr caption = (CStr)Element.getText(); caption.Trim(PS_TRIM_BOTH); if (caption.Length()) { @@ -1140,8 +1140,8 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec } else if (element_name == elmt_action) { - CStr action = tocstr(child.getAttributes().getNamedItem(attr_on)); - CStr code = tocstr(child.getText()); + CStr action = (CStr)child.getAttributes().getNamedItem(attr_on); + CStr code = (CStr)child.getText(); object->RegisterScriptHandler(action, code, this); } } @@ -1206,7 +1206,7 @@ void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile) // // Get name, we know it exists because of DTD requirements - name = tocstr( Element.getAttributes().getNamedItem( pFile->getAttributeID("name") ) ); + name = (CStr) Element.getAttributes().getNamedItem( pFile->getAttributeID("name") ); // // Read Children (the images) @@ -1251,7 +1251,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { XMBAttribute attr = attributes.item(i); std::string attr_name = pFile->getAttributeString(attr.Name); - CStr attr_value = tocstr( attr.Value ); + CStr attr_value (attr.Value); // This is the only attribute we want if (attr_name == "texture") @@ -1319,7 +1319,7 @@ void CGUI::Xeromyces_ReadStyle(XMBElement Element, CXeromyces* pFile) { XMBAttribute attr = attributes.item(i); std::string attr_name = pFile->getAttributeString(attr.Name); - CStr attr_value = tocstr( attr.Value ); + CStr attr_value (attr.Value); // The "name" setting is actually the name of the style // and not a new default @@ -1352,7 +1352,7 @@ void CGUI::Xeromyces_ReadScrollBarStyle(XMBElement Element, CXeromyces* pFile) { XMBAttribute attr = attributes.item(i); std::string attr_name = pFile->getAttributeString(attr.Name); - CStr attr_value = tocstr( attr.Value ); + CStr attr_value (attr.Value); if (attr_value == CStr("null")) continue; diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 31588a58b0..c5f4684ee8 100755 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -38,6 +38,13 @@ CStr::CStr(tstring String) m_String = String; } +#if !(defined(_MSC_VER) && defined(_UNICODE)) +CStr::CStr(std::utf16string String) +{ + m_String = tstring(String.begin(), String.end()); +} +#endif + CStr::CStr(TCHAR Char) { // Creates CStr from a TCHAR diff --git a/source/ps/CStr.h b/source/ps/CStr.h index cf9897453b..6d64dce39e 100755 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -52,9 +52,8 @@ enum PS_TRIM_MODE {PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH}; #include "Prometheus.h" #include // Used for basic string functionality #include +#include "ps/utf16string.h" -#include "posix.h" -#include "lib.h" #include "Network/Serialization.h" #include @@ -99,6 +98,9 @@ public: CStr(const CStr& Str); // Copy Constructor CStr(std::tstring String); // Creates CStr from C++ string +#if !(defined(_MSC_VER) && defined(_UNICODE)) + CStr(std::utf16string String); // Creates CStr from UTF16 string, potentially losing data in UTF16->ASCII conversions +#endif CStr(const TCHAR* String); // Creates CStr from C-Style TCHAR string CStr(TCHAR Char); // Creates CStr from a TCHAR CStr(int Number); // Creates CStr from a int @@ -215,3 +217,9 @@ public: std::ostream &operator<<(std::ostream &os, CStr& Str); #endif + +// Hacks to make VAssist happy: +#ifdef PLEASE_DO_NOT_EVER_DEFINE_THIS +class CStrW : public CStr; +class CStr8 : public CStr; +#endif diff --git a/source/ps/XeroXMB.cpp b/source/ps/XeroXMB.cpp index bdb21035c6..f210768f87 100755 --- a/source/ps/XeroXMB.cpp +++ b/source/ps/XeroXMB.cpp @@ -1,4 +1,4 @@ -// $Id: XeroXMB.cpp,v 1.2 2004/07/10 20:33:00 philip Exp $ +// $Id: XeroXMB.cpp,v 1.3 2004/07/10 20:55:55 philip Exp $ #include "precompiled.h" @@ -237,18 +237,3 @@ XMBAttribute XMBAttributeList::item(const int id) return XMBAttribute(*(int*)Pos, std::utf16string( (char16*)(Pos+8) )); } - - - -// Temporary hackiness. (Could CStr do automatic conversions?) -CStr tocstr(std::utf16string s) -{ - size_t len = s.size(); - char* s2 = new char[len+1]; - const char16* s1 = s.c_str(); - for (size_t i=0; i<=len; ++i) - s2[i] = (char)s1[i]; - CStr r(s2); - delete s2; - return r; -} diff --git a/source/ps/XeroXMB.h b/source/ps/XeroXMB.h index d858d66b73..a3c2b3f8f4 100755 --- a/source/ps/XeroXMB.h +++ b/source/ps/XeroXMB.h @@ -1,4 +1,4 @@ -/* $Id: XeroXMB.h,v 1.2 2004/07/10 20:33:00 philip Exp $ +/* $Id: XeroXMB.h,v 1.3 2004/07/10 20:55:55 philip Exp $ Xeromyces - XMB reading library @@ -211,9 +211,4 @@ private: char* m_LastPointer; }; - - -#include "ps/CStr.h" -CStr tocstr(std::utf16string s); - #endif // _XEROXMB_H_ diff --git a/source/simulation/BaseEntity.cpp b/source/simulation/BaseEntity.cpp index 02e73b01b0..fcd5e36c19 100755 --- a/source/simulation/BaseEntity.cpp +++ b/source/simulation/BaseEntity.cpp @@ -71,25 +71,25 @@ bool CBaseEntity::loadXML( CStr filename ) if (ChildName == el_name) { - m_name = tocstr(Child.getText()); + m_name = (CStr)Child.getText(); } else if (ChildName == el_actor) { - m_actorObject = g_ObjMan.FindObject( tocstr(Child.getText()) ); + m_actorObject = g_ObjMan.FindObject( (CStr)Child.getText() ); } else if (ChildName == el_speed) { - m_speed = CStr16(Child.getText()).ToFloat(); + m_speed = CStr(Child.getText()).ToFloat(); } else if (ChildName == el_turningradius) { - m_turningRadius = CStr16(Child.getText()).ToFloat(); + m_turningRadius = CStr(Child.getText()).ToFloat(); } else if (ChildName == el_size) { if( !m_bound_circle ) m_bound_circle = new CBoundingCircle(); - CStr16 radius = Child.getAttributes().getNamedItem(at_radius); + CStr radius (Child.getAttributes().getNamedItem(at_radius)); m_bound_circle->setRadius( radius.ToFloat() ); m_bound_type = CBoundingObject::BOUND_CIRCLE; } @@ -97,16 +97,16 @@ bool CBaseEntity::loadXML( CStr filename ) { if( !m_bound_box ) m_bound_box = new CBoundingBox(); - CStr16 width = Child.getAttributes().getNamedItem(at_width); - CStr16 height = Child.getAttributes().getNamedItem(at_height); + CStr width (Child.getAttributes().getNamedItem(at_width)); + CStr height (Child.getAttributes().getNamedItem(at_height)); m_bound_box->setDimensions( width.ToFloat(), height.ToFloat() ); m_bound_type = CBoundingObject::BOUND_OABB; } else if (ChildName == el_boundsoffset) { - CStr16 x = Child.getAttributes().getNamedItem(at_x); - CStr16 y = Child.getAttributes().getNamedItem(at_y); + CStr x (Child.getAttributes().getNamedItem(at_x)); + CStr y (Child.getAttributes().getNamedItem(at_y)); if( !m_bound_circle ) m_bound_circle = new CBoundingCircle();