1
0
forked from 0ad/0ad

GCC fixes: things

This was SVN commit r1035.
This commit is contained in:
Ykkrosh 2004-08-21 12:57:10 +00:00
parent 6873de4ed0
commit 003bf13eb0
9 changed files with 41 additions and 17 deletions

View File

@ -14,11 +14,11 @@ using namespace I18n;
namespace I18n { namespace I18n {
// These bits don't seem to work without the explicit namespace{} // These bits don't seem to work without the explicit namespace{}
BufferVariable* NewBufferVariable(int v) { return new BufferVariable_int(v); } template<> BufferVariable* NewBufferVariable<int>(int v) { return new BufferVariable_int(v); }
BufferVariable* NewBufferVariable(double v) { return new BufferVariable_double(v); } template<> BufferVariable* NewBufferVariable<double>(double v) { return new BufferVariable_double(v); }
BufferVariable* NewBufferVariable(const wchar_t* v) { return new BufferVariable_string(v); } template<> BufferVariable* NewBufferVariable<const wchar_t*>(const wchar_t* v) { return new BufferVariable_string(v); }
BufferVariable* NewBufferVariable(const char* v) { return new BufferVariable_string(v); } template<> BufferVariable* NewBufferVariable<const char*>(const char* v) { return new BufferVariable_string(v); }
BufferVariable* NewBufferVariable(I18n::Name v) { return new BufferVariable_rawstring(v.value); } template<> BufferVariable* NewBufferVariable<I18n::Name>(I18n::Name v) { return new BufferVariable_rawstring(v.value); }
} }
StrImW BufferVariable_int::ToString(CLocale*) StrImW BufferVariable_int::ToString(CLocale*)

View File

@ -23,6 +23,23 @@ All other methods are used internally by other I18n components.
#include <map> #include <map>
#include <algorithm> #include <algorithm>
#ifdef __GNUC__
namespace __gnu_cxx
{
template<> struct hash<I18n::Str>
{
size_t operator()(const I18n::Str& s) const
{
const wchar_t* __s = s.c_str();
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(__h);
}
};
}
#endif // __GNUC__
struct JSContext; struct JSContext;
namespace I18n namespace I18n
@ -30,7 +47,7 @@ namespace I18n
class CLocale : public CLocale_interface class CLocale : public CLocale_interface
{ {
friend StringBuffer; friend class StringBuffer;
private: private:
typedef STL_HASH_MAP<Str, TranslatedString*> StringsType; typedef STL_HASH_MAP<Str, TranslatedString*> StringsType;

View File

@ -16,4 +16,4 @@ namespace I18n
} }
#endif // I18N_DATATYPES_H #endif // I18N_DATATYPES_H

View File

@ -18,7 +18,11 @@ and 'variables' (dependent on the type passed with "translate(...) <<").
ERROR_SUBGROUP(I18n, Script); ERROR_SUBGROUP(I18n, Script);
ERROR_TYPE(I18n_Script, SetupFailed); ERROR_TYPE(I18n_Script, SetupFailed);
#ifdef XP_WIN // the Windows JS libraries are using '_W64 long' to avoid MSVC warnings
typedef _W64 long jsval; typedef _W64 long jsval;
#else
typedef long jsval;
#endif
typedef unsigned short jschar; typedef unsigned short jschar;
struct JSContext; struct JSContext;
struct JSObject; struct JSObject;

View File

@ -30,7 +30,7 @@ namespace I18n
// I'm lazy (elsewhere), so allow construction from a variety // I'm lazy (elsewhere), so allow construction from a variety
// of data types: // of data types:
const StrImW(const wchar_t* s) StrImW(const wchar_t* s)
{ {
ref = new strImW_data; ref = new strImW_data;
size_t len = wcslen(s)+1; size_t len = wcslen(s)+1;
@ -38,7 +38,7 @@ namespace I18n
memcpy((void*)ref->data, s, len*sizeof(wchar_t)); memcpy((void*)ref->data, s, len*sizeof(wchar_t));
} }
const StrImW(const char* s) StrImW(const char* s)
{ {
ref = new strImW_data; ref = new strImW_data;
size_t len = strlen(s)+1; size_t len = strlen(s)+1;
@ -49,7 +49,7 @@ namespace I18n
// On non-MSVC, or on MSVC with a native wchar_t type, define jschar separately // On non-MSVC, or on MSVC with a native wchar_t type, define jschar separately
#if !defined(_MSC_VER) || !defined(_WCHAR_T_DEFINED) #if !defined(_MSC_VER) || !defined(_WCHAR_T_DEFINED)
const StrImW(const jschar* s) StrImW(const jschar* s)
{ {
ref = new strImW_data; ref = new strImW_data;
size_t len = 0; size_t len = 0;
@ -61,7 +61,7 @@ namespace I18n
} }
#endif #endif
const StrImW(const jschar* s, size_t len) StrImW(const jschar* s, size_t len)
{ {
ref = new strImW_data; ref = new strImW_data;
ref->data = new wchar_t[len+1]; ref->data = new wchar_t[len+1];
@ -80,7 +80,7 @@ namespace I18n
} }
// Copy constructor // Copy constructor
const StrImW(const StrImW& s) StrImW(const StrImW& s)
{ {
ref = s.ref; ref = s.ref;
++ref->refs; ++ref->refs;

View File

@ -10,6 +10,7 @@ before converting into a string.
#include "Common.h" #include "Common.h"
#include "TranslatedString.h" #include "TranslatedString.h"
#include "ps/CStr.h"
namespace I18n namespace I18n
{ {
@ -20,10 +21,12 @@ namespace I18n
class StringBuffer class StringBuffer
{ {
friend CLocale; friend class CLocale;
public: public:
// Builds and returns the finished string // Builds and returns the finished string
operator Str(); operator Str();
operator CStrW() { return CStrW( (Str)*this ); }
// Stores the variable inside the StringBuffer, // Stores the variable inside the StringBuffer,
// for later conversion into a string // for later conversion into a string
@ -46,4 +49,4 @@ namespace I18n
} }
#endif I18N_STRINGBUF_H #endif // I18N_STRINGBUF_H

View File

@ -70,4 +70,4 @@ namespace I18n
} }
#endif // I18N_TSCOMPONENT_H #endif // I18N_TSCOMPONENT_H

View File

@ -9,4 +9,4 @@ TranslatedString::~TranslatedString()
{ {
for (std::vector<const TSComponent*>::iterator it = Parts.begin(); it != Parts.end(); ++it) for (std::vector<const TSComponent*>::iterator it = Parts.begin(); it != Parts.end(); ++it)
delete *it; delete *it;
} }

View File

@ -25,4 +25,4 @@ namespace I18n
} }
#endif // I18N_TSTRING_H #endif // I18N_TSTRING_H