160 lines
2.9 KiB
C++
160 lines
2.9 KiB
C++
#ifndef _COM_BSTRING_HPP_
|
|
#define _COM_BSTRING_HPP_
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
#ifndef _COMMON_WIDESTRING_HPP_
|
|
#include <common/widestr.hpp>
|
|
#endif
|
|
#ifndef _COM_OLEAUTO_HPP_
|
|
#include <com/oleauto.hpp>
|
|
#endif
|
|
|
|
class BString
|
|
{
|
|
public:
|
|
enum Disposition{Assume,Delete};
|
|
BString(void);
|
|
BString(const String &string);
|
|
virtual ~BString();
|
|
BString &operator=(const BString &string);
|
|
BString &operator=(const String &string);
|
|
BString &operator=(const wchar_t *string);
|
|
bool operator==(const BString &string)const;
|
|
bool operator==(const String &string)const;
|
|
int lengthBytes(void)const;
|
|
int length(void)const;
|
|
const wchar_t *str(void)const;
|
|
void disposition(Disposition disposition);
|
|
Disposition disposition(void)const;
|
|
String toString(void);
|
|
bool isOkay(void)const;
|
|
private:
|
|
void sysFreeString(void);
|
|
void sysAllocString(const wchar_t *pString);
|
|
|
|
wchar_t *mpWideString;
|
|
Disposition mDisposition;
|
|
};
|
|
|
|
inline
|
|
BString::BString(void)
|
|
: mpWideString(0), mDisposition(Delete)
|
|
{
|
|
}
|
|
|
|
inline
|
|
BString::BString(const String &string)
|
|
: mpWideString(0), mDisposition(Delete)
|
|
{
|
|
*this=string;
|
|
}
|
|
|
|
inline
|
|
BString::~BString()
|
|
{
|
|
sysFreeString();
|
|
}
|
|
|
|
inline
|
|
BString &BString::operator=(const BString &string)
|
|
{
|
|
if(str()==string.str())return *this;
|
|
sysFreeString();
|
|
if(!string.isOkay())return *this;
|
|
sysAllocString(string.str());
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
BString &BString::operator=(const String &string)
|
|
{
|
|
sysFreeString();
|
|
if(string.isNull())return *this;
|
|
WideString wideString(string);
|
|
sysAllocString((wchar_t*)&wideString[0]);
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
BString &BString::operator=(const wchar_t *string)
|
|
{
|
|
sysFreeString();
|
|
if(!string)return *this;
|
|
sysAllocString(string);
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
bool BString::operator==(const BString &string)const
|
|
{
|
|
if(!isOkay()||!string.isOkay())return false;
|
|
return 0==::wcscmp(str(),string.str())?true:false;
|
|
}
|
|
|
|
inline
|
|
bool BString::operator==(const String &string)const
|
|
{
|
|
BString tmpString(string);
|
|
return *this==tmpString;
|
|
}
|
|
|
|
inline
|
|
const wchar_t *BString::str(void)const
|
|
{
|
|
return mpWideString;
|
|
}
|
|
|
|
inline
|
|
void BString::sysAllocString(const wchar_t *pString)
|
|
{
|
|
sysFreeString();
|
|
if(!pString)return;
|
|
mpWideString=::SysAllocString(pString);
|
|
return;
|
|
}
|
|
|
|
inline
|
|
void BString::sysFreeString(void)
|
|
{
|
|
if(!mpWideString)return;
|
|
if(Delete==disposition())::SysFreeString(mpWideString);
|
|
mpWideString=0;
|
|
mDisposition=Delete;
|
|
}
|
|
|
|
inline
|
|
int BString::lengthBytes(void)const
|
|
{
|
|
if(!isOkay())return 0;
|
|
return ::SysStringByteLen((wchar_t*)str());
|
|
}
|
|
|
|
inline
|
|
int BString::length(void)const
|
|
{
|
|
if(!isOkay())return 0;
|
|
return ::SysStringLen((wchar_t*)str());
|
|
}
|
|
|
|
inline
|
|
bool BString::isOkay(void)const
|
|
{
|
|
return mpWideString?true:false;
|
|
}
|
|
|
|
inline
|
|
void BString::disposition(Disposition disposition)
|
|
{
|
|
mDisposition=disposition;
|
|
}
|
|
|
|
inline
|
|
BString::Disposition BString::disposition(void)const
|
|
{
|
|
return mDisposition;
|
|
}
|
|
#endif |