00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 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 register size_t ret = 0; 00050 for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) 00051 ret = 5 * ret + *it; 00052 00053 return ret; 00054 } 00055 }; 00056 } 00057 00058 // If we're using plain vanilla VC7 Std lib 00059 #elif !defined( _STLP_HASH_FUN_H ) 00060 00061 namespace std 00062 { 00063 template<> size_t hash_compare< Ogre::_StringBase, std::less< Ogre::_StringBase > >::operator ()( const Ogre::_StringBase& _stringBase ) const 00064 { 00065 register size_t ret = 0; 00066 for( Ogre::_StringBase::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it ) 00067 ret = 5 * ret + *it; 00068 00069 return ret; 00070 } 00071 } 00072 00073 #endif 00074 00075 namespace Ogre { 00076 00081 class _OgreExport String : public _StringBase 00082 { 00083 public: 00084 typedef std::stringstream StrStreamType; 00085 public: 00088 String() : _StringBase() {} 00089 00090 String(const String& rhs) : _StringBase( static_cast< const _StringBase& >( rhs ) ) {} 00091 00094 String( const _StringBase& rhs ) : _StringBase( rhs ) {} 00095 00098 String( const char* rhs ) : _StringBase( rhs ) {} 00099 00103 operator const char* () const { return c_str(); } 00104 00112 void trim( bool left = true, bool right = true ); 00113 00122 std::vector< String > split( const String& delims = "\t\n ", unsigned int maxSplits = 0) const; 00123 00126 String toLowerCase( void ); 00127 00130 String toUpperCase( void ); 00131 00137 Real toReal(void) const; 00138 00139 /* 00140 operator _StringBase() 00141 { 00142 return *this; 00143 } 00144 */ 00145 00153 template< typename T > String& operator << (T value) 00154 { 00155 // Create stringstream based on *this contents 00156 StrStreamType sstr; 00157 sstr.str(*this); 00158 // Seek to end 00159 sstr.seekp(0, std::ios_base::end); 00160 // Write 00161 sstr << value; 00162 // Assign back 00163 *this = _StringBase( sstr.str() ); 00164 00165 return *this; 00166 } 00167 }; 00168 00169 #ifdef GCC_3_1 00170 typedef ::__gnu_cxx::hash< _StringBase > _StringHash; 00171 #elif !defined( _STLP_HASH_FUN_H ) 00172 typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash; 00173 #else 00174 typedef std::hash< _StringBase > _StringHash; 00175 #endif 00176 00177 } // namespace Ogre 00178 00179 #endif // _String_H__
Copyright © 2002 by The OGRE Team