1ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Copyright 2014 PDFium Authors. All rights reserved.
2ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Use of this source code is governed by a BSD-style license that can be
3ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// found in the LICENSE file.
4ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
5ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
7ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_BASIC_H_
8ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#define _FX_BASIC_H_
9ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_SYSTEM_H_
10ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "fx_system.h"
11ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
12ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_MEMORY_H_
13ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "fx_memory.h"
14ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
15ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_STRING_H_
16ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "fx_string.h"
17ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
18ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#ifndef _FX_STREAM_H_
19ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#include "fx_stream.h"
20ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov#endif
21ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_BinaryBuf : public CFX_Object
22ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
23ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
24ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
25ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BinaryBuf(IFX_Allocator* pAllocator = NULL);
26ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
27ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BinaryBuf(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
28ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
29ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_BinaryBuf();
30ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
31ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					Clear();
32ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
33ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0);
34ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
35ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					AppendBlock(const void* pBuf, FX_STRSIZE size);
36ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
37ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					AppendFill(FX_BYTE byte, FX_STRSIZE count);
38ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
39ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					AppendString(FX_BSTR str)
40ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
41ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AppendBlock(str.GetPtr(), str.GetLength());
42ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
43ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
44ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    inline void				AppendByte(FX_BYTE byte)
45ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
46ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_AllocSize <= m_DataSize) {
47ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ExpandBuf(1);
48ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
49ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pBuffer[m_DataSize++] = byte;
50ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
51ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
52ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size);
53ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
54ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					AttachData(void* pBuf, FX_STRSIZE size);
55ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
56ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					CopyData(const void* pBuf, FX_STRSIZE size);
57ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
58ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					TakeOver(CFX_BinaryBuf& other);
59ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
60ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					Delete(int start_index, int count);
61ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
62ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPBYTE				GetBuffer() const
63ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
64ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_pBuffer;
65ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
66ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
67ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				GetSize() const
68ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
69ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_DataSize;
70ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
71ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
72ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteStringC			GetByteString() const;
73ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					GetByteStringL(CFX_ByteStringL &str) const;
74ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
75ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					DetachBuffer();
76ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
77ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*			m_pAllocator;
78ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
79ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
80ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				m_AllocStep;
81ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
82ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPBYTE				m_pBuffer;
83ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
84ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				m_DataSize;
85ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
86ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				m_AllocSize;
87ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
88ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					ExpandBuf(FX_STRSIZE size);
89ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
90ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_ByteTextBuf : public CFX_BinaryBuf
91ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
92ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
93ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
94ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator) {}
95ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
96ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					operator = (FX_BSTR str);
97ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
98ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					AppendChar(int ch)
99ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        AppendByte((FX_BYTE)ch);
101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf&		operator << (int i);
104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf&		operator << (FX_DWORD i);
106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf&		operator << (double f);
108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf&		operator << (FX_BSTR lpsz);
110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf&		operator << (const CFX_ByteTextBuf& buf);
112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				GetLength() const
114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_DataSize;
116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_WideTextBuf : public CFX_BinaryBuf
119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf(IFX_Allocator* pAllocator = NULL) : CFX_BinaryBuf(pAllocator) {}
123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					operator = (FX_LPCWSTR lpsz);
125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					operator = (FX_WSTR str);
127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					AppendChar(FX_WCHAR wch);
129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf&		operator << (int i);
131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf&		operator << (double f);
133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf&		operator << (FX_LPCWSTR lpsz);
135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf&		operator << (FX_WSTR str);
137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf&		operator << (const CFX_WideString &str);
138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf&		operator << (const CFX_WideTextBuf& buf);
140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				GetLength() const
142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_DataSize / sizeof(FX_WCHAR);
144ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
145ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
146ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPWSTR				GetBuffer() const
147ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
148ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (FX_LPWSTR)m_pBuffer;
149ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
150ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
151ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					Delete(int start_index, int count)
152ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
153ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_BinaryBuf::Delete(start_index * sizeof(FX_WCHAR), count * sizeof(FX_WCHAR));
154ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
155ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
156ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideStringC			GetWideString() const;
157ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					GetWideStringL(CFX_WideStringL& wideText) const;
158ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
159ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_ArchiveSaver : public CFX_Object
160ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
161ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
162ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
163ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver(IFX_Allocator* pAllocator = NULL) : m_SavingBuf(pAllocator), m_pStream(NULL) {}
164ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
165ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (FX_BYTE i);
166ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
167ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (int i);
168ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
169ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (FX_DWORD i);
170ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
171ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (FX_FLOAT i);
172ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
173ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (double i);
174ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
175ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (FX_BSTR bstr);
176ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
177ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (FX_LPCWSTR bstr);
178ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
179ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveSaver&		operator << (const CFX_WideString& wstr);
180ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
181ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					Write(const void* pData, FX_STRSIZE dwSize);
182ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
183ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INTPTR				GetLength()
184ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
185ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_SavingBuf.GetSize();
186ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
187ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
188ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPCBYTE				GetBuffer()
189ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
190ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_SavingBuf.GetBuffer();
191ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
192ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
193ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					SetStream(IFX_FileStream* pStream)
194ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
195ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pStream = pStream;
196ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
197ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
198ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
199ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BinaryBuf			m_SavingBuf;
200ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
201ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_FileStream*			m_pStream;
202ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
203ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_ArchiveLoader : public CFX_Object
204ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
205ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
206ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
207ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader(FX_LPCBYTE pData, FX_DWORD dwSize);
208ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
209ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (FX_BYTE& i);
210ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
211ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (int& i);
212ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
213ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (FX_DWORD& i);
214ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
215ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (FX_FLOAT& i);
216ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
217ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (double& i);
218ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
219ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (CFX_ByteString& bstr);
220ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
221ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArchiveLoader&		operator >> (CFX_WideString& wstr);
222ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
223ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					IsEOF();
224ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
225ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					Read(void* pBuf, FX_DWORD dwSize);
226ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
227ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
228ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD				m_LoadingPos;
229ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
230ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPCBYTE				m_pLoadingBuf;
231ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
232ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD				m_LoadingSize;
233ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
234ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass IFX_BufferArchive
235ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
236ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
237ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
238ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_BufferArchive(FX_STRSIZE size, IFX_Allocator* pAllocator = NULL);
239ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
240ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
241ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    virtual void			Clear();
242ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
243ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
244ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					Flush();
245ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
246ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
247ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32				AppendBlock(const void* pBuf, size_t size);
248ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
249ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32				AppendByte(FX_BYTE byte);
250ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
251ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32				AppendDWord(FX_DWORD i);
252ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
253ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
254ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32				AppendString(FX_BSTR lpsz);
255ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
256ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
257ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
258ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    virtual	FX_BOOL			DoWork(const void* pBuf, size_t size) = 0;
259ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
260ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
261ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*			m_pAllocator;
262ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
263ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				m_BufSize;
264ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
265ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPBYTE				m_pBuffer;
266ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
267ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_STRSIZE				m_Length;
268ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
269ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_FileBufferArchive : public IFX_BufferArchive, public CFX_Object
270ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
271ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
272ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_FileBufferArchive(FX_STRSIZE size = 32768, IFX_Allocator* pAllocator = NULL);
273ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_FileBufferArchive();
274ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    virtual void			Clear();
275ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
276ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					AttachFile(IFX_StreamWrite *pFile, FX_BOOL bTakeover = FALSE);
277ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
278ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					AttachFile(FX_LPCWSTR filename);
279ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
280ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					AttachFile(FX_LPCSTR filename);
281ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprivate:
282ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
283ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    virtual FX_BOOL			DoWork(const void* pBuf, size_t size);
284ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
285ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_StreamWrite			*m_pFile;
286ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
287ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					m_bTakeover;
288ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
289ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovstruct CFX_CharMap {
290ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
291ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    static CFX_CharMap*		GetDefaultMapper(FX_INT32 codepage = 0);
292ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
293ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
294ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideString	(*m_GetWideString)(CFX_CharMap* pMap, const CFX_ByteString& bstr);
295ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
296ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteString	(*m_GetByteString)(CFX_CharMap* pMap, const CFX_WideString& wstr);
297ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
298ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32		(*m_GetCodePage)();
299ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
300ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_UTF8Decoder
301ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
302ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
303ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
304ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_UTF8Decoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
305ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
306ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_PendingBytes = 0;
307ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
308ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
309ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			Clear();
310ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
311ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			Input(FX_BYTE byte);
312ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
313ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			AppendChar(FX_DWORD ch);
314ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
315ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			ClearStatus()
316ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
317ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_PendingBytes = 0;
318ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
319ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
320ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideStringC	GetResult() const
321ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
322ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_Buffer.GetWideString();
323ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
324ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			GetResult(CFX_WideStringL &result) const
325ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
326ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_Buffer.GetWideStringL(result);
327ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
328ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
329ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
330ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_PendingBytes;
331ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
332ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD		m_PendingChar;
333ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
334ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_WideTextBuf	m_Buffer;
335ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
336ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_UTF8Encoder
337ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
338ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
339ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
340ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_UTF8Encoder(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator)
341ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
342ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_UTF16First = 0;
343ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
344ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
345ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			Input(FX_WCHAR unicode);
346ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
347ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			AppendStr(FX_BSTR str)
348ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
349ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_UTF16First = 0;
350ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_Buffer << str;
351ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
352ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
353ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteStringC	GetResult() const
354ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
355ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_Buffer.GetByteString();
356ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
357ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			GetResult(CFX_ByteStringL &result) const
358ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
359ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_Buffer.GetByteStringL(result);
360ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
361ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
362ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
363ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ByteTextBuf	m_Buffer;
364ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
365ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD		m_UTF16First;
366ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
367ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl);
368ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl);
369ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI);
370ee451cb395940862dad63c85adfe8f2fd55e864cSvet GanovCFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI);
371ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_BasicArray : public CFX_Object
372ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
373ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
374ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
375ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
376ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
377ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
378ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BasicArray(int unit_size, IFX_Allocator* pAllocator = NULL);
379ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
380ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_BasicArray();
381ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
382ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			SetSize(int nNewSize, int nGrowBy);
383ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
384ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			Append(const CFX_BasicArray& src);
385ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
386ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			Copy(const CFX_BasicArray& src);
387ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
388ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPBYTE		InsertSpaceAt(int nIndex, int nCount);
389ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
390ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			RemoveAt(int nIndex, int nCount);
391ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
392ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray);
393ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
394ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    const void*		GetDataPtr(int index) const;
395ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
396ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
397ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPBYTE		m_pData;
398ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
399ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_nSize;
400ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
401ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_nMaxSize;
402ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
403ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_nGrowBy;
404ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
405ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_nUnitSize;
406ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
407ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtemplate<class TYPE>
408ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_ArrayTemplate : public CFX_BasicArray
409ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
410ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
411ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
412ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ArrayTemplate(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(TYPE), pAllocator) {}
413ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
414ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int			GetSize() const
415ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
416ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nSize;
417ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
418ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
419ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int			GetUpperBound() const
420ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
421ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nSize - 1;
422ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
423ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
424ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		SetSize(int nNewSize, int nGrowBy = -1)
425ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
426ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_BasicArray::SetSize(nNewSize, nGrowBy);
427ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
428ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
429ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void		RemoveAll()
430ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
431ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        SetSize(0, -1);
432ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
433ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
434ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    const TYPE	GetAt(int nIndex) const
435ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
436ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex < 0 || nIndex >= m_nSize) {
437ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return (const TYPE&)(*(volatile const TYPE*)NULL);
438ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
439ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return ((const TYPE*)m_pData)[nIndex];
440ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
441ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
442ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		SetAt(int nIndex, TYPE newElement)
443ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
444ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex < 0 || nIndex >= m_nSize) {
445ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return FALSE;
446ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
447ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        ((TYPE*)m_pData)[nIndex] = newElement;
448ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return TRUE;
449ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
450ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
451ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    TYPE&		ElementAt(int nIndex)
452ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
453ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex < 0 || nIndex >= m_nSize) {
454ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return *(TYPE*)NULL;
455ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
456ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return ((TYPE*)m_pData)[nIndex];
457ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
458ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
459ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    const TYPE*	GetData() const
460ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
461ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (const TYPE*)m_pData;
462ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
463ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
464ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    TYPE*		GetData()
465ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
466ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (TYPE*)m_pData;
467ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
468ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
469ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		SetAtGrow(int nIndex, TYPE newElement)
470ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
471ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex < 0) {
472ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return FALSE;
473ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
474ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex >= m_nSize)
475ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            if (!SetSize(nIndex + 1, -1)) {
476ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                return FALSE;
477ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
478ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        ((TYPE*)m_pData)[nIndex] = newElement;
479ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return TRUE;
480ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
481ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
482ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		Add(TYPE newElement)
483ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
484ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_nSize < m_nMaxSize) {
485ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_nSize ++;
486ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else if (!SetSize(m_nSize + 1, -1)) {
487ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return FALSE;
488ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
489ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        ((TYPE*)m_pData)[m_nSize - 1] = newElement;
490ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return TRUE;
491ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
492ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
493ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		Append(const CFX_ArrayTemplate& src)
494ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
495ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_BasicArray::Append(src);
496ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
497ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
498ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		Copy(const CFX_ArrayTemplate& src)
499ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
500ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_BasicArray::Copy(src);
501ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
502ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
503ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    TYPE*		GetDataPtr(int index)
504ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
505ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (TYPE*)CFX_BasicArray::GetDataPtr(index);
506ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
507ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
508ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    TYPE*		AddSpace()
509ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
510ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (TYPE*)CFX_BasicArray::InsertSpaceAt(m_nSize, 1);
511ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
512ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
513ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    TYPE*		InsertSpaceAt(int nIndex, int nCount)
514ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
515ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (TYPE*)CFX_BasicArray::InsertSpaceAt(nIndex, nCount);
516ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
517ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
518ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    const TYPE	operator[](int nIndex) const
519ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
520ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex < 0 || nIndex >= m_nSize) {
521ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            *(volatile char*)0 = '\0';
522ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
523ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return ((const TYPE*)m_pData)[nIndex];
524ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
525ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
526ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    TYPE&		operator[](int nIndex)
527ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
528ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nIndex < 0 || nIndex >= m_nSize) {
529ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            *(volatile char*)0 = '\0';
530ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
531ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return ((TYPE*)m_pData)[nIndex];
532ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
533ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
534ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		InsertAt(int nIndex, TYPE newElement, int nCount = 1)
535ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
536ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (!InsertSpaceAt(nIndex, nCount)) {
537ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return FALSE;
538ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
539ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        while (nCount--) {
540ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ((TYPE*)m_pData)[nIndex++] = newElement;
541ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
542ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return TRUE;
543ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
544ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
545ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		RemoveAt(int nIndex, int nCount = 1)
546ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
547ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_BasicArray::RemoveAt(nIndex, nCount);
548ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
549ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
550ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL		InsertAt(int nStartIndex, const CFX_BasicArray* pNewArray)
551ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
552ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_BasicArray::InsertAt(nStartIndex, pNewArray);
553ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
554ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
555ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int			Find(TYPE data, int iStart = 0) const
556ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
557ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (iStart < 0) {
558ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return -1;
559ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
560ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        for (; iStart < (int)m_nSize; iStart ++)
561ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            if (((TYPE*)m_pData)[iStart] == data) {
562ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov                return iStart;
563ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            }
564ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return -1;
565ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
566ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
567ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<FX_BYTE>		CFX_ByteArray;
568ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<FX_WORD>		CFX_WordArray;
569ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<FX_DWORD>		CFX_DWordArray;
570ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<void*>		CFX_PtrArray;
571ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<FX_FILESIZE>	CFX_FileSizeArray;
572ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<FX_FLOAT>		CFX_FloatArray;
573ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ArrayTemplate<FX_INT32>		CFX_Int32Array;
574ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtemplate <class ObjectClass>
575ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_ObjectArray : public CFX_BasicArray
576ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
577ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
578ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
579ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_ObjectArray(IFX_Allocator* pAllocator = NULL) : CFX_BasicArray(sizeof(ObjectClass), pAllocator) {}
580ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
581ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_ObjectArray()
582ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
583ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        RemoveAll();
584ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
585ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
586ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			Add(const ObjectClass& data)
587ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
588ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass(data);
589ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
590ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
591ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ObjectClass&	Add()
592ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
593ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return *(ObjectClass*) new ((void*)InsertSpaceAt(m_nSize, 1)) ObjectClass();
594ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
595ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
596ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*			AddSpace()
597ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
598ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return InsertSpaceAt(m_nSize, 1);
599ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
600ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
601ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32		Append(const CFX_ObjectArray& src, FX_INT32 nStart = 0, FX_INT32 nCount = -1)
602ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
603ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nCount == 0) {
604ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return 0;
605ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
606ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_INT32 nSize = src.GetSize();
607ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (!nSize) {
608ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return 0;
609ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
610ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FXSYS_assert(nStart > -1 && nStart < nSize);
611ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nCount < 0) {
612ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            nCount = nSize;
613ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
614ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nStart + nCount > nSize) {
615ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            nCount = nSize - nStart;
616ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
617ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nCount < 1) {
618ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return 0;
619ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
620ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        nSize = m_nSize;
621ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        InsertSpaceAt(m_nSize, nCount);
622ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        ObjectClass* pStartObj = (ObjectClass*)GetDataPtr(nSize);
623ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        nSize = nStart + nCount;
624ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        for (FX_INT32 i = nStart; i < nSize; i ++, pStartObj++) {
625ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            new ((void*)pStartObj) ObjectClass(src[i]);
626ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
627ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return nCount;
628ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
629ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
630ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_INT32		Copy(const CFX_ObjectArray& src, FX_INT32 nStart = 0, FX_INT32 nCount = -1)
631ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
632ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nCount == 0) {
633ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return 0;
634ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
635ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_INT32 nSize = src.GetSize();
636ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (!nSize) {
637ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return 0;
638ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
639ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FXSYS_assert(nStart > -1 && nStart < nSize);
640ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nCount < 0) {
641ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            nCount = nSize;
642ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
643ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nStart + nCount > nSize) {
644ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            nCount = nSize - nStart;
645ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
646ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (nCount < 1) {
647ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return 0;
648ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
649ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        RemoveAll();
650ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        SetSize(nCount, -1);
651ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        ObjectClass* pStartObj = (ObjectClass*)m_pData;
652ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        nSize = nStart + nCount;
653ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        for (FX_INT32 i = nStart; i < nSize; i ++, pStartObj++) {
654ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            new ((void*)pStartObj) ObjectClass(src[i]);
655ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
656ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return nCount;
657ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
658ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
659ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				GetSize() const
660ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
661ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nSize;
662ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
663ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
664ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ObjectClass&	operator[] (int index) const
665ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
666ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FXSYS_assert(index < m_nSize);
667ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return *(ObjectClass*)CFX_BasicArray::GetDataPtr(index);
668ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
669ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
670ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ObjectClass*	GetDataPtr(int index)
671ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
672ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (ObjectClass*)CFX_BasicArray::GetDataPtr(index);
673ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
674ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
675ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			RemoveAt(int index)
676ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
677ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FXSYS_assert(index < m_nSize);
678ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        ((ObjectClass*)GetDataPtr(index))->~ObjectClass();
679ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_BasicArray::RemoveAt(index, 1);
680ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
681ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
682ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			RemoveAll()
683ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
684ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        for (int i = 0; i < m_nSize; i ++) {
685ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            ((ObjectClass*)GetDataPtr(i))->~ObjectClass();
686ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
687ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_BasicArray::SetSize(0, -1);
688ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
689ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
690ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ObjectArray<CFX_ByteString> CFX_ByteStringArray;
691ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef CFX_ObjectArray<CFX_WideString> CFX_WideStringArray;
692ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_BaseSegmentedArray : public CFX_Object
693ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
694ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
695ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
696ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BaseSegmentedArray(int unit_size = 1, int segment_units = 512, int index_size = 8, IFX_Allocator* pAllocator = NULL);
697ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
698ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_BaseSegmentedArray();
699ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
700ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	SetUnitSize(int unit_size, int segment_units, int index_size = 8);
701ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
702ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	Add();
703ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
704ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	GetAt(int index) const;
705ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
706ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	RemoveAll();
707ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
708ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	Delete(int index, int count = 1);
709ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
710ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int		GetSize() const
711ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
712ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_DataSize;
713ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
714ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
715ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int		GetSegmentSize() const
716ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
717ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_SegmentSize;
718ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
719ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
720ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int		GetUnitSize() const
721ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
722ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_UnitSize;
723ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
724ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
725ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	Iterate(FX_BOOL (*callback)(void* param, void* pData), void* param) const;
726ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
727ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
728ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprivate:
729ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
730ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_UnitSize;
731ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
732ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    short			m_SegmentSize;
733ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
734ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BYTE			m_IndexSize;
735ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
736ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BYTE			m_IndexDepth;
737ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
738ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				m_DataSize;
739ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
740ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*			m_pIndex;
741ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void**	GetIndex(int seg_index) const;
742ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	IterateIndex(int level, int& start, void** pIndex, FX_BOOL (*callback)(void* param, void* pData), void* param) const;
743ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	IterateSegment(FX_LPCBYTE pSegment, int count, FX_BOOL (*callback)(void* param, void* pData), void* param) const;
744ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
745ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtemplate <class ElementType>
746ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_SegmentedArray : public CFX_BaseSegmentedArray
747ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
748ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
749ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
750ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_SegmentedArray(int segment_units, int index_size = 8, IFX_Allocator* pAllocator = NULL)
751ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        : CFX_BaseSegmentedArray(sizeof(ElementType), segment_units, index_size, pAllocator)
752ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {}
753ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
754ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	Add(ElementType data)
755ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
756ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        *(ElementType*)CFX_BaseSegmentedArray::Add() = data;
757ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
758ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
759ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ElementType& operator [] (int index)
760ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
761ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return *(ElementType*)CFX_BaseSegmentedArray::GetAt(index);
762ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
763ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
764ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtemplate <class DataType, int FixedSize>
765ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_FixedBufGrow : public CFX_Object
766ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
767ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
768ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_FixedBufGrow(IFX_Allocator* pAllocator = NULL)
769ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        : m_pAllocator(pAllocator)
770ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        , m_pData(NULL)
771ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {}
772ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_FixedBufGrow(int data_size, IFX_Allocator* pAllocator = NULL)
773ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        : m_pAllocator(pAllocator)
774ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        , m_pData(NULL)
775ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
776ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (data_size > FixedSize) {
777ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size);
778ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else {
779ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
780ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
781ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
782ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void SetDataSize(int data_size)
783ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
784ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_pData) {
785ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FX_Allocator_Free(m_pAllocator, m_pData);
786ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
787ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pData = NULL;
788ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (data_size > FixedSize) {
789ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, data_size);
790ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        } else {
791ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FXSYS_memset32(m_Data, 0, sizeof(DataType)*FixedSize);
792ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
793ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
794ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_FixedBufGrow()
795ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
796ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_pData) {
797ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FX_Allocator_Free(m_pAllocator, m_pData);
798ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
799ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
800ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    operator DataType*()
801ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
802ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_pData ? m_pData : m_Data;
803ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
804ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprivate:
805ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
806ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    DataType		m_Data[FixedSize];
807ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    DataType*		m_pData;
808ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
809ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtemplate <class DataType>
810ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_TempBuf
811ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
812ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
813ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_TempBuf(int size, IFX_Allocator* pAllocator = NULL) : m_pAllocator(pAllocator)
814ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
815ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        m_pData = FX_Allocator_Alloc(m_pAllocator, DataType, size);
816ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
817ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_TempBuf()
818ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
819ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (m_pData) {
820ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            FX_Allocator_Free(m_pAllocator, m_pData);
821ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
822ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
823ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    DataType&	operator[](int i)
824ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
825ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FXSYS_assert(m_pData != NULL);
826ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_pData[i];
827ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
828ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    operator DataType*()
829ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
830ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_pData;
831ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
832ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprivate:
833ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
834ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    DataType*		m_pData;
835ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
836ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_MapPtrToPtr : public CFX_Object
837ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
838ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
839ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
840ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    struct CAssoc {
841ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
842ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CAssoc* pNext;
843ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
844ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        void* key;
845ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
846ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        void* value;
847ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    };
848ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
849ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
850ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_MapPtrToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
851ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
852ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_MapPtrToPtr();
853ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
854ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int GetCount() const
855ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
856ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nCount;
857ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
858ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
859ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL IsEmpty() const
860ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
861ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nCount == 0;
862ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
863ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
864ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL Lookup(void* key, void*& rValue) const;
865ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
866ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void* GetValueAt(void* key) const;
867ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
868ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*& operator[](void* key);
869ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
870ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void SetAt(void* key, void* newValue)
871ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
872ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        (*this)[key] = newValue;
873ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
874ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
875ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL RemoveKey(void* key);
876ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
877ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void RemoveAll();
878ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
879ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION GetStartPosition() const
880ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
881ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (m_nCount == 0) ? NULL : (FX_POSITION) - 1;
882ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
883ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
884ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void*& rValue) const;
885ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
886ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD GetHashTableSize() const
887ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
888ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nHashTableSize;
889ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
890ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
891ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
892ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
893ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
894ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
895ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
896ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc** m_pHashTable;
897ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
898ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD m_nHashTableSize;
899ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
900ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int m_nCount;
901ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
902ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc* m_pFreeList;
903ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
904ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    struct CFX_Plex* m_pBlocks;
905ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
906ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int m_nBlockSize;
907ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
908ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD HashKey(void* key) const;
909ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
910ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc* NewAssoc();
911ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
912ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void FreeAssoc(CAssoc* pAssoc);
913ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
914ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc* GetAssocAt(void* key, FX_DWORD& hash) const;
915ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
916ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtemplate <class KeyType, class ValueType>
917ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_MapPtrTemplate : public CFX_MapPtrToPtr
918ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
919ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
920ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
921ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_MapPtrTemplate(IFX_Allocator* pAllocator = NULL) : CFX_MapPtrToPtr(10, pAllocator) {}
922ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
923ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL	Lookup(KeyType key, ValueType& rValue) const
924ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
925ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_LPVOID pValue = NULL;
926ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (!CFX_MapPtrToPtr::Lookup((void*)(FX_UINTPTR)key, pValue)) {
927ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov            return FALSE;
928ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        }
929ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        rValue = (ValueType)(FX_UINTPTR)pValue;
930ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return TRUE;
931ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
932ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
933ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ValueType& operator[](KeyType key)
934ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
935ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (ValueType&)CFX_MapPtrToPtr::operator []((void*)(FX_UINTPTR)key);
936ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
937ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
938ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void SetAt(KeyType key, ValueType newValue)
939ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
940ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_MapPtrToPtr::SetAt((void*)(FX_UINTPTR)key, (void*)(FX_UINTPTR)newValue);
941ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
942ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
943ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL	RemoveKey(KeyType key)
944ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
945ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return CFX_MapPtrToPtr::RemoveKey((void*)(FX_UINTPTR)key);
946ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
947ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
948ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void GetNextAssoc(FX_POSITION& rNextPosition, KeyType& rKey, ValueType& rValue) const
949ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
950ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        void* pKey = NULL;
951ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        void* pValue = NULL;
952ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_MapPtrToPtr::GetNextAssoc(rNextPosition, pKey, pValue);
953ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        rKey = (KeyType)(FX_UINTPTR)pKey;
954ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        rValue = (ValueType)(FX_UINTPTR)pValue;
955ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
956ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
957ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_CMapDWordToDWord : public CFX_Object
958ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
959ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
960ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
961ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_CMapDWordToDWord(IFX_Allocator* pAllocator = NULL) : m_Buffer(pAllocator) {}
962ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
963ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			Lookup(FX_DWORD key, FX_DWORD& value) const;
964ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
965ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			SetAt(FX_DWORD key, FX_DWORD value);
966ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
967ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			EstimateSize(FX_DWORD size, FX_DWORD grow_by);
968ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
969ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION		GetStartPosition() const;
970ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
971ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWORD& value) const;
972ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
973ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
974ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BinaryBuf	m_Buffer;
975ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
976ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_MapByteStringToPtr : public CFX_Object
977ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
978ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
979ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
980ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    struct CAssoc {
981ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
982ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CAssoc* pNext;
983ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
984ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        FX_DWORD nHashValue;
985ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
986ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CFX_ByteString key;
987ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
988ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        void* value;
989ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    };
990ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
991ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
992ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_MapByteStringToPtr(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
993ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
994ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int GetCount() const
995ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
996ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nCount;
997ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
998ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
999ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL IsEmpty() const
1000ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1001ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nCount == 0;
1002ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1003ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1004ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL Lookup(FX_BSTR key, void*& rValue) const;
1005ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1006ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*& operator[](FX_BSTR key);
1007ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1008ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void SetAt(FX_BSTR key, void* newValue)
1009ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1010ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        (*this)[key] = newValue;
1011ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1012ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1013ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL RemoveKey(FX_BSTR key);
1014ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1015ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void RemoveAll();
1016ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1017ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION GetStartPosition() const
1018ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1019ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (m_nCount == 0) ? NULL : (FX_POSITION) - 1;
1020ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1021ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1022ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const;
1023ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1024ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPVOID		GetNextValue(FX_POSITION& rNextPosition) const;
1025ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1026ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD GetHashTableSize() const
1027ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1028ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nHashTableSize;
1029ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1030ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1031ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void InitHashTable(FX_DWORD hashSize, FX_BOOL bAllocNow = TRUE);
1032ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1033ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD HashKey(FX_BSTR key) const;
1034ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
1035ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1036ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
1037ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1038ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc** m_pHashTable;
1039ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1040ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_DWORD m_nHashTableSize;
1041ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1042ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int m_nCount;
1043ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1044ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc* m_pFreeList;
1045ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1046ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    struct CFX_Plex* m_pBlocks;
1047ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1048ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int m_nBlockSize;
1049ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1050ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc* NewAssoc();
1051ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1052ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void FreeAssoc(CAssoc* pAssoc);
1053ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1054ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CAssoc* GetAssocAt(FX_BSTR key, FX_DWORD& hash) const;
1055ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
1056ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1057ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_MapByteStringToPtr();
1058ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
1059ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_CMapByteStringToPtr : public CFX_Object
1060ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1061ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
1062ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1063ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator = NULL);
1064ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1065ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_CMapByteStringToPtr();
1066ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1067ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			RemoveAll();
1068ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1069ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION		GetStartPosition() const;
1070ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1071ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteString& rKey, void*& rValue) const;
1072ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1073ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPVOID		GetNextValue(FX_POSITION& rNextPosition) const;
1074ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1075ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL			Lookup(FX_BSTR key, void*& rValue) const;
1076ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1077ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			SetAt(FX_BSTR key, void* value);
1078ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1079ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			RemoveKey(FX_BSTR key);
1080ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1081ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int				GetCount() const;
1082ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1083ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void			AddValue(FX_BSTR key, void* pValue);
1084ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprivate:
1085ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1086ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_BaseSegmentedArray			m_Buffer;
1087ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
1088ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_PtrList : public CFX_Object
1089ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1090ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
1091ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1092ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    struct CNode {
1093ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1094ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CNode* pNext;
1095ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1096ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CNode* pPrev;
1097ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1098ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        void* data;
1099ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    };
1100ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
1101ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1102ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_PtrList(int nBlockSize = 10, IFX_Allocator* pAllocator = NULL);
1103ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1104ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION GetHeadPosition() const
1105ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1106ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (FX_POSITION)m_pNodeHead;
1107ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1108ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1109ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION GetTailPosition() const
1110ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1111ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return (FX_POSITION)m_pNodeTail;
1112ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1113ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1114ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	GetNext(FX_POSITION& rPosition) const
1115ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1116ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CNode* pNode = (CNode*) rPosition;
1117ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        rPosition = (FX_POSITION) pNode->pNext;
1118ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return pNode->data;
1119ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1120ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1121ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	GetPrev(FX_POSITION& rPosition) const
1122ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1123ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CNode* pNode = (CNode*) rPosition;
1124ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        rPosition = (FX_POSITION) pNode->pPrev;
1125ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return pNode->data;
1126ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1127ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1128ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION	GetNextPosition(FX_POSITION pos) const
1129ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1130ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return ((CNode*)pos)->pNext;
1131ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1132ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1133ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION	GetPrevPosition(FX_POSITION pos) const
1134ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1135ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return ((CNode*)pos)->pPrev;
1136ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1137ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1138ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void*	GetAt(FX_POSITION rPosition) const
1139ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1140ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CNode* pNode = (CNode*) rPosition;
1141ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return pNode->data;
1142ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1143ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1144ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int		GetCount() const
1145ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1146ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        return m_nCount;
1147ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1148ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1149ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION	AddTail(void* newElement);
1150ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1151ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION AddHead(void* newElement);
1152ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1153ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	SetAt(FX_POSITION pos, void* newElement)
1154ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1155ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        CNode* pNode = (CNode*) pos;
1156ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        pNode->data = newElement;
1157ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    }
1158ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1159ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION InsertAfter(FX_POSITION pos, void* newElement);
1160ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1161ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION Find(void* searchValue, FX_POSITION startAfter = NULL ) const;
1162ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1163ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_POSITION FindIndex(int index) const;
1164ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1165ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	RemoveAt(FX_POSITION pos);
1166ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1167ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void	RemoveAll();
1168ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovprotected:
1169ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1170ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    IFX_Allocator*	m_pAllocator;
1171ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1172ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CNode* m_pNodeHead;
1173ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1174ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CNode* m_pNodeTail;
1175ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1176ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int m_nCount;
1177ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1178ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CNode* m_pNodeFree;
1179ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1180ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    struct CFX_Plex* m_pBlocks;
1181ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1182ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    int m_nBlockSize;
1183ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1184ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CNode* NewNode(CNode* pPrev, CNode* pNext);
1185ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1186ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void FreeNode(CNode* pNode);
1187ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
1188ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1189ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_PtrList();
1190ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
1191ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovtypedef void (*PD_CALLBACK_FREEDATA)(FX_LPVOID pData);
1192ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovstruct FX_PRIVATEDATA {
1193ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1194ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					FreeData();
1195ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1196ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPVOID				m_pModuleId;
1197ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1198ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPVOID				m_pData;
1199ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1200ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    PD_CALLBACK_FREEDATA	m_pCallback;
1201ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1202ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					m_bSelfDestruct;
1203ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov};
1204ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovclass CFX_PrivateData
1205ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov{
1206ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganovpublic:
1207ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1208ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    CFX_PrivateData(IFX_Allocator* pAllocator = NULL) : m_DataList(pAllocator) {}
1209ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1210ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    ~CFX_PrivateData();
1211ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1212ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					ClearAll();
1213ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1214ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					SetPrivateData(FX_LPVOID module_id, FX_LPVOID pData, PD_CALLBACK_FREEDATA callback);
1215ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1216ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    void					SetPrivateObj(FX_LPVOID module_id, CFX_DestructObject* pObj);
1217ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1218ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_LPVOID				GetPrivateData(FX_LPVOID module_id);
1219ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov
1220ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    FX_BOOL					LookupPrivateData(FX_LPVOID module_id, FX_LPVOID &pData) const
1221ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov    {
1222ee451cb395940862dad63c85adfe8f2fd55e864cSvet Ganov        if (!module_id) {
1223