Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: core/include/fxcrt/fx_basic.h

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_INCLUDE_FXCRT_FX_BASIC_H_ 7 #ifndef CORE_INCLUDE_FXCRT_FX_BASIC_H_
8 #define CORE_INCLUDE_FXCRT_FX_BASIC_H_ 8 #define CORE_INCLUDE_FXCRT_FX_BASIC_H_
9 9
10 #include "fx_memory.h" 10 #include "fx_memory.h"
11 #include "fx_stream.h" 11 #include "fx_stream.h"
12 #include "fx_string.h" 12 #include "fx_string.h"
13 #include "fx_system.h" 13 #include "fx_system.h"
14 14
15 // The FX_ArraySize(arr) macro returns the # of elements in an array arr. 15 // The FX_ArraySize(arr) macro returns the # of elements in an array arr.
16 // The expression is a compile-time constant, and therefore can be 16 // The expression is a compile-time constant, and therefore can be
17 // used in defining new arrays, for example. If you use FX_ArraySize on 17 // used in defining new arrays, for example. If you use FX_ArraySize on
18 // a pointer by mistake, you will get a compile-time error. 18 // a pointer by mistake, you will get a compile-time error.
19 // 19 //
20 // One caveat is that FX_ArraySize() doesn't accept any array of an 20 // One caveat is that FX_ArraySize() doesn't accept any array of an
21 // anonymous type or a type defined inside a function. 21 // anonymous type or a type defined inside a function.
22 #define FX_ArraySize(array) (sizeof(ArraySizeHelper(array))) 22 #define FX_ArraySize(array) (sizeof(ArraySizeHelper(array)))
23 23
24 // This template function declaration is used in defining FX_ArraySize. 24 // This template function declaration is used in defining FX_ArraySize.
25 // Note that the function doesn't need an implementation, as we only 25 // Note that the function doesn't need an implementation, as we only
26 // use its type. 26 // use its type.
27 template <typename T, size_t N> 27 template <typename T, size_t N>
28 char (&ArraySizeHelper(T (&array)[N]))[N]; 28 char(&ArraySizeHelper(T(&array)[N]))[N];
29 29
30 class CFX_BinaryBuf 30 class CFX_BinaryBuf {
31 { 31 public:
32 public: 32 CFX_BinaryBuf();
33 CFX_BinaryBuf(); 33 CFX_BinaryBuf(FX_STRSIZE size);
34 CFX_BinaryBuf(FX_STRSIZE size); 34
35 35 ~CFX_BinaryBuf();
36 ~CFX_BinaryBuf(); 36
37 37 void Clear();
38 void» » » » » Clear(); 38
39 39 void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0);
40 void» » » » » EstimateSize(FX_STRSIZE size, FX _STRSIZE alloc_step = 0); 40
41 41 void AppendBlock(const void* pBuf, FX_STRSIZE size);
42 void» » » » » AppendBlock(const void* pBuf, FX _STRSIZE size); 42
43 43 void AppendFill(uint8_t byte, FX_STRSIZE count);
44 void» » » » » AppendFill(uint8_t byte, FX_STRS IZE count); 44
45 45 void AppendString(const CFX_ByteStringC& str) {
46 void» » » » » AppendString(const CFX_ByteStrin gC& str) 46 AppendBlock(str.GetPtr(), str.GetLength());
47 { 47 }
48 AppendBlock(str.GetPtr(), str.GetLength()); 48
49 } 49 inline void AppendByte(uint8_t byte) {
50 50 if (m_AllocSize <= m_DataSize) {
51 inline void»» » » AppendByte(uint8_t byte) 51 ExpandBuf(1);
52 { 52 }
53 if (m_AllocSize <= m_DataSize) { 53 m_pBuffer[m_DataSize++] = byte;
54 ExpandBuf(1); 54 }
55 } 55
56 m_pBuffer[m_DataSize++] = byte; 56 void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size);
57 } 57
58 58 void AttachData(void* pBuf, FX_STRSIZE size);
59 void» » » » » InsertBlock(FX_STRSIZE pos, cons t void* pBuf, FX_STRSIZE size); 59
60 60 void CopyData(const void* pBuf, FX_STRSIZE size);
61 void» » » » » AttachData(void* pBuf, FX_STRSIZ E size); 61
62 62 void TakeOver(CFX_BinaryBuf& other);
63 void» » » » » CopyData(const void* pBuf, FX_ST RSIZE size); 63
64 64 void Delete(int start_index, int count);
65 void» » » » » TakeOver(CFX_BinaryBuf& other); 65
66 66 uint8_t* GetBuffer() const { return m_pBuffer; }
67 void» » » » » Delete(int start_index, int coun t); 67
68 68 FX_STRSIZE GetSize() const { return m_DataSize; }
69 uint8_t*» » » » GetBuffer() const 69
70 { 70 CFX_ByteStringC GetByteString() const;
71 return m_pBuffer; 71
72 } 72 void DetachBuffer();
73 73
74 FX_STRSIZE» » » » GetSize() const 74 protected:
75 { 75 FX_STRSIZE m_AllocStep;
76 return m_DataSize; 76
77 } 77 uint8_t* m_pBuffer;
78 78
79 CFX_ByteStringC» » » GetByteString() const; 79 FX_STRSIZE m_DataSize;
80 80
81 void» » » » » DetachBuffer(); 81 FX_STRSIZE m_AllocSize;
82 protected: 82
83 83 void ExpandBuf(FX_STRSIZE size);
84 FX_STRSIZE» » » » m_AllocStep; 84 };
85 85 class CFX_ByteTextBuf : public CFX_BinaryBuf {
86 uint8_t*» » » » m_pBuffer; 86 public:
87 87 void operator=(const CFX_ByteStringC& str);
88 FX_STRSIZE» » » » m_DataSize; 88
89 89 void AppendChar(int ch) { AppendByte((uint8_t)ch); }
90 FX_STRSIZE» » » » m_AllocSize; 90
91 91 CFX_ByteTextBuf& operator<<(int i);
92 void» » » » » ExpandBuf(FX_STRSIZE size); 92
93 }; 93 CFX_ByteTextBuf& operator<<(FX_DWORD i);
94 class CFX_ByteTextBuf : public CFX_BinaryBuf 94
95 { 95 CFX_ByteTextBuf& operator<<(double f);
96 public: 96
97 97 CFX_ByteTextBuf& operator<<(const CFX_ByteStringC& lpsz);
98 void» » » » » operator = (const CFX_ByteString C& str); 98
99 99 CFX_ByteTextBuf& operator<<(const CFX_ByteTextBuf& buf);
100 void» » » » » AppendChar(int ch) 100
101 { 101 FX_STRSIZE GetLength() const { return m_DataSize; }
102 AppendByte((uint8_t)ch); 102 };
103 } 103 class CFX_WideTextBuf : public CFX_BinaryBuf {
104 104 public:
105 CFX_ByteTextBuf&» » operator << (int i); 105 void operator=(const FX_WCHAR* lpsz);
106 106
107 CFX_ByteTextBuf&» » operator << (FX_DWORD i); 107 void operator=(const CFX_WideStringC& str);
108 108
109 CFX_ByteTextBuf&» » operator << (double f); 109 void AppendChar(FX_WCHAR wch);
110 110
111 CFX_ByteTextBuf&» » operator << (const CFX_ByteStringC& lpsz); 111 CFX_WideTextBuf& operator<<(int i);
112 112
113 CFX_ByteTextBuf&» » operator << (const CFX_ByteTextBuf& buf); 113 CFX_WideTextBuf& operator<<(double f);
114 114
115 FX_STRSIZE» » » » GetLength() const 115 CFX_WideTextBuf& operator<<(const FX_WCHAR* lpsz);
116 { 116
117 return m_DataSize; 117 CFX_WideTextBuf& operator<<(const CFX_WideStringC& str);
118 } 118 CFX_WideTextBuf& operator<<(const CFX_WideString& str);
119 }; 119
120 class CFX_WideTextBuf : public CFX_BinaryBuf 120 CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf);
121 { 121
122 public: 122 FX_STRSIZE GetLength() const { return m_DataSize / sizeof(FX_WCHAR); }
123 123
124 void» » » » » operator = (const FX_WCHAR* lpsz ); 124 FX_WCHAR* GetBuffer() const { return (FX_WCHAR*)m_pBuffer; }
125 125
126 void» » » » » operator = (const CFX_WideString C& str); 126 void Delete(int start_index, int count) {
127 127 CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR),
128 void» » » » » AppendChar(FX_WCHAR wch); 128 count * sizeof(FX_WCHAR));
129 129 }
130 CFX_WideTextBuf&» » operator << (int i); 130
131 131 CFX_WideStringC GetWideString() const;
132 CFX_WideTextBuf&» » operator << (double f); 132 };
133 133
134 CFX_WideTextBuf&» » operator << (const FX_WCHAR* lpsz); 134 class IFX_BufferArchive {
135 135 public:
136 CFX_WideTextBuf&» » operator << (const CFX_WideStringC& str); 136 IFX_BufferArchive(FX_STRSIZE size);
137 CFX_WideTextBuf&» » operator << (const CFX_WideString &str); 137 virtual ~IFX_BufferArchive() {}
138 138
139 CFX_WideTextBuf&» » operator << (const CFX_WideTextBuf& buf); 139 virtual void Clear();
140 140
141 FX_STRSIZE» » » » GetLength() const 141 FX_BOOL Flush();
142 { 142
143 return m_DataSize / sizeof(FX_WCHAR); 143 int32_t AppendBlock(const void* pBuf, size_t size);
144 } 144
145 145 int32_t AppendByte(uint8_t byte);
146 FX_WCHAR*» » » » GetBuffer() const 146
147 { 147 int32_t AppendDWord(FX_DWORD i);
148 return (FX_WCHAR*)m_pBuffer; 148
149 } 149 int32_t AppendString(const CFX_ByteStringC& lpsz);
150 150
151 void» » » » » Delete(int start_index, int coun t) 151 protected:
152 { 152 virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0;
153 CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_ WCHAR)); 153
154 } 154 FX_STRSIZE m_BufSize;
155 155
156 CFX_WideStringC» » » GetWideString() const; 156 uint8_t* m_pBuffer;
157 }; 157
158 158 FX_STRSIZE m_Length;
159 class IFX_BufferArchive 159 };
160 { 160
161 public: 161 class CFX_FileBufferArchive : public IFX_BufferArchive {
162 IFX_BufferArchive(FX_STRSIZE size); 162 public:
163 virtual ~IFX_BufferArchive() {} 163 CFX_FileBufferArchive(FX_STRSIZE size = 32768);
164 164 ~CFX_FileBufferArchive() override;
165 virtual void Clear(); 165
166 166 void Clear() override;
167 FX_BOOL Flush(); 167
168 168 FX_BOOL AttachFile(IFX_StreamWrite* pFile, FX_BOOL bTakeover = FALSE);
169 int32_t AppendBlock(const void* pBuf, size_t size); 169
170 170 FX_BOOL AttachFile(const FX_WCHAR* filename);
171 int32_t AppendByte(uint8_t byte); 171
172 172 FX_BOOL AttachFile(const FX_CHAR* filename);
173 int32_t AppendDWord(FX_DWORD i); 173
174 174 private:
175 175 FX_BOOL DoWork(const void* pBuf, size_t size) override;
176 int32_t AppendString(const CFX_ByteStringC& lpsz); 176
177 177 IFX_StreamWrite* m_pFile;
178 protected: 178
179 179 FX_BOOL m_bTakeover;
180 virtual FX_BOOL DoWork(const void* pBuf, size_t size) = 0;
181
182 FX_STRSIZE m_BufSize;
183
184 uint8_t* m_pBuffer;
185
186 FX_STRSIZE m_Length;
187 };
188
189 class CFX_FileBufferArchive : public IFX_BufferArchive
190 {
191 public:
192 CFX_FileBufferArchive(FX_STRSIZE size = 32768);
193 ~CFX_FileBufferArchive() override;
194
195 void Clear() override;
196
197 FX_BOOL AttachFile(IFX_StreamWrite *pFile, FX_BOOL bTakeover = FALSE);
198
199 FX_BOOL AttachFile(const FX_WCHAR* filename);
200
201 FX_BOOL AttachFile(const FX_CHAR* filename);
202
203 private:
204 FX_BOOL DoWork(const void* pBuf, size_t size) override;
205
206 IFX_StreamWrite* m_pFile;
207
208 FX_BOOL m_bTakeover;
209 }; 180 };
210 181
211 struct CFX_CharMap { 182 struct CFX_CharMap {
212 183 static CFX_CharMap* GetDefaultMapper(int32_t codepage = 0);
213 static CFX_CharMap*»» GetDefaultMapper(int32_t codepage = 0); 184
214 185 CFX_WideString (*m_GetWideString)(CFX_CharMap* pMap,
215 186 const CFX_ByteString& bstr);
216 CFX_WideString» (*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteStri ng& bstr); 187
217 188 CFX_ByteString (*m_GetByteString)(CFX_CharMap* pMap,
218 CFX_ByteString» (*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideStri ng& wstr); 189 const CFX_WideString& wstr);
219 190
220 int32_t» » (*m_GetCodePage)(); 191 int32_t (*m_GetCodePage)();
221 }; 192 };
222 class CFX_UTF8Decoder 193 class CFX_UTF8Decoder {
223 { 194 public:
224 public: 195 CFX_UTF8Decoder() { m_PendingBytes = 0; }
225 CFX_UTF8Decoder() 196
226 { 197 void Clear();
227 m_PendingBytes = 0; 198
228 } 199 void Input(uint8_t byte);
229 200
230 void» » » Clear(); 201 void AppendChar(FX_DWORD ch);
231 202
232 void» » » Input(uint8_t byte); 203 void ClearStatus() { m_PendingBytes = 0; }
233 204
234 void» » » AppendChar(FX_DWORD ch); 205 CFX_WideStringC GetResult() const { return m_Buffer.GetWideString(); }
235 206
236 void» » » ClearStatus() 207 protected:
237 { 208 int m_PendingBytes;
238 m_PendingBytes = 0; 209
239 } 210 FX_DWORD m_PendingChar;
240 211
241 CFX_WideStringC» GetResult() const 212 CFX_WideTextBuf m_Buffer;
242 { 213 };
243 return m_Buffer.GetWideString(); 214 class CFX_UTF8Encoder {
244 } 215 public:
245 protected: 216 CFX_UTF8Encoder() { m_UTF16First = 0; }
246 217
247 int»» » » m_PendingBytes; 218 void Input(FX_WCHAR unicode);
248 219
249 FX_DWORD» » m_PendingChar; 220 void AppendStr(const CFX_ByteStringC& str) {
250 221 m_UTF16First = 0;
251 CFX_WideTextBuf» m_Buffer; 222 m_Buffer << str;
252 }; 223 }
253 class CFX_UTF8Encoder 224
254 { 225 CFX_ByteStringC GetResult() const { return m_Buffer.GetByteString(); }
255 public: 226
256 CFX_UTF8Encoder() 227 protected:
257 { 228 CFX_ByteTextBuf m_Buffer;
258 m_UTF16First = 0; 229
259 } 230 FX_DWORD m_UTF16First;
260
261 void» » » Input(FX_WCHAR unicode);
262
263 void» » » AppendStr(const CFX_ByteStringC& str)
264 {
265 m_UTF16First = 0;
266 m_Buffer << str;
267 }
268
269 CFX_ByteStringC» GetResult() const
270 {
271 return m_Buffer.GetByteString();
272 }
273 protected:
274
275 CFX_ByteTextBuf» m_Buffer;
276
277 FX_DWORD» » m_UTF16First;
278 }; 231 };
279 CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl); 232 CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl);
280 CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl); 233 CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl);
281 CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI); 234 CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI);
282 CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI); 235 CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI);
283 class CFX_BasicArray 236 class CFX_BasicArray {
284 { 237 protected:
285 protected: 238 CFX_BasicArray(int unit_size);
286 CFX_BasicArray(int unit_size); 239
287 240 ~CFX_BasicArray();
288 ~CFX_BasicArray(); 241
289 242 FX_BOOL SetSize(int nNewSize);
290 FX_BOOL» » » SetSize(int nNewSize); 243
291 244 FX_BOOL Append(const CFX_BasicArray& src);
292 FX_BOOL» » » Append(const CFX_BasicArray& src); 245
293 246 FX_BOOL Copy(const CFX_BasicArray& src);
294 FX_BOOL» » » Copy(const CFX_BasicArray& src); 247
295 248 uint8_t* InsertSpaceAt(int nIndex, int nCount);
296 uint8_t*» » InsertSpaceAt(int nIndex, int nCount); 249
297 250 FX_BOOL RemoveAt(int nIndex, int nCount);
298 FX_BOOL» » » RemoveAt(int nIndex, int nCount); 251
299 252 FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray);
300 FX_BOOL» » » InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray); 253
301 254 const void* GetDataPtr(int index) const;
302 const void*»» GetDataPtr(int index) const; 255
303 protected: 256 protected:
304 257 uint8_t* m_pData;
305 uint8_t*» » m_pData; 258
306 259 int m_nSize;
307 int»» » » m_nSize; 260
308 261 int m_nMaxSize;
309 int»» » » m_nMaxSize; 262
310 263 int m_nUnitSize;
311 int»» » » m_nUnitSize; 264 };
312 }; 265 template <class TYPE>
313 template<class TYPE> 266 class CFX_ArrayTemplate : public CFX_BasicArray {
314 class CFX_ArrayTemplate : public CFX_BasicArray 267 public:
315 { 268 CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {}
316 public: 269
317 CFX_ArrayTemplate() : CFX_BasicArray(sizeof(TYPE)) {} 270 int GetSize() const { return m_nSize; }
318 271
319 int»» » GetSize() const 272 int GetUpperBound() const { return m_nSize - 1; }
320 { 273
321 return m_nSize; 274 FX_BOOL SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); }
322 } 275
323 276 void RemoveAll() { SetSize(0); }
324 int»» » GetUpperBound() const 277
325 { 278 const TYPE GetAt(int nIndex) const {
326 return m_nSize - 1; 279 if (nIndex < 0 || nIndex >= m_nSize) {
327 } 280 return (const TYPE&)(*(volatile const TYPE*)NULL);
328 281 }
329 FX_BOOL» » SetSize(int nNewSize) 282 return ((const TYPE*)m_pData)[nIndex];
330 { 283 }
331 return CFX_BasicArray::SetSize(nNewSize); 284
332 } 285 FX_BOOL SetAt(int nIndex, TYPE newElement) {
333 286 if (nIndex < 0 || nIndex >= m_nSize) {
334 void» » RemoveAll() 287 return FALSE;
335 { 288 }
336 SetSize(0); 289 ((TYPE*)m_pData)[nIndex] = newElement;
337 } 290 return TRUE;
338 291 }
339 const TYPE» GetAt(int nIndex) const 292
340 { 293 TYPE& ElementAt(int nIndex) {
341 if (nIndex < 0 || nIndex >= m_nSize) { 294 if (nIndex < 0 || nIndex >= m_nSize) {
342 return (const TYPE&)(*(volatile const TYPE*)NULL); 295 return *(TYPE*)NULL;
343 } 296 }
344 return ((const TYPE*)m_pData)[nIndex]; 297 return ((TYPE*)m_pData)[nIndex];
345 } 298 }
346 299
347 FX_BOOL» » SetAt(int nIndex, TYPE newElement) 300 const TYPE* GetData() const { return (const TYPE*)m_pData; }
348 { 301
349 if (nIndex < 0 || nIndex >= m_nSize) { 302 TYPE* GetData() { return (TYPE*)m_pData; }
350 return FALSE; 303
351 } 304 FX_BOOL SetAtGrow(int nIndex, TYPE newElement) {
352 ((TYPE*)m_pData)[nIndex] = newElement; 305 if (nIndex < 0) {
353 return TRUE; 306 return FALSE;
354 } 307 }
355 308 if (nIndex >= m_nSize)
356 TYPE&» » ElementAt(int nIndex) 309 if (!SetSize(nIndex + 1)) {
357 { 310 return FALSE;
358 if (nIndex < 0 || nIndex >= m_nSize) { 311 }
359 return *(TYPE*)NULL; 312 ((TYPE*)m_pData)[nIndex] = newElement;
360 } 313 return TRUE;
361 return ((TYPE*)m_pData)[nIndex]; 314 }
362 } 315
363 316 FX_BOOL Add(TYPE newElement) {
364 const TYPE*»GetData() const 317 if (m_nSize < m_nMaxSize) {
365 { 318 m_nSize++;
366 return (const TYPE*)m_pData; 319 } else if (!SetSize(m_nSize + 1)) {
367 } 320 return FALSE;
368 321 }
369 TYPE*» » GetData() 322 ((TYPE*)m_pData)[m_nSize - 1] = newElement;
370 { 323 return TRUE;
371 return (TYPE*)m_pData; 324 }
372 } 325
373 326 FX_BOOL Append(const CFX_ArrayTemplate& src) {
374 FX_BOOL» » SetAtGrow(int nIndex, TYPE newElement) 327 return CFX_BasicArray::Append(src);
375 { 328 }
376 if (nIndex < 0) { 329
377 return FALSE; 330 FX_BOOL Copy(const CFX_ArrayTemplate& src) {
378 } 331 return CFX_BasicArray::Copy(src);
379 if (nIndex >= m_nSize) 332 }
380 if (!SetSize(nIndex + 1)) { 333
381 return FALSE; 334 TYPE* GetDataPtr(int index) {
382 } 335 return (TYPE*)CFX_BasicArray::GetDataPtr(index);
383 ((TYPE*)m_pData)[nIndex] = newElement; 336 }
384 return TRUE; 337
385 } 338 TYPE* AddSpace() { return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); }
386 339
387 FX_BOOL» » Add(TYPE newElement) 340 TYPE* InsertSpaceAt(int nIndex, int nCount) {
388 { 341 return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount);
389 if (m_nSize < m_nMaxSize) { 342 }
390 m_nSize ++; 343
391 } else if (!SetSize(m_nSize + 1)) { 344 const TYPE operator[](int nIndex) const {
392 return FALSE; 345 if (nIndex < 0 || nIndex >= m_nSize) {
393 } 346 *(volatile char*)0 = '\0';
394 ((TYPE*)m_pData)[m_nSize - 1] = newElement; 347 }
395 return TRUE; 348 return ((const TYPE*)m_pData)[nIndex];
396 } 349 }
397 350
398 FX_BOOL» » Append(const CFX_ArrayTemplate& src) 351 TYPE& operator[](int nIndex) {
399 { 352 if (nIndex < 0 || nIndex >= m_nSize) {
400 return CFX_BasicArray::Append(src); 353 *(volatile char*)0 = '\0';
401 } 354 }
402 355 return ((TYPE*)m_pData)[nIndex];
403 FX_BOOL» » Copy(const CFX_ArrayTemplate& src) 356 }
404 { 357
405 return CFX_BasicArray::Copy(src); 358 FX_BOOL InsertAt(int nIndex, TYPE newElement, int nCount = 1) {
406 } 359 if (!InsertSpaceAt(nIndex, nCount)) {
407 360 return FALSE;
408 TYPE*» » GetDataPtr(int index) 361 }
409 { 362 while (nCount--) {
410 return (TYPE*)CFX_BasicArray::GetDataPtr(index); 363 ((TYPE*)m_pData)[nIndex++] = newElement;
411 } 364 }
412 365 return TRUE;
413 TYPE*» » AddSpace() 366 }
414 { 367
415 return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1); 368 FX_BOOL RemoveAt(int nIndex, int nCount = 1) {
416 } 369 return CFX_BasicArray::RemoveAt(nIndex, nCount);
417 370 }
418 TYPE*» » InsertSpaceAt(int nIndex, int nCount) 371
419 { 372 FX_BOOL InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray) {
420 return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount); 373 return CFX_BasicArray::InsertAt(nStartIndex, pNewArray);
421 } 374 }
422 375
423 const TYPE» operator[](int nIndex) const 376 int Find(TYPE data, int iStart = 0) const {
424 { 377 if (iStart < 0) {
425 if (nIndex < 0 || nIndex >= m_nSize) { 378 return -1;
426 *(volatile char*)0 = '\0'; 379 }
427 } 380 for (; iStart < (int)m_nSize; iStart++)
428 return ((const TYPE*)m_pData)[nIndex]; 381 if (((TYPE*)m_pData)[iStart] == data) {
429 } 382 return iStart;
430 383 }
431 TYPE&» » operator[](int nIndex) 384 return -1;
432 { 385 }
433 if (nIndex < 0 || nIndex >= m_nSize) { 386 };
434 *(volatile char*)0 = '\0'; 387 typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray;
435 } 388 typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray;
436 return ((TYPE*)m_pData)[nIndex]; 389 typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray;
437 } 390 typedef CFX_ArrayTemplate<void*> CFX_PtrArray;
438 391 typedef CFX_ArrayTemplate<FX_FILESIZE> CFX_FileSizeArray;
439 FX_BOOL» » InsertAt(int nIndex, TYPE newElement, int nCount = 1) 392 typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray;
440 { 393 typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array;
441 if (!InsertSpaceAt(nIndex, nCount)) {
442 return FALSE;
443 }
444 while (nCount--) {
445 ((TYPE*)m_pData)[nIndex++] = newElement;
446 }
447 return TRUE;
448 }
449
450 FX_BOOL» » RemoveAt(int nIndex, int nCount = 1)
451 {
452 return CFX_BasicArray::RemoveAt(nIndex, nCount);
453 }
454
455 FX_BOOL» » InsertAt(int nStartIndex, const CFX_BasicArray* pNewArra y)
456 {
457 return CFX_BasicArray::InsertAt(nStartIndex, pNewArray);
458 }
459
460 int»» » Find(TYPE data, int iStart = 0) const
461 {
462 if (iStart < 0) {
463 return -1;
464 }
465 for (; iStart < (int)m_nSize; iStart ++)
466 if (((TYPE*)m_pData)[iStart] == data) {
467 return iStart;
468 }
469 return -1;
470 }
471 };
472 typedef CFX_ArrayTemplate<uint8_t>» » CFX_ByteArray;
473 typedef CFX_ArrayTemplate<FX_WORD>» » CFX_WordArray;
474 typedef CFX_ArrayTemplate<FX_DWORD>» » CFX_DWordArray;
475 typedef CFX_ArrayTemplate<void*>» » CFX_PtrArray;
476 typedef CFX_ArrayTemplate<FX_FILESIZE>» CFX_FileSizeArray;
477 typedef CFX_ArrayTemplate<FX_FLOAT>» » CFX_FloatArray;
478 typedef CFX_ArrayTemplate<int32_t>» » CFX_Int32Array;
479 template <class ObjectClass> 394 template <class ObjectClass>
480 class CFX_ObjectArray : public CFX_BasicArray 395 class CFX_ObjectArray : public CFX_BasicArray {
481 { 396 public:
482 public: 397 CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {}
483 CFX_ObjectArray() : CFX_BasicArray(sizeof(ObjectClass)) {} 398
484 399 ~CFX_ObjectArray() { RemoveAll(); }
485 ~CFX_ObjectArray() 400
486 { 401 void Add(const ObjectClass& data) {
487 RemoveAll(); 402 new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data);
488 } 403 }
489 404
490 void» » » Add(const ObjectClass& data) 405 ObjectClass& Add() {
491 { 406 return *(ObjectClass*)new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass();
492 new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data); 407 }
493 } 408
494 409 void* AddSpace() { return InsertSpaceAt(m_nSize, 1); }
495 ObjectClass&» Add() 410
496 { 411 int32_t Append(const CFX_ObjectArray& src,
497 return *(ObjectClass*) new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClas s(); 412 int32_t nStart = 0,
498 } 413 int32_t nCount = -1) {
499 414 if (nCount == 0) {
500 void*» » » AddSpace() 415 return 0;
501 { 416 }
502 return InsertSpaceAt(m_nSize, 1); 417 int32_t nSize = src.GetSize();
503 } 418 if (!nSize) {
504 419 return 0;
505 int32_t» » Append(const CFX_ObjectArray& src, int32_t nStart = 0, i nt32_t nCount = -1) 420 }
506 { 421 FXSYS_assert(nStart > -1 && nStart < nSize);
507 if (nCount == 0) { 422 if (nCount < 0) {
508 return 0; 423 nCount = nSize;
509 } 424 }
510 int32_t nSize = src.GetSize(); 425 if (nStart + nCount > nSize) {
511 if (!nSize) { 426 nCount = nSize - nStart;
512 return 0; 427 }
513 } 428 if (nCount < 1) {
514 FXSYS_assert(nStart > -1 && nStart < nSize); 429 return 0;
515 if (nCount < 0) { 430 }
516 nCount = nSize; 431 nSize = m_nSize;
517 } 432 InsertSpaceAt(m_nSize, nCount);
518 if (nStart + nCount > nSize) { 433 ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize);
519 nCount = nSize - nStart; 434 nSize = nStart + nCount;
520 } 435 for (int32_t i = nStart; i < nSize; i++, pStartObj++) {
521 if (nCount < 1) { 436 new ((void*)pStartObj) ObjectClass(src[i]);
522 return 0; 437 }
523 } 438 return nCount;
524 nSize = m_nSize; 439 }
525 InsertSpaceAt(m_nSize, nCount); 440
526 ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize); 441 int32_t Copy(const CFX_ObjectArray& src,
527 nSize = nStart + nCount; 442 int32_t nStart = 0,
528 for (int32_t i = nStart; i < nSize; i ++, pStartObj++) { 443 int32_t nCount = -1) {
529 new ((void*)pStartObj) ObjectClass(src[i]); 444 if (nCount == 0) {
530 } 445 return 0;
531 return nCount; 446 }
532 } 447 int32_t nSize = src.GetSize();
533 448 if (!nSize) {
534 int32_t» » Copy(const CFX_ObjectArray& src, int32_t nStart = 0, int 32_t nCount = -1) 449 return 0;
535 { 450 }
536 if (nCount == 0) { 451 FXSYS_assert(nStart > -1 && nStart < nSize);
537 return 0; 452 if (nCount < 0) {
538 } 453 nCount = nSize;
539 int32_t nSize = src.GetSize(); 454 }
540 if (!nSize) { 455 if (nStart + nCount > nSize) {
541 return 0; 456 nCount = nSize - nStart;
542 } 457 }
543 FXSYS_assert(nStart > -1 && nStart < nSize); 458 if (nCount < 1) {
544 if (nCount < 0) { 459 return 0;
545 nCount = nSize; 460 }
546 } 461 RemoveAll();
547 if (nStart + nCount > nSize) { 462 SetSize(nCount);
548 nCount = nSize - nStart; 463 ObjectClass* pStartObj = (ObjectClass*)m_pData;
549 } 464 nSize = nStart + nCount;
550 if (nCount < 1) { 465 for (int32_t i = nStart; i < nSize; i++, pStartObj++) {
551 return 0; 466 new ((void*)pStartObj) ObjectClass(src[i]);
552 } 467 }
553 RemoveAll(); 468 return nCount;
554 SetSize(nCount); 469 }
555 ObjectClass* pStartObj = (ObjectClass*)m_pData; 470
556 nSize = nStart + nCount; 471 int GetSize() const { return m_nSize; }
557 for (int32_t i = nStart; i < nSize; i ++, pStartObj++) { 472
558 new ((void*)pStartObj) ObjectClass(src[i]); 473 ObjectClass& operator[](int index) const {
559 } 474 FXSYS_assert(index < m_nSize);
560 return nCount; 475 return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index);
561 } 476 }
562 477
563 int»» » » GetSize() const 478 ObjectClass* GetDataPtr(int index) {
564 { 479 return (ObjectClass*)CFX_BasicArray::GetDataPtr(index);
565 return m_nSize; 480 }
566 } 481
567 482 void RemoveAt(int index) {
568 ObjectClass&» operator[] (int index) const 483 FXSYS_assert(index < m_nSize);
569 { 484 ((ObjectClass*)GetDataPtr(index))->~ObjectClass();
570 FXSYS_assert(index < m_nSize); 485 CFX_BasicArray::RemoveAt(index, 1);
571 return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index); 486 }
572 } 487
573 488 void RemoveAll() {
574 ObjectClass*» GetDataPtr(int index) 489 for (int i = 0; i < m_nSize; i++) {
575 { 490 ((ObjectClass*)GetDataPtr(i))->~ObjectClass();
576 return (ObjectClass*)CFX_BasicArray::GetDataPtr(index); 491 }
577 } 492 CFX_BasicArray::SetSize(0);
578 493 }
579 void» » » RemoveAt(int index)
580 {
581 FXSYS_assert(index < m_nSize);
582 ((ObjectClass*)GetDataPtr(index))->~ObjectClass();
583 CFX_BasicArray::RemoveAt(index, 1);
584 }
585
586 void» » » RemoveAll()
587 {
588 for (int i = 0; i < m_nSize; i ++) {
589 ((ObjectClass*)GetDataPtr(i))->~ObjectClass();
590 }
591 CFX_BasicArray::SetSize(0);
592 }
593 }; 494 };
594 typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray; 495 typedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray;
595 typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray; 496 typedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray;
596 class CFX_BaseSegmentedArray 497 class CFX_BaseSegmentedArray {
597 { 498 public:
598 public: 499 CFX_BaseSegmentedArray(int unit_size = 1,
599 CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index _size = 8); 500 int segment_units = 512,
600 501 int index_size = 8);
601 ~CFX_BaseSegmentedArray(); 502
602 503 ~CFX_BaseSegmentedArray();
603 void» SetUnitSize(int unit_size, int segment_units, int index_size = 8 ); 504
604 505 void SetUnitSize(int unit_size, int segment_units, int index_size = 8);
605 void*» Add(); 506
606 507 void* Add();
607 void*» GetAt(int index) const; 508
608 509 void* GetAt(int index) const;
609 void» RemoveAll(); 510
610 511 void RemoveAll();
611 void» Delete(int index, int count = 1); 512
612 513 void Delete(int index, int count = 1);
613 int»» GetSize() const 514
614 { 515 int GetSize() const { return m_DataSize; }
615 return m_DataSize; 516
616 } 517 int GetSegmentSize() const { return m_SegmentSize; }
617 518
618 int»» GetSegmentSize() const 519 int GetUnitSize() const { return m_UnitSize; }
619 { 520
620 return m_SegmentSize; 521 void* Iterate(FX_BOOL (*callback)(void* param, void* pData),
621 } 522 void* param) const;
622 523
623 int»» GetUnitSize() const 524 private:
624 { 525 int m_UnitSize;
625 return m_UnitSize; 526
626 } 527 short m_SegmentSize;
627 528
628 void*» Iterate(FX_BOOL (*callback)(void* param, void* pData), void* par am) const; 529 uint8_t m_IndexSize;
629 private: 530
630 531 uint8_t m_IndexDepth;
631 int»» » » m_UnitSize; 532
632 533 int m_DataSize;
633 short» » » m_SegmentSize; 534
634 535 void* m_pIndex;
635 uint8_t» » » m_IndexSize; 536 void** GetIndex(int seg_index) const;
636 537 void* IterateIndex(int level,
637 uint8_t» » » m_IndexDepth; 538 int& start,
638 539 void** pIndex,
639 int»» » » m_DataSize; 540 FX_BOOL (*callback)(void* param, void* pData),
640 541 void* param) const;
641 void*» » » m_pIndex; 542 void* IterateSegment(const uint8_t* pSegment,
642 void**» GetIndex(int seg_index) const; 543 int count,
643 void*» IterateIndex(int level, int& start, void** pIndex, FX_BOOL (*cal lback)(void* param, void* pData), void* param) const; 544 FX_BOOL (*callback)(void* param, void* pData),
644 void*» IterateSegment(const uint8_t* pSegment, int count, FX_BOOL (*cal lback)(void* param, void* pData), void* param) const; 545 void* param) const;
645 }; 546 };
646 template <class ElementType> 547 template <class ElementType>
647 class CFX_SegmentedArray : public CFX_BaseSegmentedArray 548 class CFX_SegmentedArray : public CFX_BaseSegmentedArray {
648 { 549 public:
649 public: 550 CFX_SegmentedArray(int segment_units, int index_size = 8)
650 CFX_SegmentedArray(int segment_units, int index_size = 8) 551 : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size) {
651 : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size) 552 }
652 {} 553
653 554 void Add(ElementType data) {
654 void» Add(ElementType data) 555 *(ElementType*)CFX_BaseSegmentedArray::Add() = data;
655 { 556 }
656 *(ElementType*)CFX_BaseSegmentedArray::Add() = data; 557
657 } 558 ElementType& operator[](int index) {
658 559 return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index);
659 ElementType& operator [] (int index) 560 }
660 {
661 return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index);
662 }
663 }; 561 };
664 template <class DataType, int FixedSize> 562 template <class DataType, int FixedSize>
665 class CFX_FixedBufGrow 563 class CFX_FixedBufGrow {
666 { 564 public:
667 public: 565 CFX_FixedBufGrow() : m_pData(NULL) {}
668 CFX_FixedBufGrow() : m_pData(NULL) 566 CFX_FixedBufGrow(int data_size) : m_pData(NULL) {
669 {} 567 if (data_size > FixedSize) {
670 CFX_FixedBufGrow(int data_size) : m_pData(NULL) 568 m_pData = FX_Alloc(DataType, data_size);
671 { 569 } else {
672 if (data_size > FixedSize) { 570 FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize);
673 m_pData = FX_Alloc(DataType, data_size); 571 }
674 } else { 572 }
675 FXSYS_memset(m_Data, 0, sizeof(DataType)*FixedSize); 573 void SetDataSize(int data_size) {
676 } 574 if (m_pData) {
677 } 575 FX_Free(m_pData);
678 void SetDataSize(int data_size) 576 }
679 { 577 m_pData = NULL;
680 if (m_pData) { 578 if (data_size > FixedSize) {
681 FX_Free(m_pData); 579 m_pData = FX_Alloc(DataType, data_size);
682 } 580 } else {
683 m_pData = NULL; 581 FXSYS_memset(m_Data, 0, sizeof(DataType) * FixedSize);
684 if (data_size > FixedSize) { 582 }
685 m_pData = FX_Alloc(DataType, data_size); 583 }
686 } else { 584 ~CFX_FixedBufGrow() {
687 FXSYS_memset(m_Data, 0, sizeof(DataType)*FixedSize); 585 if (m_pData) {
688 } 586 FX_Free(m_pData);
689 } 587 }
690 ~CFX_FixedBufGrow() 588 }
691 { 589 operator DataType*() { return m_pData ? m_pData : m_Data; }
692 if (m_pData) { 590
693 FX_Free(m_pData); 591 private:
694 } 592 DataType m_Data[FixedSize];
695 } 593 DataType* m_pData;
696 operator DataType*() 594 };
697 { 595 class CFX_MapPtrToPtr {
698 return m_pData ? m_pData : m_Data; 596 protected:
699 } 597 struct CAssoc {
700 private: 598 CAssoc* pNext;
701 DataType m_Data[FixedSize]; 599
702 DataType* m_pData; 600 void* key;
703 }; 601
704 class CFX_MapPtrToPtr 602 void* value;
705 { 603 };
706 protected: 604
707 605 public:
708 struct CAssoc { 606 CFX_MapPtrToPtr(int nBlockSize = 10);
709 607
710 CAssoc* pNext; 608 ~CFX_MapPtrToPtr();
711 609
712 void* key; 610 int GetCount() const { return m_nCount; }
713 611
714 void* value; 612 FX_BOOL IsEmpty() const { return m_nCount == 0; }
715 }; 613
716 public: 614 FX_BOOL Lookup(void* key, void*& rValue) const;
717 CFX_MapPtrToPtr(int nBlockSize = 10); 615
718 616 void* GetValueAt(void* key) const;
719 ~CFX_MapPtrToPtr(); 617
720 618 void*& operator[](void* key);
721 int GetCount() const 619
722 { 620 void SetAt(void* key, void* newValue) { (*this)[key] = newValue; }
723 return m_nCount; 621
724 } 622 FX_BOOL RemoveKey(void* key);
725 623
726 FX_BOOL IsEmpty() const 624 void RemoveAll();
727 { 625
728 return m_nCount == 0; 626 FX_POSITION GetStartPosition() const {
729 } 627 return (m_nCount == 0) ? NULL : (FX_POSITION)-1;
730 628 }
731 FX_BOOL Lookup(void* key, void*& rValue) const; 629
732 630 void GetNextAssoc(FX_POSITION& rNextPosition,
733 void* GetValueAt(void* key) const; 631 void*& rKey,
734 632 void*& rValue) const;
735 void*& operator[](void* key); 633
736 634 FX_DWORD GetHashTableSize() const { return m_nHashTableSize; }
737 void SetAt(void* key, void* newValue) 635
738 { 636 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
739 (*this)[key] = newValue; 637
740 } 638 protected:
741 639 CAssoc** m_pHashTable;
742 FX_BOOL RemoveKey(void* key); 640
743 641 FX_DWORD m_nHashTableSize;
744 void RemoveAll(); 642
745 643 int m_nCount;
746 FX_POSITION GetStartPosition() const 644
747 { 645 CAssoc* m_pFreeList;
748 return (m_nCount == 0) ? NULL : (FX_POSITION) - 1; 646
749 } 647 struct CFX_Plex* m_pBlocks;
750 648
751 void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) co nst; 649 int m_nBlockSize;
752 650
753 FX_DWORD GetHashTableSize() const 651 FX_DWORD HashKey(void* key) const;
754 { 652
755 return m_nHashTableSize; 653 CAssoc* NewAssoc();
756 } 654
757 655 void FreeAssoc(CAssoc* pAssoc);
758 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); 656
759 protected: 657 CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
760 658 };
761 CAssoc** m_pHashTable; 659
762 660 class CFX_CMapDWordToDWord {
763 FX_DWORD m_nHashTableSize; 661 public:
764 662 FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const;
765 int m_nCount; 663
766 664 void SetAt(FX_DWORD key, FX_DWORD value);
767 CAssoc* m_pFreeList; 665
768 666 void EstimateSize(FX_DWORD size, FX_DWORD grow_by);
769 struct CFX_Plex* m_pBlocks; 667
770 668 FX_POSITION GetStartPosition() const;
771 int m_nBlockSize; 669
772 670 void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWORD& value) const;
773 FX_DWORD HashKey(void* key) const; 671
774 672 protected:
775 CAssoc* NewAssoc(); 673 CFX_BinaryBuf m_Buffer;
776 674 };
777 void FreeAssoc(CAssoc* pAssoc); 675 class CFX_MapByteStringToPtr {
778 676 protected:
779 CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const; 677 struct CAssoc {
780 }; 678 CAssoc* pNext;
781 679
782 class CFX_CMapDWordToDWord 680 FX_DWORD nHashValue;
783 { 681
784 public: 682 CFX_ByteString key;
785 683
786 FX_BOOL Lookup(FX_DWORD key, FX_DWORD& value) const; 684 void* value;
787 685 };
788 void SetAt(FX_DWORD key, FX_DWORD value); 686
789 687 public:
790 void EstimateSize(FX_DWORD size, FX_DWORD grow_by); 688 CFX_MapByteStringToPtr(int nBlockSize = 10);
791 689
792 FX_POSITION GetStartPosition() const; 690 int GetCount() const { return m_nCount; }
793 691
794 void GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX _DWORD& value) const; 692 FX_BOOL IsEmpty() const { return m_nCount == 0; }
795 protected: 693
796 694 FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const;
797 CFX_BinaryBuf m_Buffer; 695
798 }; 696 void*& operator[](const CFX_ByteStringC& key);
799 class CFX_MapByteStringToPtr 697
800 { 698 void SetAt(const CFX_ByteStringC& key, void* newValue) {
801 protected: 699 (*this)[key] = newValue;
802 700 }
803 struct CAssoc { 701
804 702 FX_BOOL RemoveKey(const CFX_ByteStringC& key);
805 CAssoc* pNext; 703
806 704 void RemoveAll();
807 FX_DWORD nHashValue; 705
808 706 FX_POSITION GetStartPosition() const {
809 CFX_ByteString key; 707 return (m_nCount == 0) ? NULL : (FX_POSITION)-1;
810 708 }
811 void* value; 709
812 }; 710 void GetNextAssoc(FX_POSITION& rNextPosition,
813 public: 711 CFX_ByteString& rKey,
814 CFX_MapByteStringToPtr(int nBlockSize = 10); 712 void*& rValue) const;
815 713
816 int GetCount() const 714 void* GetNextValue(FX_POSITION& rNextPosition) const;
817 { 715
818 return m_nCount; 716 FX_DWORD GetHashTableSize() const { return m_nHashTableSize; }
819 } 717
820 718 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
821 FX_BOOL IsEmpty() const 719
822 { 720 FX_DWORD HashKey(const CFX_ByteStringC& key) const;
823 return m_nCount == 0; 721
824 } 722 protected:
825 723 CAssoc** m_pHashTable;
826 FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const; 724
827 725 FX_DWORD m_nHashTableSize;
828 void*& operator[](const CFX_ByteStringC& key); 726
829 727 int m_nCount;
830 void SetAt(const CFX_ByteStringC& key, void* newValue) 728
831 { 729 CAssoc* m_pFreeList;
832 (*this)[key] = newValue; 730
833 } 731 struct CFX_Plex* m_pBlocks;
834 732
835 FX_BOOL RemoveKey(const CFX_ByteStringC& key); 733 int m_nBlockSize;
836 734
837 void RemoveAll(); 735 CAssoc* NewAssoc();
838 736
839 FX_POSITION GetStartPosition() const 737 void FreeAssoc(CAssoc* pAssoc);
840 { 738
841 return (m_nCount == 0) ? NULL : (FX_POSITION) - 1; 739 CAssoc* GetAssocAt(const CFX_ByteStringC& key, FX_DWORD& hash) const;
842 } 740
843 741 public:
844 void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& r Value) const; 742 ~CFX_MapByteStringToPtr();
845 743 };
846 void* GetNextValue(FX_POSITION& rNextPosition) const; 744 class CFX_CMapByteStringToPtr {
847 745 public:
848 FX_DWORD GetHashTableSize() const 746 CFX_CMapByteStringToPtr();
849 { 747
850 return m_nHashTableSize; 748 ~CFX_CMapByteStringToPtr();
851 } 749
852 750 void RemoveAll();
853 void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE); 751
854 752 FX_POSITION GetStartPosition() const;
855 FX_DWORD HashKey(const CFX_ByteStringC& key) const; 753
856 protected: 754 void GetNextAssoc(FX_POSITION& rNextPosition,
857 755 CFX_ByteString& rKey,
858 CAssoc** m_pHashTable; 756 void*& rValue) const;
859 757
860 FX_DWORD m_nHashTableSize; 758 void* GetNextValue(FX_POSITION& rNextPosition) const;
861 759
862 int m_nCount; 760 FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const;
863 761
864 CAssoc* m_pFreeList; 762 void SetAt(const CFX_ByteStringC& key, void* value);
865 763
866 struct CFX_Plex* m_pBlocks; 764 void RemoveKey(const CFX_ByteStringC& key);
867 765
868 int m_nBlockSize; 766 int GetCount() const;
869 767
870 CAssoc* NewAssoc(); 768 void AddValue(const CFX_ByteStringC& key, void* pValue);
871 769
872 void FreeAssoc(CAssoc* pAssoc); 770 private:
873 771 CFX_BaseSegmentedArray m_Buffer;
874 CAssoc* GetAssocAt(const CFX_ByteStringC& key, FX_DWORD& hash) const; 772 };
875 public: 773 class CFX_PtrList {
876 774 protected:
877 ~CFX_MapByteStringToPtr(); 775 struct CNode {
878 }; 776 CNode* pNext;
879 class CFX_CMapByteStringToPtr 777
880 { 778 CNode* pPrev;
881 public: 779
882 CFX_CMapByteStringToPtr(); 780 void* data;
883 781 };
884 ~CFX_CMapByteStringToPtr(); 782
885 783 public:
886 void RemoveAll(); 784 CFX_PtrList(int nBlockSize = 10);
887 785
888 FX_POSITION GetStartPosition() const; 786 FX_POSITION GetHeadPosition() const { return (FX_POSITION)m_pNodeHead; }
889 787
890 void GetNextAssoc(FX_POSITION& rNextPosition, CFX_Byt eString& rKey, void*& rValue) const; 788 FX_POSITION GetTailPosition() const { return (FX_POSITION)m_pNodeTail; }
891 789
892 void* GetNextValue(FX_POSITION& rNextPosition) const; 790 void* GetNext(FX_POSITION& rPosition) const {
893 791 CNode* pNode = (CNode*)rPosition;
894 FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue ) const; 792 rPosition = (FX_POSITION)pNode->pNext;
895 793 return pNode->data;
896 void SetAt(const CFX_ByteStringC& key, void* value); 794 }
897 795
898 void RemoveKey(const CFX_ByteStringC& key); 796 void* GetPrev(FX_POSITION& rPosition) const {
899 797 CNode* pNode = (CNode*)rPosition;
900 int GetCount() const; 798 rPosition = (FX_POSITION)pNode->pPrev;
901 799 return pNode->data;
902 void AddValue(const CFX_ByteStringC& key, void* pValu e); 800 }
903 private: 801
904 802 FX_POSITION GetNextPosition(FX_POSITION pos) const {
905 CFX_BaseSegmentedArray m_Buffer; 803 return ((CNode*)pos)->pNext;
906 }; 804 }
907 class CFX_PtrList 805
908 { 806 FX_POSITION GetPrevPosition(FX_POSITION pos) const {
909 protected: 807 return ((CNode*)pos)->pPrev;
910 808 }
911 struct CNode { 809
912 810 void* GetAt(FX_POSITION rPosition) const {
913 CNode* pNext; 811 CNode* pNode = (CNode*)rPosition;
914 812 return pNode->data;
915 CNode* pPrev; 813 }
916 814
917 void* data; 815 int GetCount() const { return m_nCount; }
918 }; 816
919 public: 817 FX_POSITION AddTail(void* newElement);
920 CFX_PtrList(int nBlockSize = 10); 818
921 819 FX_POSITION AddHead(void* newElement);
922 FX_POSITION GetHeadPosition() const 820
923 { 821 void SetAt(FX_POSITION pos, void* newElement) {
924 return (FX_POSITION)m_pNodeHead; 822 CNode* pNode = (CNode*)pos;
925 } 823 pNode->data = newElement;
926 824 }
927 FX_POSITION GetTailPosition() const 825
928 { 826 FX_POSITION InsertAfter(FX_POSITION pos, void* newElement);
929 return (FX_POSITION)m_pNodeTail; 827
930 } 828 FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL) const;
931 829
932 void* GetNext(FX_POSITION& rPosition) const 830 FX_POSITION FindIndex(int index) const;
933 { 831
934 CNode* pNode = (CNode*) rPosition; 832 void RemoveAt(FX_POSITION pos);
935 rPosition = (FX_POSITION) pNode->pNext; 833
936 return pNode->data; 834 void RemoveAll();
937 } 835
938 836 protected:
939 void* GetPrev(FX_POSITION& rPosition) const 837 CNode* m_pNodeHead;
940 { 838
941 CNode* pNode = (CNode*) rPosition; 839 CNode* m_pNodeTail;
942 rPosition = (FX_POSITION) pNode->pPrev; 840
943 return pNode->data; 841 int m_nCount;
944 } 842
945 843 CNode* m_pNodeFree;
946 FX_POSITION GetNextPosition(FX_POSITION pos) const 844
947 { 845 struct CFX_Plex* m_pBlocks;
948 return ((CNode*)pos)->pNext; 846
949 } 847 int m_nBlockSize;
950 848
951 FX_POSITION GetPrevPosition(FX_POSITION pos) const 849 CNode* NewNode(CNode* pPrev, CNode* pNext);
952 { 850
953 return ((CNode*)pos)->pPrev; 851 void FreeNode(CNode* pNode);
954 } 852
955 853 public:
956 void* GetAt(FX_POSITION rPosition) const 854 ~CFX_PtrList();
957 {
958 CNode* pNode = (CNode*) rPosition;
959 return pNode->data;
960 }
961
962 int GetCount() const
963 {
964 return m_nCount;
965 }
966
967 FX_POSITION AddTail(void* newElement);
968
969 FX_POSITION AddHead(void* newElement);
970
971 void SetAt(FX_POSITION pos, void* newElement)
972 {
973 CNode* pNode = (CNode*) pos;
974 pNode->data = newElement;
975 }
976
977 FX_POSITION InsertAfter(FX_POSITION pos, void* newElement);
978
979 FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL ) const;
980
981 FX_POSITION FindIndex(int index) const;
982
983 void RemoveAt(FX_POSITION pos);
984
985 void RemoveAll();
986 protected:
987
988 CNode* m_pNodeHead;
989
990 CNode* m_pNodeTail;
991
992 int m_nCount;
993
994 CNode* m_pNodeFree;
995
996 struct CFX_Plex* m_pBlocks;
997
998 int m_nBlockSize;
999
1000 CNode* NewNode(CNode* pPrev, CNode* pNext);
1001
1002 void FreeNode(CNode* pNode);
1003 public:
1004
1005 ~CFX_PtrList();
1006 }; 855 };
1007 typedef void (*PD_CALLBACK_FREEDATA)(void* pData); 856 typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
1008 struct FX_PRIVATEDATA { 857 struct FX_PRIVATEDATA {
1009 858 void FreeData();
1010 void» » » » » FreeData(); 859
1011 860 void* m_pModuleId;
1012 void*» » » » m_pModuleId; 861
1013 862 void* m_pData;
1014 void*» » » » m_pData; 863
1015 864 PD_CALLBACK_FREEDATA m_pCallback;
1016 PD_CALLBACK_FREEDATA» m_pCallback; 865
1017 866 FX_BOOL m_bSelfDestruct;
1018 FX_BOOL» » » » » m_bSelfDestruct; 867 };
1019 }; 868 class CFX_PrivateData {
1020 class CFX_PrivateData 869 public:
1021 { 870 ~CFX_PrivateData();
1022 public: 871
1023 872 void ClearAll();
1024 ~CFX_PrivateData(); 873
1025 874 void SetPrivateData(void* module_id,
1026 void» » » » » ClearAll(); 875 void* pData,
1027 876 PD_CALLBACK_FREEDATA callback);
1028 void» » » » » SetPrivateData(void* module_id, void* pData, PD_CALLBACK_FREEDATA callback); 877
1029 878 void SetPrivateObj(void* module_id, CFX_DestructObject* pObj);
1030 void» » » » » SetPrivateObj(void* module_id, C FX_DestructObject* pObj); 879
1031 880 void* GetPrivateData(void* module_id);
1032 void*» » » » GetPrivateData(void* module_id); 881
1033 882 FX_BOOL LookupPrivateData(void* module_id, void*& pData) const {
1034 FX_BOOL» » » » » LookupPrivateData(void* module_i d, void* &pData) const 883 if (!module_id) {
1035 { 884 return FALSE;
1036 if (!module_id) { 885 }
1037 return FALSE; 886 FX_DWORD nCount = m_DataList.GetSize();
1038 } 887 for (FX_DWORD n = 0; n < nCount; n++) {
1039 FX_DWORD nCount = m_DataList.GetSize(); 888 if (m_DataList[n].m_pModuleId == module_id) {
1040 for (FX_DWORD n = 0; n < nCount; n ++) { 889 pData = m_DataList[n].m_pData;
1041 if (m_DataList[n].m_pModuleId == module_id) { 890 return TRUE;
1042 pData = m_DataList[n].m_pData; 891 }
1043 return TRUE; 892 }
1044 } 893 return FALSE;
1045 } 894 }
1046 return FALSE; 895
1047 } 896 FX_BOOL RemovePrivateData(void* module_id);
1048 897
1049 FX_BOOL» » » » » RemovePrivateData(void* module_i d); 898 protected:
1050 protected: 899 CFX_ArrayTemplate<FX_PRIVATEDATA> m_DataList;
1051 900
1052 CFX_ArrayTemplate<FX_PRIVATEDATA>» m_DataList; 901 void AddData(void* module_id,
1053 902 void* pData,
1054 void» » » » » AddData(void* module_id, void* p Data, PD_CALLBACK_FREEDATA callback, FX_BOOL bSelfDestruct); 903 PD_CALLBACK_FREEDATA callback,
1055 }; 904 FX_BOOL bSelfDestruct);
1056 class CFX_BitStream 905 };
1057 { 906 class CFX_BitStream {
1058 public: 907 public:
1059 908 void Init(const uint8_t* pData, FX_DWORD dwSize);
1060 void» » » » Init(const uint8_t* pData, FX_DWORD dwSi ze); 909
1061 910 FX_DWORD GetBits(FX_DWORD nBits);
1062 911
1063 FX_DWORD» » » GetBits(FX_DWORD nBits); 912 void ByteAlign();
1064 913
1065 void» » » » ByteAlign(); 914 FX_BOOL IsEOF() { return m_BitPos >= m_BitSize; }
1066 915
1067 FX_BOOL» » » » IsEOF() 916 void SkipBits(FX_DWORD nBits) { m_BitPos += nBits; }
1068 { 917
1069 return m_BitPos >= m_BitSize; 918 void Rewind() { m_BitPos = 0; }
1070 } 919
1071 920 protected:
1072 void» » » » SkipBits(FX_DWORD nBits) 921 FX_DWORD m_BitPos;
1073 { 922
1074 m_BitPos += nBits; 923 FX_DWORD m_BitSize;
1075 } 924
1076 925 const uint8_t* m_pData;
1077 void» » » » Rewind() 926 };
1078 { 927 template <class ObjClass>
1079 m_BitPos = 0; 928 class CFX_CountRef {
1080 } 929 public:
1081 protected: 930 typedef CFX_CountRef<ObjClass> Ref;
1082 931
1083 FX_DWORD» » » m_BitPos; 932 class CountedObj : public ObjClass {
1084 933 public:
1085 FX_DWORD» » » m_BitSize; 934 CountedObj() {}
1086 935
1087 const uint8_t*» » » m_pData; 936 CountedObj(const CountedObj& src) : ObjClass(src) {}
1088 }; 937
1089 template <class ObjClass> class CFX_CountRef 938 int m_RefCount;
1090 { 939 };
1091 public: 940
1092 941 CFX_CountRef() { m_pObject = NULL; }
1093 typedef CFX_CountRef<ObjClass> Ref; 942
1094 943 CFX_CountRef(const Ref& ref) {
1095 class CountedObj : public ObjClass 944 m_pObject = ref.m_pObject;
1096 { 945 if (m_pObject) {
1097 public: 946 m_pObject->m_RefCount++;
1098 947 }
1099 CountedObj() {} 948 }
1100 949
1101 CountedObj(const CountedObj& src) : ObjClass(src) {} 950 ~CFX_CountRef() {
1102 951 if (!m_pObject) {
1103 int» » » m_RefCount; 952 return;
1104 }; 953 }
1105 954 m_pObject->m_RefCount--;
1106 CFX_CountRef() 955 if (m_pObject->m_RefCount <= 0) {
1107 { 956 delete m_pObject;
1108 m_pObject = NULL; 957 }
1109 } 958 }
1110 959
1111 CFX_CountRef(const Ref& ref) 960 ObjClass* New() {
1112 { 961 if (m_pObject) {
1113 m_pObject = ref.m_pObject; 962 m_pObject->m_RefCount--;
1114 if (m_pObject) { 963 if (m_pObject->m_RefCount <= 0) {
1115 m_pObject->m_RefCount ++; 964 delete m_pObject;
1116 } 965 }
1117 } 966 }
1118 967 m_pObject = new CountedObj;
1119 ~CFX_CountRef() 968 m_pObject->m_RefCount = 1;
1120 { 969 return m_pObject;
1121 if (!m_pObject) { 970 }
1122 return; 971
1123 } 972 void operator=(const Ref& ref) {
1124 m_pObject->m_RefCount --; 973 if (ref.m_pObject) {
1125 if (m_pObject->m_RefCount <= 0) { 974 ref.m_pObject->m_RefCount++;
1126 delete m_pObject; 975 }
1127 } 976 if (m_pObject) {
1128 } 977 m_pObject->m_RefCount--;
1129 978 if (m_pObject->m_RefCount <= 0) {
1130 ObjClass*» » » New() 979 delete m_pObject;
1131 { 980 }
1132 if (m_pObject) { 981 }
1133 m_pObject->m_RefCount --; 982 m_pObject = ref.m_pObject;
1134 if (m_pObject->m_RefCount <= 0) { 983 }
1135 delete m_pObject; 984
1136 } 985 void operator=(void* p) {
1137 } 986 FXSYS_assert(p == 0);
1138 m_pObject = new CountedObj; 987 if (m_pObject == NULL) {
1139 m_pObject->m_RefCount = 1; 988 return;
1140 return m_pObject; 989 }
1141 } 990 m_pObject->m_RefCount--;
1142 991 if (m_pObject->m_RefCount <= 0) {
1143 void» » » » operator = (const Ref& ref) 992 delete m_pObject;
1144 { 993 }
1145 if (ref.m_pObject) { 994 m_pObject = NULL;
1146 ref.m_pObject->m_RefCount ++; 995 }
1147 } 996
1148 if (m_pObject) { 997 const ObjClass* GetObject() const { return m_pObject; }
1149 m_pObject->m_RefCount --; 998
1150 if (m_pObject->m_RefCount <= 0) { 999 operator const ObjClass*() const { return m_pObject; }
1151 delete m_pObject; 1000
1152 } 1001 FX_BOOL IsNull() const { return m_pObject == NULL; }
1153 } 1002
1154 m_pObject = ref.m_pObject; 1003 FX_BOOL NotNull() const { return m_pObject != NULL; }
1155 } 1004
1156 1005 ObjClass* GetModify() {
1157 void» » » » operator = (void* p) 1006 if (m_pObject == NULL) {
1158 { 1007 m_pObject = new CountedObj;
1159 FXSYS_assert(p == 0); 1008 m_pObject->m_RefCount = 1;
1160 if (m_pObject == NULL) { 1009 } else if (m_pObject->m_RefCount > 1) {
1161 return; 1010 m_pObject->m_RefCount--;
1162 } 1011 CountedObj* pOldObject = m_pObject;
1163 m_pObject->m_RefCount --; 1012 m_pObject = new CountedObj(*pOldObject);
1164 if (m_pObject->m_RefCount <= 0) { 1013 m_pObject->m_RefCount = 1;
1165 delete m_pObject; 1014 }
1166 } 1015 return m_pObject;
1167 m_pObject = NULL; 1016 }
1168 } 1017
1169 1018 void SetNull() {
1170 const ObjClass*» » GetObject() const 1019 if (m_pObject == NULL) {
1171 { 1020 return;
1172 return m_pObject; 1021 }
1173 } 1022 m_pObject->m_RefCount--;
1174 1023 if (m_pObject->m_RefCount <= 0) {
1175 operator» » » const ObjClass*() const 1024 delete m_pObject;
1176 { 1025 }
1177 return m_pObject; 1026 m_pObject = NULL;
1178 } 1027 }
1179 1028
1180 FX_BOOL» » » » IsNull() const 1029 FX_BOOL operator==(const Ref& ref) const {
1181 { 1030 return m_pObject == ref.m_pObject;
1182 return m_pObject == NULL; 1031 }
1183 } 1032
1184 1033 protected:
1185 FX_BOOL» » » » NotNull() const 1034 CountedObj* m_pObject;
1186 { 1035 };
1187 return m_pObject != NULL; 1036 class IFX_Pause {
1188 } 1037 public:
1189 1038 virtual ~IFX_Pause() {}
1190 ObjClass*» » » GetModify() 1039 virtual FX_BOOL NeedToPauseNow() = 0;
1191 { 1040 };
1192 if (m_pObject == NULL) { 1041 class CFX_DataFilter {
1193 m_pObject = new CountedObj; 1042 public:
1194 m_pObject->m_RefCount = 1; 1043 virtual ~CFX_DataFilter();
1195 } else if (m_pObject->m_RefCount > 1) { 1044
1196 m_pObject->m_RefCount --; 1045 void SetDestFilter(CFX_DataFilter* pFilter);
1197 CountedObj* pOldObject = m_pObject; 1046
1198 m_pObject = new CountedObj(*pOldObject); 1047 FX_BOOL IsEOF() const { return m_bEOF; }
1199 m_pObject->m_RefCount = 1; 1048
1200 } 1049 FX_DWORD GetSrcPos() { return m_SrcPos; }
1201 return m_pObject; 1050
1202 } 1051 void FilterIn(const uint8_t* src_buf,
1203 1052 FX_DWORD src_size,
1204 void» » » » SetNull() 1053 CFX_BinaryBuf& dest_buf);
1205 { 1054
1206 if (m_pObject == NULL) { 1055 void FilterFinish(CFX_BinaryBuf& dest_buf);
1207 return; 1056
1208 } 1057 protected:
1209 m_pObject->m_RefCount --; 1058 CFX_DataFilter();
1210 if (m_pObject->m_RefCount <= 0) { 1059 virtual void v_FilterIn(const uint8_t* src_buf,
1211 delete m_pObject; 1060 FX_DWORD src_size,
1212 } 1061 CFX_BinaryBuf& dest_buf) = 0;
1213 m_pObject = NULL; 1062 virtual void v_FilterFinish(CFX_BinaryBuf& dest_buf) = 0;
1214 } 1063 void ReportEOF(FX_DWORD left_input);
1215 1064
1216 FX_BOOL» » » » operator == (const Ref& ref) const 1065 FX_BOOL m_bEOF;
1217 { 1066
1218 return m_pObject == ref.m_pObject; 1067 FX_DWORD m_SrcPos;
1219 } 1068
1220 protected: 1069 CFX_DataFilter* m_pDestFilter;
1221 1070 };
1222 CountedObj*»» » m_pObject; 1071
1223 }; 1072 template <typename T>
1224 class IFX_Pause
1225 {
1226 public:
1227 virtual ~IFX_Pause() { }
1228 virtual FX_BOOL» NeedToPauseNow() = 0;
1229 };
1230 class CFX_DataFilter
1231 {
1232 public:
1233
1234 virtual ~CFX_DataFilter();
1235
1236 void» » » SetDestFilter(CFX_DataFilter* pFilter);
1237
1238 FX_BOOL» » » IsEOF() const
1239 {
1240 return m_bEOF;
1241 }
1242
1243 FX_DWORD» » GetSrcPos()
1244 {
1245 return m_SrcPos;
1246 }
1247
1248 void» » » FilterIn(const uint8_t* src_buf, FX_DWORD src_si ze, CFX_BinaryBuf& dest_buf);
1249
1250 void» » » FilterFinish(CFX_BinaryBuf& dest_buf);
1251 protected:
1252
1253 CFX_DataFilter();
1254 virtual void» v_FilterIn(const uint8_t* src_buf, FX_DWORD src_size, CF X_BinaryBuf& dest_buf) = 0;
1255 virtual void» v_FilterFinish(CFX_BinaryBuf& dest_buf) = 0;
1256 void» » » ReportEOF(FX_DWORD left_input);
1257
1258 FX_BOOL» » » m_bEOF;
1259
1260 FX_DWORD» » m_SrcPos;
1261
1262 CFX_DataFilter*» m_pDestFilter;
1263 };
1264
1265 template<typename T>
1266 class CFX_AutoRestorer { 1073 class CFX_AutoRestorer {
1267 public: 1074 public:
1268 explicit CFX_AutoRestorer(T* location) { 1075 explicit CFX_AutoRestorer(T* location) {
1269 m_Location = location; 1076 m_Location = location;
1270 m_OldValue = *location; 1077 m_OldValue = *location;
1271 } 1078 }
1272 ~CFX_AutoRestorer() { *m_Location = m_OldValue; } 1079 ~CFX_AutoRestorer() { *m_Location = m_OldValue; }
1273 1080
1274 private: 1081 private:
1275 T* m_Location; 1082 T* m_Location;
1276 T m_OldValue; 1083 T m_OldValue;
1277 }; 1084 };
1278 1085
1279 template <class T> 1086 template <class T>
1280 class CFX_SmartPointer 1087 class CFX_SmartPointer {
1281 { 1088 public:
1282 public: 1089 CFX_SmartPointer(T* pObj) : m_pObj(pObj) {}
1283 CFX_SmartPointer(T *pObj) : m_pObj(pObj) {} 1090 ~CFX_SmartPointer() { m_pObj->Release(); }
1284 ~CFX_SmartPointer() 1091 T* Get(void) { return m_pObj; }
1285 { 1092 T& operator*(void) { return *m_pObj; }
1286 m_pObj->Release(); 1093 T* operator->(void) { return m_pObj; }
1287 } 1094
1288 T* Get(void) 1095 protected:
1289 { 1096 T* m_pObj;
1290 return m_pObj; 1097 };
1291 } 1098 #define FX_DATALIST_LENGTH 1024
1292 T&» » operator *(void) 1099 template <size_t unit>
1293 { 1100 class CFX_SortListArray {
1294 return *m_pObj; 1101 protected:
1295 } 1102 struct DataList {
1296 T*» » operator ->(void) 1103 int32_t start;
1297 { 1104
1298 return m_pObj; 1105 int32_t count;
1299 } 1106 uint8_t* data;
1300 protected: 1107 };
1301 T *m_pObj; 1108
1302 }; 1109 public:
1303 #define FX_DATALIST_LENGTH» 1024 1110 CFX_SortListArray() : m_CurList(0) {}
1304 template<size_t unit> 1111
1305 class CFX_SortListArray 1112 ~CFX_SortListArray() { Clear(); }
1306 { 1113
1307 protected: 1114 void Clear() {
1308 1115 for (int32_t i = m_DataLists.GetUpperBound(); i >= 0; i--) {
1309 struct DataList { 1116 DataList list = m_DataLists.ElementAt(i);
1310 1117 if (list.data) {
1311 int32_t»start; 1118 FX_Free(list.data);
1312 1119 }
1313 int32_t»count; 1120 }
1314 uint8_t*» data; 1121 m_DataLists.RemoveAll();
1315 }; 1122 m_CurList = 0;
1316 public: 1123 }
1317 1124
1318 CFX_SortListArray() : m_CurList(0) {} 1125 void Append(int32_t nStart, int32_t nCount) {
1319 1126 if (nStart < 0) {
1320 ~CFX_SortListArray() 1127 return;
1321 { 1128 }
1322 Clear(); 1129 while (nCount > 0) {
1323 } 1130 int32_t temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH);
1324 1131 DataList list;
1325 1132 list.data = FX_Alloc2D(uint8_t, temp_count, unit);
1326 void» » » Clear() 1133 list.start = nStart;
1327 { 1134 list.count = temp_count;
1328 for (int32_t i = m_DataLists.GetUpperBound(); i >= 0; i--) { 1135 Append(list);
1329 DataList list = m_DataLists.ElementAt(i); 1136 nCount -= temp_count;
1330 if (list.data) { 1137 nStart += temp_count;
1331 FX_Free(list.data); 1138 }
1332 } 1139 }
1140
1141 uint8_t* GetAt(int32_t nIndex) {
1142 if (nIndex < 0) {
1143 return NULL;
1144 }
1145 if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) {
1146 return NULL;
1147 }
1148 DataList* pCurList = m_DataLists.GetDataPtr(m_CurList);
1149 if (!pCurList || nIndex < pCurList->start ||
1150 nIndex >= pCurList->start + pCurList->count) {
1151 pCurList = NULL;
1152 int32_t iStart = 0;
1153 int32_t iEnd = m_DataLists.GetUpperBound();
1154 int32_t iMid = 0;
1155 while (iStart <= iEnd) {
1156 iMid = (iStart + iEnd) / 2;
1157 DataList* list = m_DataLists.GetDataPtr(iMid);
1158 if (nIndex < list->start) {
1159 iEnd = iMid - 1;
1160 } else if (nIndex >= list->start + list->count) {
1161 iStart = iMid + 1;
1162 } else {
1163 pCurList = list;
1164 m_CurList = iMid;
1165 break;
1333 } 1166 }
1334 m_DataLists.RemoveAll(); 1167 }
1335 m_CurList = 0; 1168 }
1336 } 1169 return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit : NULL;
1337 1170 }
1338 void» » » Append(int32_t nStart, int32_t nCount) 1171
1339 { 1172 protected:
1340 if (nStart < 0) { 1173 void Append(const DataList& list) {
1341 return; 1174 int32_t iStart = 0;
1175 int32_t iEnd = m_DataLists.GetUpperBound();
1176 int32_t iFind = 0;
1177 while (iStart <= iEnd) {
1178 int32_t iMid = (iStart + iEnd) / 2;
1179 DataList* cur_list = m_DataLists.GetDataPtr(iMid);
1180 if (list.start < cur_list->start + cur_list->count) {
1181 iEnd = iMid - 1;
1182 } else {
1183 if (iMid == iEnd) {
1184 iFind = iMid + 1;
1185 break;
1342 } 1186 }
1343 while (nCount > 0) { 1187 DataList* next_list = m_DataLists.GetDataPtr(iMid + 1);
1344 int32_t temp_count = FX_MIN(nCount, FX_DATALIST_LENGTH); 1188 if (list.start < next_list->start) {
1345 DataList list; 1189 iFind = iMid + 1;
1346 list.data = FX_Alloc2D(uint8_t, temp_count, unit); 1190 break;
1347 list.start = nStart; 1191 } else {
1348 list.count = temp_count; 1192 iStart = iMid + 1;
1349 Append(list);
1350 nCount -= temp_count;
1351 nStart += temp_count;
1352 } 1193 }
1353 } 1194 }
1354 1195 }
1355 uint8_t*» » GetAt(int32_t nIndex) 1196 m_DataLists.InsertAt(iFind, list);
1356 { 1197 }
1357 if (nIndex < 0) { 1198 int32_t m_CurList;
1358 return NULL; 1199 CFX_ArrayTemplate<DataList> m_DataLists;
1359 } 1200 };
1360 if (m_CurList < 0 || m_CurList >= m_DataLists.GetSize()) { 1201 template <typename T1, typename T2>
1361 return NULL; 1202 class CFX_ListArrayTemplate {
1362 } 1203 public:
1363 DataList *pCurList = m_DataLists.GetDataPtr(m_CurList); 1204 void Clear() { m_Data.Clear(); }
1364 if (!pCurList || nIndex < pCurList->start || nIndex >= pCurList->start + pCurList->count) { 1205
1365 pCurList = NULL; 1206 void Add(int32_t nStart, int32_t nCount) { m_Data.Append(nStart, nCount); }
1366 int32_t iStart = 0; 1207
1367 int32_t iEnd = m_DataLists.GetUpperBound(); 1208 T2& operator[](int32_t nIndex) {
1368 int32_t iMid = 0; 1209 uint8_t* data = m_Data.GetAt(nIndex);
1369 while (iStart <= iEnd) { 1210 FXSYS_assert(data != NULL);
1370 iMid = (iStart + iEnd) / 2; 1211 return (T2&)(*(volatile T2*)data);
1371 DataList* list = m_DataLists.GetDataPtr(iMid); 1212 }
1372 if (nIndex < list->start) { 1213
1373 iEnd = iMid - 1; 1214 T2* GetPtrAt(int32_t nIndex) { return (T2*)m_Data.GetAt(nIndex); }
1374 } else if (nIndex >= list->start + list->count) { 1215
1375 iStart = iMid + 1; 1216 protected:
1376 } else { 1217 T1 m_Data;
1377 pCurList = list; 1218 };
1378 m_CurList = iMid; 1219 typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>,
1379 break; 1220 FX_FILESIZE> CFX_FileSizeListArray;
1380 } 1221 typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_DWORD)>, FX_DWORD>
1381 } 1222 CFX_DWordListArray;
1382 }
1383 return pCurList ? pCurList->data + (nIndex - pCurList->start) * unit : N ULL;
1384 }
1385 protected:
1386 void» » » Append(const DataList& list)
1387 {
1388 int32_t iStart = 0;
1389 int32_t iEnd = m_DataLists.GetUpperBound();
1390 int32_t iFind = 0;
1391 while (iStart <= iEnd) {
1392 int32_t iMid = (iStart + iEnd) / 2;
1393 DataList* cur_list = m_DataLists.GetDataPtr(iMid);
1394 if (list.start < cur_list->start + cur_list->count) {
1395 iEnd = iMid - 1;
1396 } else {
1397 if (iMid == iEnd) {
1398 iFind = iMid + 1;
1399 break;
1400 }
1401 DataList* next_list = m_DataLists.GetDataPtr(iMid + 1);
1402 if (list.start < next_list->start) {
1403 iFind = iMid + 1;
1404 break;
1405 } else {
1406 iStart = iMid + 1;
1407 }
1408 }
1409 }
1410 m_DataLists.InsertAt(iFind, list);
1411 }
1412 int32_t» » m_CurList;
1413 CFX_ArrayTemplate<DataList>»m_DataLists;
1414 };
1415 template<typename T1, typename T2>
1416 class CFX_ListArrayTemplate
1417 {
1418 public:
1419
1420 void» » » Clear()
1421 {
1422 m_Data.Clear();
1423 }
1424
1425 void» » » Add(int32_t nStart, int32_t nCount)
1426 {
1427 m_Data.Append(nStart, nCount);
1428 }
1429
1430 T2&»» » » operator [] (int32_t nIndex)
1431 {
1432 uint8_t* data = m_Data.GetAt(nIndex);
1433 FXSYS_assert(data != NULL);
1434 return (T2&)(*(volatile T2*)data);
1435 }
1436
1437 T2*»» » » GetPtrAt(int32_t nIndex)
1438 {
1439 return (T2*)m_Data.GetAt(nIndex);
1440 }
1441 protected:
1442 T1» » » m_Data;
1443 };
1444 typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_FILESIZE)>, FX_FILESIZ E>» CFX_FileSizeListArray;
1445 typedef CFX_ListArrayTemplate<CFX_SortListArray<sizeof(FX_DWORD)>, FX_DWORD>» » CFX_DWordListArray;
1446 typedef enum { 1223 typedef enum {
1447 Ready, 1224 Ready,
1448 ToBeContinued, 1225 ToBeContinued,
1449 Found, 1226 Found,
1450 NotFound, 1227 NotFound,
1451 Failed, 1228 Failed,
1452 Done 1229 Done
1453 } FX_ProgressiveStatus; 1230 } FX_ProgressiveStatus;
1454 #define ProgressiveStatus» FX_ProgressiveStatus 1231 #define ProgressiveStatus FX_ProgressiveStatus
1455 #define FX_NAMESPACE_DECLARE(namespace, type) namespace::type 1232 #define FX_NAMESPACE_DECLARE(namespace, type) namespace ::type
1456 1233
1457 class CFX_Vector_3by1 1234 class CFX_Vector_3by1 {
1458 { 1235 public:
1459 public: 1236 CFX_Vector_3by1() : a(0.0f), b(0.0f), c(0.0f) {}
1460 1237
1461 CFX_Vector_3by1() : 1238 CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1)
1462 a(0.0f), b(0.0f), c(0.0f) 1239 : a(a1), b(b1), c(c1) {}
1463 {} 1240
1464 1241 FX_FLOAT a;
1465 CFX_Vector_3by1(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1): 1242 FX_FLOAT b;
1466 a(a1), b(b1), c(c1) 1243 FX_FLOAT c;
1467 {} 1244 };
1468 1245 class CFX_Matrix_3by3 {
1469 FX_FLOAT a; 1246 public:
1470 FX_FLOAT b; 1247 CFX_Matrix_3by3()
1471 FX_FLOAT c; 1248 : a(0.0f),
1472 }; 1249 b(0.0f),
1473 class CFX_Matrix_3by3 1250 c(0.0f),
1474 { 1251 d(0.0f),
1475 public: 1252 e(0.0f),
1476 1253 f(0.0f),
1477 CFX_Matrix_3by3(): 1254 g(0.0f),
1478 a(0.0f), b(0.0f), c(0.0f), d(0.0f), e(0.0f), f(0.0f), g(0.0f), h(0.0f), i(0.0f) 1255 h(0.0f),
1479 {} 1256 i(0.0f) {}
1480 1257
1481 CFX_Matrix_3by3(FX_FLOAT a1, FX_FLOAT b1, FX_FLOAT c1, FX_FLOAT d1, FX_FLOAT e1, FX_FLOAT f1, FX_FLOAT g1, FX_FLOAT h1, FX_FLOAT i1) : 1258 CFX_Matrix_3by3(FX_FLOAT a1,
1482 a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) 1259 FX_FLOAT b1,
1483 {} 1260 FX_FLOAT c1,
1484 1261 FX_FLOAT d1,
1485 CFX_Matrix_3by3 Inverse(); 1262 FX_FLOAT e1,
1486 1263 FX_FLOAT f1,
1487 CFX_Matrix_3by3 Multiply(const CFX_Matrix_3by3 &m); 1264 FX_FLOAT g1,
1488 1265 FX_FLOAT h1,
1489 CFX_Vector_3by1 TransformVector(const CFX_Vector_3by1 &v); 1266 FX_FLOAT i1)
1490 1267 : a(a1), b(b1), c(c1), d(d1), e(e1), f(f1), g(g1), h(h1), i(i1) {}
1491 FX_FLOAT a; 1268
1492 FX_FLOAT b; 1269 CFX_Matrix_3by3 Inverse();
1493 FX_FLOAT c; 1270
1494 FX_FLOAT d; 1271 CFX_Matrix_3by3 Multiply(const CFX_Matrix_3by3& m);
1495 FX_FLOAT e; 1272
1496 FX_FLOAT f; 1273 CFX_Vector_3by1 TransformVector(const CFX_Vector_3by1& v);
1497 FX_FLOAT g; 1274
1498 FX_FLOAT h; 1275 FX_FLOAT a;
1499 FX_FLOAT i; 1276 FX_FLOAT b;
1277 FX_FLOAT c;
1278 FX_FLOAT d;
1279 FX_FLOAT e;
1280 FX_FLOAT f;
1281 FX_FLOAT g;
1282 FX_FLOAT h;
1283 FX_FLOAT i;
1500 }; 1284 };
1501 1285
1502 #endif // CORE_INCLUDE_FXCRT_FX_BASIC_H_ 1286 #endif // CORE_INCLUDE_FXCRT_FX_BASIC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698