Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreString.h

Go to the documentation of this file.
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 based on *this contents
00186             StrStreamType sstr;
00187             sstr.str(*this);
00188             // Seek to end
00189             sstr.seekp(0, std::ios_base::end);
00190             // Write
00191             sstr << value;
00192             // Assign back
00193             *this = _StringBase( sstr.str() );
00194 
00195             return *this;
00196         }
00198         static String BLANK;
00199     };
00200 
00201 #ifdef GCC_3_1
00202     typedef ::__gnu_cxx::hash< _StringBase > _StringHash;    
00203 #elif !defined( _STLP_HASH_FUN_H )
00204 #   if _DEFINE_DEPRECATED_HASH_CLASSES
00205         typedef std::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
00206 #   else
00207         typedef stdext::hash_compare< _StringBase, std::less< _StringBase > > _StringHash;
00208 #   endif
00209 #else
00210     typedef std::hash< _StringBase > _StringHash;
00211 #endif
00212 
00213 } // namespace Ogre
00214 
00215 #endif // _String_H__

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:28 2004