Added CStr and some other things to precompiled.h, to reduce build times.

Altered CStr/UniDoubler's macros, to avoid polluting/conflicting/etc.
Fixed headers in non-PCH builds.
Used the _d version of vorbisfile*.lib in Debug builds.

This was SVN commit r2366.
This commit is contained in:
Ykkrosh 2005-06-01 20:12:45 +00:00
parent cfb4ac8d27
commit b657a1cbca
23 changed files with 163 additions and 106 deletions

View File

@ -6,6 +6,7 @@ class CSkeletonAnim;
struct SPropPoint;
#include <vector>
#include <map>
#include "CStr.h"
#include "ObjectBase.h"
#include "Overlay.h"

View File

@ -18,8 +18,8 @@ gee@pyro.nu
using namespace std;
static const TCHAR TagStart = '[';
static const TCHAR TagEnd = ']';
static const wchar_t TagStart = '[';
static const wchar_t TagEnd = ']';
void CGUIString::SFeedback::Reset()
{

View File

@ -47,7 +47,7 @@ bool __ParseString<CRect>(const CStr& Value, CRect &Output)
// Use the parser to parse the values
CParser& parser (CParserCache::Get("_$value_$value_$value_$value_"));
string str = (const TCHAR*)Value;
string str = Value;
CParserLine line;
line.ParseString(parser, str);
@ -124,7 +124,7 @@ bool __ParseString<CSize>(const CStr& Value, CSize &Output)
// Use the parser to parse the values
CParser& parser (CParserCache::Get("_$value_$value_"));
string str = (const TCHAR*)Value;
string str = Value;
CParserLine line;
line.ParseString(parser, str);
@ -288,7 +288,7 @@ CRect CClientArea::GetClientArea(const CRect &parent) const
bool CClientArea::SetClientArea(const CStr& Value)
{
// Get value in STL string format
string _Value = (const TCHAR*)Value;
string _Value = Value;
// This might lack incredible speed, but since all XML files
// are read at startup, reading 100 client areas will be

View File

@ -572,7 +572,7 @@ JSBool JSI_IGUIObject::toString(JSContext* cx, JSObject* obj, uintN UNUSEDPARAM(
IGUIObject* e = (IGUIObject*)JS_GetPrivate( cx, obj );
char buffer[256];
snprintf(buffer, 256, "[GUIObject: %s]", (const TCHAR*)e->GetName());
snprintf(buffer, 256, "[GUIObject: %s]", e->GetName().c_str());
buffer[255] = 0;
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer));
return JS_TRUE;

View File

@ -19,6 +19,8 @@
// make string_s (secure CRT string functions) available everywhere
#include "lib/string_s.h"
// make MICROLOG and the old error system available everywhere
#include "Pyrogenesis.h"
//
// memory headers
@ -85,6 +87,23 @@
#include <string>
#include <vector>
#ifdef __GNUC__
# include <ext/hash_map>
# include <ext/hash_set>
#else
# include <hash_map>
# include <hash_set>
#endif
// CStr is included very frequently, so a reasonable amount of time is saved
// by including it here. (~10% in a full rebuild, as of r2365)
#include "ps/CStr.h"
// Some other external libraries that are used in several places:
#include "jsapi.h"
#include "boost/shared_ptr.hpp"
#include "boost/weak_ptr.hpp"
// (further headers to be precompiled go here)
#endif // #ifdef HAVE_PCH
@ -101,7 +120,7 @@
// use VC debug heap (superceded by mmgr; it remains for completeness)
#ifdef HAVE_DEBUGALLOC
// can't define _CRTDBG_MAP_ALLOC because it has a broken 'new',
// can't define _CRTDBG_MAP_ALLOC because crtdbg.h has a broken 'new',
// so manually redefine the appropriate functions.
# define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
# define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)

View File

@ -13,7 +13,11 @@
#include "ogghack.h"
#ifdef _MSC_VER
#pragma comment(lib, "vorbisfile.lib")
# ifdef NDEBUG
# pragma comment(lib, "vorbisfile.lib")
# else
# pragma comment(lib, "vorbisfile_d.lib")
# endif
#endif

View File

@ -25,6 +25,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#ifdef __APPLE__
# include <OpenAL/alut.h>

View File

@ -29,6 +29,8 @@
#include "vfs_tree.h"
#include <string.h>
#include <time.h>
#include <math.h>
#include <map>
#include <list>

View File

@ -1,9 +1,11 @@
#include "precompiled.h"
#include <string.h>
#include <time.h>
#include <string>
#include <vector>
#include <algorithm>
#include "lib.h"
#include "res.h"

View File

@ -44,6 +44,7 @@
#include <map>
#include <assert.h>
#include <time.h>
// provision for removing all ZLib code (all inflate calls will fail).
// used for checking DLL dependency; might also simulate corrupt Zip files.

View File

@ -27,6 +27,7 @@
#include <math.h>
#include <process.h> // _beginthreadex
#include <time.h>
#include <algorithm>
#include <numeric>

View File

@ -30,6 +30,5 @@ typedef unsigned int PS_uint;
#if defined(SIZE_MAX) && SIZE_MAX < 32
# error "check size_t and SIZE_MAX - too small?"
#endif
#endif // #ifndef __TYPES_H__

View File

@ -4,6 +4,8 @@
#include "ConfigDB.h"
#include "lib.h"
#include <time.h>
#include "CConsole.h"
extern CConsole* g_Console;

View File

@ -7,9 +7,12 @@
#include "Network/Serialization.h"
#include <cassert>
#include <sstream>
#define UNIDOUBLER_HEADER "CStr.cpp"
#include "UniDoubler.h"
// Only include these function definitions in the first instance of CStr.cpp:
CStrW::CStrW(const CStr8 &asciStr) : std::wstring(asciStr.begin(), asciStr.end()) {}
CStr8::CStr8(const CStrW &wideStr) : std:: string(wideStr.begin(), wideStr.end()) {}
@ -131,6 +134,24 @@ using namespace std;
#include <sstream>
#ifdef _UNICODE
#define tstringstream wstringstream
#define _tstod wcstod
#define _ttoi(a) wcstol(a, NULL, 0)
#define _ttol(a) wcstol(a, NULL, 0)
#define _istspace iswspace
#define _totlower towlower
#define _totupper towupper
#else
#define tstringstream stringstream
#define _tstod strtod
#define _ttoi atoi
#define _ttol atol
#define _istspace isspace
#define _totlower tolower
#define _totupper toupper
#endif
// Construction and assignment from numbers:
#define NUM_TYPE(T) \
@ -209,9 +230,9 @@ long CStr::Find(const CStr& Str) const
}
// Search the string for another string
long CStr::Find(const TCHAR &tchar) const
long CStr::Find(const tchar &chr) const
{
size_t Pos = find(tchar, 0);
size_t Pos = find(chr, 0);
if (Pos != npos)
return (long)Pos;
@ -220,9 +241,9 @@ long CStr::Find(const TCHAR &tchar) const
}
// Search the string for another string
long CStr::Find(const int &start, const TCHAR &tchar) const
long CStr::Find(const int &start, const tchar &chr) const
{
size_t Pos = find(tchar, start);
size_t Pos = find(chr, start);
if (Pos != npos)
return (long)Pos;
@ -230,8 +251,8 @@ long CStr::Find(const int &start, const TCHAR &tchar) const
return -1;
}
long CStr::FindInsensitive(const int &start, const TCHAR &tchar) const { return LCase().Find(start, _totlower(tchar)); }
long CStr::FindInsensitive(const TCHAR &tchar) const { return LCase().Find(_totlower(tchar)); }
long CStr::FindInsensitive(const int &start, const tchar &chr) const { return LCase().Find(start, _totlower(chr)); }
long CStr::FindInsensitive(const tchar &chr) const { return LCase().Find(_totlower(chr)); }
long CStr::FindInsensitive(const CStr& Str) const { return LCase().Find(Str.LCase()); }
@ -251,7 +272,7 @@ CStr CStr::LowerCase() const
{
tstring NewString = *this;
for (size_t i = 0; i < length(); i++)
NewString[i] = (TCHAR)_totlower((*this)[i]);
NewString[i] = (tchar)_totlower((*this)[i]);
return NewString;
}
@ -260,7 +281,7 @@ CStr CStr::UpperCase() const
{
tstring NewString = *this;
for (size_t i = 0; i < length(); i++)
NewString[i] = (TCHAR)_totupper((*this)[i]);
NewString[i] = (tchar)_totupper((*this)[i]);
return NewString;
}
@ -271,7 +292,7 @@ CStr CStr::LCase() const
{
tstring NewString = *this;
for (size_t i = 0; i < length(); i++)
NewString[i] = (TCHAR)_totlower((*this)[i]);
NewString[i] = (tchar)_totlower((*this)[i]);
return NewString;
}
@ -280,7 +301,7 @@ CStr CStr::UCase() const
{
tstring NewString = *this;
for (size_t i = 0; i < length(); i++)
NewString[i] = (TCHAR)_totupper((*this)[i]);
NewString[i] = (tchar)_totupper((*this)[i]);
return NewString;
}
@ -380,19 +401,19 @@ CStr CStr::UnescapeBackslashes()
bool escaping = false;
for (size_t i = 0; i < length(); i++)
{
TCHAR ch = (*this)[i];
tchar ch = (*this)[i];
if (escaping)
{
switch (ch)
{
case _T('n'): NewString += _T('\n'); break;
case 'n': NewString += '\n'; break;
default: NewString += ch; break;
}
escaping = false;
}
else
{
if (ch == _T('\\'))
if (ch == '\\')
escaping = true;
else
NewString += ch;
@ -450,7 +471,7 @@ CStr CStr::operator+(const CStr& Str)
return std::operator+(*this, std::tstring(Str));
}
CStr CStr::operator+(const TCHAR* Str)
CStr CStr::operator+(const tchar* Str)
{
return std::operator+(*this, std::tstring(Str));
}
@ -469,7 +490,7 @@ CStrW CStr::operator+(const CStr8& Str)
#endif
CStr::operator const TCHAR*() const
CStr::operator const tchar*() const
{
return c_str();
}
@ -509,7 +530,7 @@ const u8 *CStrW::Deserialize(const u8 *buffer, const u8 *bufferend)
std::wstring::iterator str = begin();
while (ptr < strend)
*(str++) = (TCHAR)ntohs(*(ptr++)); // convert from network order (big-endian)
*(str++) = (tchar)ntohs(*(ptr++)); // convert from network order (big-endian)
return (const u8 *)(strend+1);
}
@ -553,4 +574,13 @@ uint CStr::GetSerializedLength() const
#endif // _UNICODE
// Clean up, to keep the second pass through unidoubler happy
#undef tstringstream
#undef _tstod
#undef _ttoi
#undef _ttol
#undef _istspace
#undef _totlower
#undef _totupper
#endif // CStr_CPP_FIRST

View File

@ -28,6 +28,10 @@ Example:
More Info:
http://wildfiregames.com/0ad/codepit/TDD/CStr.html
[[ This documentation is out of date; CStr is always 8 bits, and CStrW is always
sizeof(wchar_t) (16 or 32). Don't use _T; CStrW constants are just L"string". ]]
*/
// history:
@ -47,74 +51,48 @@ enum PS_TRIM_MODE { PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH };
#endif
#if !defined(CSTR_H) || defined(IN_UNIDOUBLER)
#define CSTR_H
// Include this section when in unidoubler mode, and when this unicode/ascii
// version has not already been included.
#if defined(IN_UNIDOUBLER) && ( (defined(_UNICODE) && !defined(CSTR_H_U)) || (!defined(_UNICODE) && !defined(CSTR_H_A)) )
#include "Pyrogenesis.h"
#include <string> // Used for basic string functionality
#include <iostream>
#ifdef _UNICODE
#define CSTR_H_U
#else
#define CSTR_H_A
#endif
#include <string>
#include "ps/utf16string.h"
#include "Network/Serialization.h"
#include <cstdlib>
#ifdef _UNICODE
#define tstring wstring
#define tstringstream wstringstream
#define _tcout wcout
#define _tstod wcstod
#define TCHAR wchar_t
#define _ttoi(a) wcstol(a, NULL, 0)
#define _ttol(a) wcstol(a, NULL, 0)
#define _T(t) L ## t
#define _istspace iswspace
#define _tsnprintf swprintf
#define _totlower towlower
#define _totupper towupper
#else
#define tstringstream stringstream
#define tstring string
#define _tcout cout
#define _tstod strtod
#define _ttoi atoi
#define _ttol atol
#define TCHAR char
#define _T(t) t
#define _istspace isspace
#define _tsnprintf snprintf
#define _totlower tolower
#define _totupper toupper
#endif
class CStr8;
class CStrW;
// CStr class, the mother of all strings
class CStr: public std::tstring, public ISerializable
{
// The two variations must be friends with each other
#ifdef _UNICODE
friend class CStr8;
#else
friend class CStrW;
#endif
public:
// CONSTRUCTORS
CStr() {}
CStr(const CStr& String) : std::tstring(String) {}
CStr(const TCHAR* String) : std::tstring(String) {}
CStr(const TCHAR* String, size_t Length)
CStr(const tchar* String) : std::tstring(String) {}
CStr(const tchar* String, size_t Length)
: std::tstring(String, Length) {}
CStr(const TCHAR Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr)
CStr(const tchar Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr)
CStr(std::tstring String) : std::tstring(String) {}
// CStrW construction from utf16strings
// CStr(8|W) construction from utf16strings, except on MSVC CStrW where
// CStrW === utf16string
#if !(defined(_MSC_VER) && defined(_UNICODE))
CStr(utf16string String) : std::tstring(String.begin(), String.end()) {}
#endif
@ -154,7 +132,7 @@ public:
float ToFloat() const;
double ToDouble() const;
// Returns the length of the string in characters
// Returns the length of the string in characters
size_t Length() const { return length(); }
// Retrieves the substring within the string
@ -163,13 +141,13 @@ public:
// Search the string for another string. Returns the offset of the first
// match, or -1 if no matches are found.
long Find(const CStr& Str) const;
long Find(const TCHAR &tchar) const;
long Find(const int &start, const TCHAR &tchar) const;
long Find(const tchar &chr) const;
long Find(const int &start, const tchar &chr) const;
// Case-insensitive versions of Find
long FindInsensitive(const CStr& Str) const;
long FindInsensitive(const TCHAR &tchar) const;
long FindInsensitive(const int &start, const TCHAR &tchar) const;
long FindInsensitive(const tchar &chr) const;
long FindInsensitive(const int &start, const tchar &chr) const;
// You can also do a "ReverseFind" - i.e. search starting from the end
long ReverseFind(const CStr& Str) const;
@ -224,18 +202,18 @@ public:
CStr& operator=(double Number);
CStr operator+(const CStr& Str);
CStr operator+(const TCHAR* Str);
CStr operator+(const tchar* Str);
#ifndef _UNICODE
CStr8 operator+(const CStrW& Str);
#else
CStrW operator+(const CStr8& Str);
#endif
operator const TCHAR*() const;
operator const tchar*() const;
// Do some range checking in debug builds
TCHAR &operator[](size_t n) { assert(n < length()); return this->std::tstring::operator[](n); }
TCHAR &operator[](int n) { assert(n >= 0 && (size_t)n < length()); return this->std::tstring::operator[](n); }
tchar &operator[](size_t n) { assert(n < length()); return this->std::tstring::operator[](n); }
tchar &operator[](int n) { assert(n >= 0 && (size_t)n < length()); return this->std::tstring::operator[](n); }
// Conversion to utf16string
inline utf16string utf16() const

View File

@ -268,6 +268,12 @@ const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \
/*************************************************************************/
// Pass 6, String Representation
#define _T(s) s
// PT: I'm not sure whether this is correct - it appears that this code
// relied on CStr.h leaving _T defined in ASCII mode, so I'm not sure
// why the macro is actually used at all...
#define START_NMTS()
#define END_NMTS()

View File

@ -4,6 +4,7 @@
#include "ThreadUtil.h"
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "lib/timer.h"
CNetLog g_NetLog;

View File

@ -90,7 +90,7 @@ void RenderProfile()
glPushMatrix();
glwprintf( L"%%/parent" );
glPopMatrix();
glPopMatrix();
glPopMatrix();
CProfileNode::const_profile_iterator it;

View File

@ -5,37 +5,53 @@
#define IN_UNIDOUBLER
#define _UNICODE
// When compiling CStr.cpp with PCH, the unidoubler stuff gets rather
// confusing because of all the nested inclusions, but this makes it work:
#undef CStr
#undef CStr_hash_compare
// First, set up the environment for the Unicode version
#define _UNICODE
#define CStr CStrW
#define CStr_hash_compare CStrW_hash_compare
#define tstring wstring
#define tchar wchar_t
#define _T(t) L ## t
// Include the unidoubled file
#include UNIDOUBLER_HEADER
// Undef all the Conversion Macros
#undef tstring
#undef tstringstream
#undef _tcout
#undef _tstod
#undef _ttoi
#undef _ttol
#undef TCHAR
#undef _T
#undef _istspace
#undef _tsnprintf
#undef _totlower
#undef _totupper
// Now include the 8-bit version under the name CStr8
// Clean up all the macros
#undef _UNICODE
#undef CStr
#undef CStr_hash_compare
#undef tstring
#undef tchar
#undef _T
// Now include the 8-bit version under the name CStr8
#define CStr CStr8
#define CStr_hash_compare CStr8_hash_compare
#define tstring string
#define tchar char
#define _T(t) t
#include UNIDOUBLER_HEADER
// Clean up the macros again, to minimise namespace pollution
#undef CStr
#undef CStr_hash_compare
#undef tstring
#undef tchar
#undef _T
// To please the file that originally include CStr.h, make CStr an alias for CStr8:
#define CStr CStr8
#define CStr_hash_compare CStr8_hash_compare
#undef IN_UNIDOUBLER
#undef UNIDOUBLER_HEADER
#endif

View File

@ -5,6 +5,7 @@
#include "CConsole.h"
#include "Profile.h"
#include <sstream>
#include <iostream>
#include "res/res.h"

View File

@ -470,7 +470,7 @@ bool CEntity::processContactActionNoPathing( CEntityOrder* current, size_t times
// Load time needs to be animation->m_ActionPos2 ms after the start of the animation.
m_fsm_anipos2 = m_fsm_anipos + ( action->m_Speed * m_fsm_animation->m_ActionPos2 * 2 );
m_fsm_anipos2 = m_fsm_anipos + (size_t)( action->m_Speed * m_fsm_animation->m_ActionPos2 * 2 );
if( m_fsm_anipos2 < 0 )
{
// Load now.

View File

@ -6,9 +6,6 @@
#include "ScEd.h"
#include "SimpleEdit.h"
// Slight hack, since this gets undef'd earlier to avoid conflicts with CStr
#define _T(x) x
/////////////////////////////////////////////////////////////////////////////
// CSimpleEdit dialog

View File

@ -14,9 +14,11 @@
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
// Fix nasty conflicts between various header files.
#define _SIZE_T_DEFINED
#include "posix.h"
//#include "CStr.h"
#include "CStr.h"
#undef UNUSED
#undef _WINDOWS_
@ -31,12 +33,6 @@
#endif // _AFX_NO_AFXCMN_SUPPORT
#undef UNUSED
#undef _T
#undef _istspace
#undef _totlower
#undef _totupper
#undef _ttoi
#undef _ttol
#include "resource.h"