STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | List of all members
_bstr_t::Data_t Class Reference

Public Member Functions

 Data_t (const char *s)
 
 Data_t (const wchar_t *s)
 
 Data_t (BSTR bstr, bool fCopy)
 
 Data_t (const _bstr_t &s1, const _bstr_t &s2)
 
unsigned long AddRef () throw ()
 
unsigned long Release () throw ()
 
unsigned long RefCount () const throw ()
 
 operator const wchar_t * () const throw ()
 
 operator const char * () const
 
const wchar_tGetWString () const throw ()
 
wchar_t *& GetWString () throw ()
 
const char * GetString () const
 
BSTR Copy () const
 
void Assign (BSTR s)
 
void Attach (BSTR s) throw ()
 
unsigned int Length () const throw ()
 
int Compare (const Data_t &str) const throw ()
 
voidoperator new (size_t sz)
 

Private Member Functions

 Data_t () throw ()
 
 Data_t (const Data_t &s) throw ()
 
 ~Data_t () throw ()
 
void _Free () throw ()
 

Private Attributes

BSTR m_wstr
 
char * m_str
 
unsigned long m_RefCount
 

Constructor & Destructor Documentation

_bstr_t::Data_t::Data_t ( const char *  s)
inline
681  : m_str(NULL), m_RefCount(1)
682 {
684 }
BSTR __stdcall ConvertStringToBSTR(const char *pSrc)
#define NULL
Definition: vcruntime.h:236
unsigned long m_RefCount
Definition: comutil.h:257
char * m_str
Definition: comutil.h:256
BSTR m_wstr
Definition: comutil.h:255
_bstr_t::Data_t::Data_t ( const wchar_t s)
inline
689  : m_str(NULL), m_RefCount(1)
690 {
691  m_wstr = ::SysAllocString(s);
692 
693  if (m_wstr == NULL && s != NULL) {
694  _com_issue_error(E_OUTOFMEMORY);
695  }
696 }
#define NULL
Definition: vcruntime.h:236
unsigned long m_RefCount
Definition: comutil.h:257
char * m_str
Definition: comutil.h:256
void __stdcall _com_issue_error(HRESULT)
BSTR m_wstr
Definition: comutil.h:255
_bstr_t::Data_t::Data_t ( BSTR  bstr,
bool  fCopy 
)
inline
702  : m_str(NULL), m_RefCount(1)
703 {
704  if (fCopy && bstr != NULL) {
705  m_wstr = ::SysAllocStringByteLen(reinterpret_cast<char*>(bstr),
706  ::SysStringByteLen(bstr));
707 
708  if (m_wstr == NULL) {
709  _com_issue_error(E_OUTOFMEMORY);
710  }
711  }
712  else {
713  m_wstr = bstr;
714  }
715 }
#define NULL
Definition: vcruntime.h:236
unsigned long m_RefCount
Definition: comutil.h:257
char * m_str
Definition: comutil.h:256
void __stdcall _com_issue_error(HRESULT)
BSTR m_wstr
Definition: comutil.h:255
_bstr_t::Data_t::Data_t ( const _bstr_t s1,
const _bstr_t s2 
)
inline
720  : m_str(NULL), m_RefCount(1)
721 {
722  const unsigned int l1 = s1.length();
723  const unsigned int l2 = s2.length();
724  unsigned int l3;
725 
726  if (FAILED(_com_util::UIntAdd(l1, l2, &l3)) ||
727  FAILED(_com_util::UIntMult(l3, sizeof(wchar_t), &l3)))
728  {
729  _com_issue_error(E_OUTOFMEMORY);
730  return;
731  }
732 
733  m_wstr = ::SysAllocStringByteLen(NULL, (l1 + l2) * sizeof(wchar_t));
734  if (m_wstr == NULL)
735  {
736  if (l1 + l2 == 0)
737  {
738  return;
739  }
740  _com_issue_error(E_OUTOFMEMORY);
741  return;
742  }
743 
744  const wchar_t* wstr1 = static_cast<const wchar_t*>(s1);
745 
746  if (wstr1 != NULL)
747  {
748  _COM_MEMCPY_S(m_wstr, (l1 + l2 + 1) * sizeof(wchar_t), wstr1, (l1 + 1) * sizeof(wchar_t));
749  }
750 
751  const wchar_t* wstr2 = static_cast<const wchar_t*>(s2);
752 
753  if (wstr2 != NULL)
754  {
755  _COM_MEMCPY_S(m_wstr + l1, (l2 + 1) * sizeof(wchar_t), wstr2, (l2 + 1) * sizeof(wchar_t));
756  }
757 }
#define NULL
Definition: vcruntime.h:236
unsigned long m_RefCount
Definition: comutil.h:257
char * m_str
Definition: comutil.h:256
void __stdcall _com_issue_error(HRESULT)
#define FAILED(hr)
Definition: comutil.h:71
static HRESULT UIntAdd(UINT uAugend, UINT uAddend, UINT *puResult)
Definition: comutil.h:100
#define _COM_MEMCPY_S(dest, destsize, src, count)
Definition: comutil.h:48
static HRESULT UIntMult(UINT uMultiplicand, UINT uMultiplier, UINT *puResult)
Definition: comutil.h:110
BSTR m_wstr
Definition: comutil.h:255
unsigned int length() const
Definition: comutil.h:552
_bstr_t::Data_t::Data_t ( )
throw (
)
private
_bstr_t::Data_t::Data_t ( const Data_t s)
throw (
)
private
_bstr_t::Data_t::~Data_t ( )
throw (
)
inlineprivate
922 {
923  _Free();
924 }
void _Free()
Definition: comutil.h:928

Member Function Documentation

void _bstr_t::Data_t::_Free ( )
throw (
)
inlineprivate
929 {
930  if (m_wstr != NULL) {
931  ::SysFreeString(m_wstr);
932  m_wstr = NULL;
933  }
934 
935  if (m_str != NULL) {
936  delete [] m_str;
937  m_str = NULL;
938  }
939 }
#define NULL
Definition: vcruntime.h:236
char * m_str
Definition: comutil.h:256
BSTR m_wstr
Definition: comutil.h:255
unsigned long _bstr_t::Data_t::AddRef ( )
throw (
)
inline
766 {
767  InterlockedIncrement(reinterpret_cast<long*>(&m_RefCount));
768  return m_RefCount;
769 }
unsigned long m_RefCount
Definition: comutil.h:257
void _bstr_t::Data_t::Assign ( BSTR  s)
inline
849 {
850  _Free();
851 
852  if (s != NULL) {
853  m_wstr = ::SysAllocStringByteLen(reinterpret_cast<char*>(s), ::SysStringByteLen(s));
854  m_str = 0;
855  }
856 }
void _Free()
Definition: comutil.h:928
#define NULL
Definition: vcruntime.h:236
char * m_str
Definition: comutil.h:256
BSTR m_wstr
Definition: comutil.h:255
void _bstr_t::Data_t::Attach ( BSTR  s)
throw (
)
inline
859 {
860  _Free();
861 
862  m_wstr = s;
863  m_str = 0;
864  m_RefCount = 1;
865 }
void _Free()
Definition: comutil.h:928
unsigned long m_RefCount
Definition: comutil.h:257
char * m_str
Definition: comutil.h:256
BSTR m_wstr
Definition: comutil.h:255
int _bstr_t::Data_t::Compare ( const Data_t str) const
throw (
)
inline
877 {
878  // Dont need to check for NULL here, because
879  // SysStringLen will return 0 if you pass in NULL
880  const unsigned int l1 = ::SysStringLen(m_wstr);
881  const unsigned int l2 = ::SysStringLen(str.m_wstr);
882 
883  unsigned int len = l1;
884  if (len > l2) {
885  len = l2;
886  }
887 
888  BSTR bstr1 = m_wstr;
889  BSTR bstr2 = str.m_wstr;
890 
891  while (len-- > 0) {
892  if (*bstr1++ != *bstr2++) {
893  return bstr1[-1] - bstr2[-1];
894  }
895  }
896 
897  return (l1 < l2) ? -1 : (l1 == l2) ? 0 : 1;
898 }
BSTR m_wstr
Definition: comutil.h:255
BSTR _bstr_t::Data_t::Copy ( ) const
inline
834 {
835  if (m_wstr != NULL) {
836  BSTR bstr = ::SysAllocStringByteLen(reinterpret_cast<char*>(m_wstr), ::SysStringByteLen(m_wstr));
837 
838  if (bstr == NULL) {
839  _com_issue_error(E_OUTOFMEMORY);
840  }
841 
842  return bstr;
843  }
844 
845  return NULL;
846 }
#define NULL
Definition: vcruntime.h:236
void __stdcall _com_issue_error(HRESULT)
BSTR m_wstr
Definition: comutil.h:255
const char * _bstr_t::Data_t::GetString ( ) const
inline
823 {
824  if (m_str == NULL) {
826  }
827 
828  return m_str;
829 }
#define NULL
Definition: vcruntime.h:236
char * m_str
Definition: comutil.h:256
BSTR m_wstr
Definition: comutil.h:255
char *__stdcall ConvertBSTRToString(BSTR pSrc)
const wchar_t * _bstr_t::Data_t::GetWString ( ) const
throw (
)
inline
813 {
814  return m_wstr;
815 }
BSTR m_wstr
Definition: comutil.h:255
wchar_t *& _bstr_t::Data_t::GetWString ( )
throw (
)
inline
818 {
819  return m_wstr;
820 }
BSTR m_wstr
Definition: comutil.h:255
unsigned int _bstr_t::Data_t::Length ( ) const
throw (
)
inline
870 {
871  return m_wstr ? ::SysStringLen(m_wstr) : 0;
872 }
BSTR m_wstr
Definition: comutil.h:255
_bstr_t::Data_t::operator const char * ( ) const
inline
802 {
803  return GetString();
804 }
const char * GetString() const
Definition: comutil.h:822
_bstr_t::Data_t::operator const wchar_t * ( ) const
throw (
)
inline
795 {
796  return m_wstr;
797 }
BSTR m_wstr
Definition: comutil.h:255
void * _bstr_t::Data_t::operator new ( size_t  sz)
inline
914 {
915  return ::operator new(sz);
916 }
unsigned long _bstr_t::Data_t::RefCount ( ) const
throw (
)
inline
782 {
783  return m_RefCount;
784 }
unsigned long m_RefCount
Definition: comutil.h:257
unsigned long _bstr_t::Data_t::Release ( )
throw (
)
inline
772 {
773  unsigned long cRef = InterlockedDecrement(reinterpret_cast<long*>(&m_RefCount));
774  if (cRef == 0) {
775  delete this;
776  }
777 
778  return cRef;
779 }
unsigned long m_RefCount
Definition: comutil.h:257

Member Data Documentation

unsigned long _bstr_t::Data_t::m_RefCount
private
char* _bstr_t::Data_t::m_str
mutableprivate
BSTR _bstr_t::Data_t::m_wstr
private

The documentation for this class was generated from the following file: