- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ustring.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/util/ustring.hpp 00008 begin : Sat Aug 11 2001 00009 $Id: ustring.hpp,v 1.16 2005/09/30 14:30:08 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef USTRING_HPP 00029 #define USTRING_HPP 00030 00031 #include "../uobject.hpp" 00032 #include "../usharedptr.hpp" 00033 00034 #include <string> 00035 #include <vector> 00036 00037 #include "../ufo_types.hpp" // UStringStream 00038 00039 namespace ufo { 00040 00051 class UFO_EXPORT UString : public UObject { 00052 UFO_DECLARE_DYNAMIC_CLASS(UString) 00053 private: // Private attributes 00054 USharedPtr<std::string> m_stringRef; 00055 public: 00056 UString(char * str); 00057 UString(const char * str); 00058 UString(const std::string & str); 00059 00060 public: // operators 00061 inline bool operator ==(UString & str) const; 00062 inline bool operator ==(const UString & str) const; 00063 00064 inline bool operator ==(const std::string & str) const; 00065 00066 UString & operator =(char * str); 00067 UString & operator =(const char * str); 00068 UString & operator =(const std::string & str); 00069 00070 operator std::string() const { 00071 return *m_stringRef; 00072 } 00073 00074 public: // Public methods 00079 inline const std::string & str() const; 00088 inline std::string & str(); 00089 00091 inline const char * c_str() const; 00092 00094 void detach(); 00095 00100 std::vector<std::string> tokenize(char delimiter) const; 00101 00103 UString upperCase() const; 00105 UString lowerCase() const; 00106 00107 public: // Public static methods 00109 #ifndef _MSC_VER 00110 template <typename TYPE> 00111 static std::string toString(const TYPE & t); 00112 #else 00113 template <typename TYPE> 00114 static std::string toString(const TYPE & t) { 00115 UOStringStream os; 00116 os << t; 00117 return os.str(); 00118 } 00119 #endif 00120 static int toInt(const std::string & str); 00121 static unsigned int toUnsignedInt(const std::string & str); 00122 static double toDouble(const std::string & str); 00123 00126 static unsigned int hash(const char * cstr); 00127 00128 public: // Overrides UObject 00129 00130 virtual unsigned int hashCode() const; 00131 00133 virtual bool equals(const UString * str) const; 00134 00136 virtual bool equals(const UObject * obj) const; 00138 virtual std::string toString() const; 00139 00140 virtual UObject * clone() const; 00141 00142 protected: // Overrides UObject 00143 virtual std::ostream & paramString(std::ostream & os) const; 00144 }; 00145 00146 // 00147 // inline implementation 00148 // 00149 00150 00151 inline bool 00152 UString::operator ==(UString & str) const { 00153 return !(m_stringRef->compare(str.str())); 00154 } 00155 inline bool 00156 UString::operator ==(const UString & str) const { 00157 return !(m_stringRef->compare(str.str())); 00158 } 00159 00160 inline bool 00161 UString::operator ==(const std::string & str) const { 00162 return !(m_stringRef->compare(str)); 00163 } 00164 00165 inline const std::string & 00166 UString::str() const { 00167 return *m_stringRef; 00168 } 00169 00170 inline std::string & 00171 UString::str() { 00172 return *m_stringRef; 00173 } 00174 00175 inline const char * 00176 UString::c_str() const { 00177 return m_stringRef->c_str(); 00178 } 00179 00180 #ifndef _MSC_VER 00181 template <typename TYPE> std::string 00182 UString::toString(const TYPE & t) { 00183 UOStringStream os; 00184 os << t; 00185 return os.str(); 00186 } 00187 #endif 00188 00189 00190 } // namespace ufo 00191 00192 #endif // USTRING_HPP

The libUFO Project - written by Johannes Schmidt