ReactOS  0.4.13-dev-241-g63286c6
atlstr.h
Go to the documentation of this file.
1 #ifndef __ATLSTR_H__
2 #define __ATLSTR_H__
3 
4 #pragma once
5 #include "atlbase.h"
6 #include "cstringt.h"
7 
8 namespace ATL
9 {
10 
12 {
13 protected:
16 
17 public:
19  m_MemMgr(MemMgr)
20  {
22  }
23 
24  virtual ~CAtlStringMgr(void)
25  {
26  }
27 
28  static IAtlStringMgr* GetInstance(void)
29  {
30  static CWin32Heap Win32Heap(::GetProcessHeap());
31  static CAtlStringMgr StringMgr(&Win32Heap);
32  return &StringMgr;
33  }
34 
36  _In_ int NumChars,
37  _In_ int CharSize)
38  {
39  size_t SizeBytes;
41 
42  SizeBytes = sizeof(CStringData) + ((NumChars + 1) * CharSize);
43 
44  StrData = static_cast<CStringData*>(m_MemMgr->Allocate(SizeBytes));
45  if (StrData == NULL) return NULL;
46 
48  StrData->nRefs = 1;
49  StrData->nAllocLength = NumChars;
51 
52  return StrData;
53  }
54 
55  virtual void Free(_In_ CStringData* StrData)
56  {
57  ATLASSERT(StrData->pStringMgr == this);
59  }
60 
63  _In_ int nChars,
64  _In_ int nCharSize) throw()
65  {
66  ATLASSERT(StrData->pStringMgr == this);
67 
68  CStringData* pNewData;
70  ULONG nDataBytes;
71 
72  nChars++;
73  nDataBytes = nChars * nCharSize;
74  SizeBytes = sizeof(CStringData) + nDataBytes;
75 
76  pNewData = static_cast<CStringData*>(m_MemMgr->Reallocate(StrData, SizeBytes));
77  if (pNewData == NULL) return NULL;
78 
79  pNewData->nAllocLength = nChars - 1;
80  return pNewData;
81  }
83  {
85  return &m_NilStrData;
86  }
87  virtual IAtlStringMgr* Clone() throw()
88  {
89  return this;
90  }
91 
92 private:
93  static bool StaticInitialize()
94  {
95  GetInstance();
96  return true;
97  }
98 };
99 
100 
101 template< typename _CharType = wchar_t >
102 class ChTraitsOS :
103  public ChTraitsBase < _CharType >
104 {
105 
106 };
107 
108 
109 template<typename _BaseType = wchar_t, class StringIterator = ChTraitsOS<_BaseType> >
110 class StrTraitATL :
111  public StringIterator
112 {
113 public:
115  {
116  return AtlFindStringResourceInstance(nID);
117  }
118 
120  {
122  }
123 };
124 
125 
128 
129 
132 
133 
134 #ifdef UNICODE
135 typedef CAtlStringW CAtlString;
136 typedef CStringW CString;
137 #else
140 #endif
141 
142 
143 }
144 
145 #endif
virtual ~CAtlStringMgr(void)
Definition: atlstr.h:24
#define ATLASSERT(x)
Definition: CComVariant.cpp:9
virtual _Ret_maybenull_ _Post_writable_byte_size_(sizeof(CStringData)+NumChars *CharSize) CStringData *Allocate(_In_ int NumChars
#define _Post_readable_byte_size_(size)
Definition: no_sal2.h:463
IAtlMemMgr * m_MemMgr
Definition: atlstr.h:14
_In_opt_ PALLOCATE_FUNCTION Allocate
Definition: exfuncs.h:656
#define _In_opt_
Definition: no_sal2.h:213
virtual void Free(_In_ CStringData *StrData)
Definition: atlstr.h:55
smooth NULL
Definition: ftsmooth.c:416
CStringT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t > > > CAtlStringW
Definition: atlstr.h:126
virtual _Ret_maybenull_ _In_ int _In_ int nCharSize throw()
Definition: atlstr.h:64
Definition: rosdlgs.h:5
CStringA CString
Definition: atlstr.h:139
#define GetProcessHeap()
Definition: compat.h:395
HINSTANCE AtlFindStringResourceInstance(UINT nID, WORD wLanguage=0)
Definition: atlcore.h:294
virtual _Ret_maybenull_ _In_ int nCharSize
Definition: atlsimpstr.h:24
virtual void Free(_Inout_opt_ void *Buffer)=0
#define _Ret_maybenull_
Definition: no_sal2.h:590
static HINSTANCE FindStringResourceInstance(_In_ UINT nID)
Definition: atlstr.h:114
#define _Inout_
Definition: no_sal2.h:244
void SetManager(_In_ IAtlStringMgr *pMgr)
Definition: atlsimpstr.h:95
virtual _Ret_maybenull_ _In_ int nChars
Definition: atlstr.h:63
virtual _Ret_maybenull_ _In_ int CharSize
Definition: atlstr.h:38
CAtlStringA CAtlString
Definition: atlstr.h:138
virtual IAtlStringMgr * Clone()
Definition: atlstr.h:87
static IAtlStringMgr * GetDefaultManager()
Definition: atlstr.h:119
#define _In_
Definition: no_sal2.h:204
CNilStringData m_NilStrData
Definition: atlstr.h:15
CAtlStringA CStringA
Definition: atlstr.h:131
CStringT< char, StrTraitATL< char, ChTraitsCRT< char > > > CAtlStringA
Definition: atlstr.h:127
unsigned int UINT
Definition: ndis.h:50
static bool StaticInitialize()
Definition: atlstr.h:93
IAtlStringMgr * pStringMgr
Definition: atlsimpstr.h:44
unsigned int ULONG
Definition: retypes.h:1
return StrData
Definition: atlstr.h:52
CAtlStringW CStringW
Definition: atlstr.h:130
CAtlStringMgr(_In_opt_ IAtlMemMgr *MemMgr=NULL)
Definition: atlstr.h:18
static IAtlStringMgr * GetInstance(void)
Definition: atlstr.h:28
virtual CStringData * GetNilString()
Definition: atlstr.h:82
CStringData * StrData
Definition: atlstr.h:40