00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
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" 
00038 
00039 
namespace ufo {
00040 
00051 class UFO_EXPORT UString : 
public UObject {
00052     UFO_DECLARE_DYNAMIC_CLASS(UString)
00053 
private: 
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: 
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: 
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: 
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: 
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: 
00143     
virtual std::ostream & paramString(std::ostream & os) 
const;
00144 };
00145 
00146 
00147 
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 } 
00191 
00192 
#endif // USTRING_HPP