00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #ifndef _String_H__ 00026 #define _String_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 00030 namespace Ogre { 00031 00032 #if OGRE_WCHAR_T_STRINGS 00033 typedef std::wstring _StringBase; 00034 #else 00035 typedef std::string _StringBase; 00036 #endif 00037 } 00038 00039 // If we're using the GCC 3.1 C++ Std lib 00040 #if defined( GCC_3_1 ) 00041 00042 #include <ext/hash_map> 00043 namespace __gnu_cxx 00044 { 00045 template <> struct hash< Ogre::_StringBase > 00046 { 00047 size_t operator()( const Ogre::_StringBase _stringBase ) const 00048 { 00049 /* This is the PRO-STL way, but it seems to cause problems with VC7.1 00050 and in some other cases (although I can't recreate it) 00051 hash<const char*> H; 00052 return H(_stringBase.c_str()); 00053 */ 00055 register size_t ret = 0; 00056 for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) 00057 ret = 5 * ret + *it; 00058 00059 return ret; 00060 } 00061 }; 00062 } 00063 00064 // If we're using plain vanilla VC7 Std lib 00065 #elif !defined( _STLP_HASH_FUN_H ) 00066 00067 # if _DEFINE_DEPRECATED_HASH_CLASSES 00068 namespace std 00069 # else 00070 namespace stdext 00071 # endif 00072 { 00073 template<> size_t hash_compare< Ogre::_StringBase, std::less< Ogre::_StringBase > >::operator ()( const Ogre::_StringBase& _stringBase ) const 00074 { 00075 /* This is the PRO-STL way, but it seems to cause problems with VC7.1 00076 and in some other cases (although I can't recreate it) 00077 hash<const char*> H; 00078 return H(_stringBase.c_str()); 00079 */ 00081 register size_t ret = 0; 00082 for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) 00083 ret = 5 * ret + *it; 00084 00085 return ret; 00086 } 00087 } 00088 00089 #endif 00090 00091 namespace Ogre { 00092 00097 class _OgreExport String : public _StringBase 00098 { 00099 public: 00100 typedef std::stringstream StrStreamType; 00101 public: 00104 String() : _StringBase() {} 00105 00106 String(const String& rhs) : _StringBase( static_cast< const _StringBase& >( rhs ) ) {} 00107 00110 String( const _StringBase& rhs ) : _StringBase( rhs ) {} 00111 00114 String( const char* rhs ) : _StringBase( rhs ) {} 00115 00119 operator const char* () const { return c_str(); } 00120 00128 void trim( bool left = true, bool right = true ); 00129 00138 std::vector< String > split( const String& delims = "\t\n ", unsigned int maxSplits = 0) const; 00139 00142 String toLowerCase( void ); 00143 00146 String toUpperCase( void ); 00147 00153 Real toReal(void) const; 00154 00160 bool startsWith(const String& pattern, bool lowerCase = true) const; 00161 00167 bool endsWith(const String& pattern, bool lowerCase = true) const; 00168 00169 /* 00170 operator _StringBase() 00171 { 00172 return *this; 00173 } 00174 */ 00175 00183 template< typename T > String& operator << (T value) 00184 { 00185 // Create stringstream to convert 00186 StrStreamType sstr; 00187 // Write value to string 00188 sstr << value; 00189 // Append 00190 *this += sstr.str(); 00191 00192 return *this; 00193 } 00195 static const String BLANK; 00196 }; 00197 00198 #ifdef GCC_3_1 00199 typedef ::__gnu_cxx::hash< _StringBase > _StringHash; 00200 #elif !defined( _STLP_HASH_FUN_H ) 00201 # if _DEFINE_DEPRECATED_HASH_CLASSES 00202 typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash; 00203 # else 00204 typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash; 00205 # endif 00206 #else 00207 typedef std::hash< _StringBase > _StringHash; 00208 #endif 00209 00210 } // namespace Ogre 00211 00212 #endif // _String_H__
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:49 2004