00001
00011 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00012 #pragma once
00013 #endif
00014 #ifndef BSTR_STRING_H_
00015 #define BSTR_STRING_H_
00016
00017 #ifndef WIN32
00018 #error BstrString module supports only WIN32 platform.
00019 #endif
00020
00021 #include <windows.h>
00022 #include <Oleauto.h>
00023
00024 namespace common
00025 {
00026
00031
00033
00036 class BstrString
00037 {
00038 public:
00040 static int Cmp(const BstrString &bstr1, const BstrString &bstr2, bool ignoreCase = false);
00041
00042 BstrString();
00043 BstrString(const BstrString &bstr);
00044 BstrString(const char *str);
00045 BstrString(const char *str, size_t strLen);
00046 BstrString(const wchar_t *wcs);
00047 BstrString(const wchar_t *wcs, size_t wcsLen);
00048 BstrString(const std::string &s);
00049 BstrString(const std::wstring &s);
00050 BstrString(BSTR bstr);
00051 BstrString(size_t length);
00052 ~BstrString();
00053
00054 void assign(const BstrString &bstr);
00055 void assign(const char *str);
00056 void assign(const char *str, size_t strLen);
00057 void assign(const wchar_t *wcs);
00058 void assign(const wchar_t *wcs, size_t wcsLen);
00059 void assign(const std::string &s);
00060 void assign(const std::wstring &s);
00061 void assign(BSTR bstr);
00062
00063 BstrString & operator = (const BstrString &bstr) { assign(bstr); return *this; }
00064 BstrString & operator = (const char *str) { assign(str); return *this; }
00065 BstrString & operator = (const wchar_t *wcs) { assign(wcs); return *this; }
00066 BstrString & operator = (BSTR bstr) { assign(bstr); return *this; }
00067 BstrString & operator = (const std::string &s) { assign(s); return *this; }
00068 BstrString & operator = (const std::wstring &s) { assign(s); return *this; }
00069
00070 bool operator == (const BstrString &bstr) const { return Cmp(*this, bstr) == 0; }
00071 bool operator != (const BstrString &bstr) const { return Cmp(*this, bstr) != 0; }
00072 bool operator < (const BstrString &bstr) const { return Cmp(*this, bstr) < 0; }
00073 bool operator > (const BstrString &bstr) const { return Cmp(*this, bstr) > 0; }
00074 bool operator <= (const BstrString &bstr) const { return Cmp(*this, bstr) <= 0; }
00075 bool operator >= (const BstrString &bstr) const { return Cmp(*this, bstr) >= 0; }
00076
00077 wchar_t & operator [] (size_t index) { return ( (wchar_t*) Bstr )[index]; }
00078 const wchar_t & operator [] (size_t index) const { return ( (const wchar_t*)Bstr )[index]; }
00079
00080 void append(const BstrString &bstr);
00081 void append(const char *str);
00082 void append(const char *str, size_t strLen);
00083 void append(const wchar_t *wcs);
00084 void append(const wchar_t *wcs, size_t wcsLen);
00085 void append(const std::string &s);
00086 void append(const std::wstring &s);
00087 void append(BSTR bstr);
00088
00089 BstrString & operator += (const BstrString &bstr) { append(bstr); return *this; }
00090 BstrString & operator += (const char *str) { append(str); return *this; }
00091 BstrString & operator += (const wchar_t *wcs) { append(wcs); return *this; }
00092 BstrString & operator += (const std::string &s) { append(s); return *this; }
00093 BstrString & operator += (const std::wstring &s) { append(s); return *this; }
00094 BstrString & operator += (BSTR bstr) { append(bstr); return *this; }
00095
00096 BstrString operator + (const BstrString &bstr) const;
00097
00098 void clear();
00099
00100 const char *c_str() const;
00101 const wchar_t *wc_str() const { return (const wchar_t*)Bstr; }
00102 BSTR data() { return Bstr; }
00103 BSTR b_str() const { return Bstr; }
00104
00106 size_t CalcStrLen() const;
00108 bool ConvertToStr(char *outBuf, size_t bufLen) const;
00109
00110 size_t length() const;
00111 size_t size() const { return length(); }
00112 bool empty() const { return length() == 0; }
00113 void resize(size_t newLength);
00114
00115 BstrString substr(size_t off = 0, size_t count = 0xFFFFFFFF) const;
00116
00117 private:
00118 BSTR Bstr;
00119
00120
00121 mutable char *TmpStr;
00122 };
00123
00124
00126
00127
00128 }
00129
00130 #endif