DCL 4.0
Loading...
Searching...
No Matches
ARRAY_T Class Reference

#include <__ARRAY.h>

Inheritance diagram for ARRAY_T:
Object

Classes

struct  Buffer

Public Types

typedef const ELEMENT_T * ConstIterator
typedef ELEMENT_T * Iterator

Public Member Functions

virtual ~ARRAY_T ()
 ARRAY_T (size_t _size=0)
 ARRAY_T (const ARRAY_T &_src)
const ARRAY_Toperator= (const ARRAY_T &_src)
ConstIterator begin () const
ConstIterator end () const
Iterator begin ()
Iterator end ()
void clear ()
void shrink ()
void resize (size_t _size)
Iterator insert (Iterator _pos, CONST_ELEMENT_REF _element)
ARRAY_Tinsert (size_t _index, CONST_ELEMENT_REF _element)
ARRAY_Tadd (CONST_ELEMENT_REF _element)
ARRAY_Tadd (const ARRAY_T &_src)
Iterator find (CONST_ELEMENT_REF _element)
Iterator erase (Iterator _pos)
Iterator erase (Iterator _first, Iterator _last)
ARRAY_Terase (size_t _index)
ARRAY_Terase (size_t _index, size_t _size)
size_t index (Iterator _pos) const
size_t size () const
bool isEmpty () const
ELEMENT_T & operator[] (size_t _index)
ELEMENT_T operator[] (size_t _index) const
ELEMENT_T * data () const
size_t size (ConstIterator _first, ConstIterator _last) const
size_t size (Iterator _first, Iterator _last) const
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Member Functions

Buffer__buf () const
size_t & __size () const
size_t & __maxSize () const
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Protected Attributes

ELEMENT_T * __pData

Detailed Description

template class Array의 DSO 호환성을 제공한다.

C++의 template class는 해당 코드를 사용하기 전에는 실제 이진 코드를 생성하지 않으므로, DSO(so, DLL)와 DSO, 또는 실행파일에서 객체를 주고받을 수 없다.

이 클래스는 DSO의 이러한 문제를 해결하며, 포함파일은 <dcl/Array.h>이다.

이 코드를 사용하는 클래스는 다음과 같다.

  • class DCLCAPI StringArray
  • class DCLCAPI ByteStringArray
  • class DCLCAPI PointerArray
See also
Array

Definition at line 54 of file __ARRAY.h.

Member Typedef Documentation

◆ ConstIterator

typedef const ELEMENT_T* ARRAY_T::ConstIterator

Definition at line 61 of file __ARRAY.h.

◆ Iterator

typedef ELEMENT_T* ARRAY_T::Iterator

Definition at line 62 of file __ARRAY.h.

Constructor & Destructor Documentation

◆ ~ARRAY_T()

ARRAY_T::~ARRAY_T ( )
virtual

Definition at line 121 of file __ARRAY.cpp.

122{
123 clear();
124 free(__buf());
125}
void CharsetConvertException *__fields clear()
Buffer * __buf() const
Definition __ARRAY.h:113

◆ ARRAY_T() [1/2]

ARRAY_T::ARRAY_T ( size_t _size = 0)

◆ ARRAY_T() [2/2]

ARRAY_T::ARRAY_T ( const ARRAY_T & _src)

Definition at line 115 of file __ARRAY.cpp.

116{
117 __pData = NULL;
118 *this = _src;
119}
#define NULL
Definition Config.h:340
ELEMENT_T * __pData
Definition __ARRAY.h:104

Member Function Documentation

◆ __buf()

Buffer * ARRAY_T::__buf ( ) const
inlineprotected

Definition at line 113 of file __ARRAY.h.

113{ return (Buffer*) __pData - 1; }

◆ __maxSize()

size_t & ARRAY_T::__maxSize ( ) const
inlineprotected

Definition at line 115 of file __ARRAY.h.

115{ return __buf()->__maxSize; }
size_t __maxSize
Definition __ARRAY.h:109

◆ __size()

size_t & ARRAY_T::__size ( ) const
inlineprotected

Definition at line 114 of file __ARRAY.h.

114{ return __buf()->__size; }
size_t __size
Definition __ARRAY.h:108

◆ add() [1/2]

ARRAY_T & ARRAY_T::add ( const ARRAY_T & _src)

Definition at line 254 of file __ARRAY.cpp.

255{
256 if (_src.size() > 0)
257 {
258 size_t newSize = size() + _src.size();
259 if (__maxSize() < newSize)
260 {
261 Buffer* buf = (Buffer*) realloc(__buf(), sizeof(Buffer) + newSize * sizeof(ELEMENT_T));
262 // FIXME!
263 // if (buf == NULL)
264 // throw new BadAllocException();
266
267 __pData = buf->data();
268 }
269
270 constructElements(__pData + size(), _src.size());
271 for(size_t i = 0; i < _src.size(); i++)
272 __pData[size() + i] = _src.__pData[i];
273
274 __maxSize() = __size() = newSize;
275 }
276 return *this;
277}
#define constructElements(_pElements, _size)
#define __DCL_ASSERT(expr)
Definition Object.h:371
ByteBuffer * buf
size_t size() const
Definition __ARRAY.h:203
size_t & __size() const
Definition __ARRAY.h:114
size_t & __maxSize() const
Definition __ARRAY.h:115

◆ add() [2/2]

ARRAY_T & ARRAY_T::add ( CONST_ELEMENT_REF _element)
inline

Definition at line 155 of file __ARRAY.h.

156{
157 return insert(size(), _element);
158}
Iterator insert(Iterator _pos, CONST_ELEMENT_REF _element)
Definition __ARRAY.cpp:214

◆ begin() [1/2]

ARRAY_T::Iterator ARRAY_T::begin ( )
inline

Definition at line 141 of file __ARRAY.h.

142{
143 return __pData;
144}

◆ begin() [2/2]

ARRAY_T::ConstIterator ARRAY_T::begin ( ) const
inline

Definition at line 127 of file __ARRAY.h.

128{
129 return (const ELEMENT_T*) __pData;
130}

◆ clear()

void ARRAY_T::clear ( )

Definition at line 141 of file __ARRAY.cpp.

142{
143 if (size() > 0)
144 {
145 destructElements(__pData, size());
146 __size() = 0;
147 }
148}
#define destructElements(_pElements, _size)

◆ data()

ELEMENT_T * ARRAY_T::data ( ) const
inline

Definition at line 233 of file __ARRAY.h.

234{
235 return __pData;
236}

◆ end() [1/2]

ARRAY_T::Iterator ARRAY_T::end ( )
inline

Definition at line 148 of file __ARRAY.h.

149{
150 return __pData + size();
151}

◆ end() [2/2]

ARRAY_T::ConstIterator ARRAY_T::end ( ) const
inline

Definition at line 134 of file __ARRAY.h.

135{
136 return (const ELEMENT_T*) __pData + size();
137}

◆ erase() [1/4]

ARRAY_T::Iterator ARRAY_T::erase ( Iterator _first,
Iterator _last )
inline

Definition at line 177 of file __ARRAY.h.

178{
179 __DCL_ASSERT_PARAM(begin() <= _first);
180 __DCL_ASSERT_PARAM(_last <= end());
181 erase(_first - begin(), _last - _first);
182 return _first;
183}
#define __DCL_ASSERT_PARAM(expr)
Definition Object.h:384
Iterator erase(Iterator _pos)
Definition __ARRAY.h:162
ConstIterator end() const
Definition __ARRAY.h:134
ConstIterator begin() const
Definition __ARRAY.h:127

◆ erase() [2/4]

ARRAY_T::Iterator ARRAY_T::erase ( Iterator _pos)
inline

Definition at line 162 of file __ARRAY.h.

163{
164 __DCL_ASSERT_PARAM(begin() <= _pos);
165 __DCL_ASSERT_PARAM(_pos < end());
166#if 0
167 erase(_pos - begin(), 1);
168 return _pos;
169#endif
170 size_t index = _pos - begin();
171 erase(index, 1);
172 return __pData + index;
173}
size_t index(Iterator _pos) const
Definition __ARRAY.h:195

◆ erase() [3/4]

ARRAY_T & ARRAY_T::erase ( size_t _index)
inline

Definition at line 187 of file __ARRAY.h.

188{
189 __DCL_ASSERT_PARAM(_index < size());
190 return erase(_index, 1);
191}

◆ erase() [4/4]

ARRAY_T & ARRAY_T::erase ( size_t _index,
size_t _size )

Definition at line 292 of file __ARRAY.cpp.

293{
294 __DCL_ASSERT_PARAM(_index + _size <= size());
295 if (_size > 0)
296 {
297 destructElements(__pData + _index, _size);
298 if (_index + _size < size())
299 memmove((void*)(__pData + _index), (const void*)(__pData + _index + _size),
300 (size() - (_index + _size)) * sizeof(ELEMENT_T));
301 __size() -= _size;
302 }
303 return *this;
304}

◆ find()

ARRAY_T::Iterator ARRAY_T::find ( CONST_ELEMENT_REF _element)

Definition at line 280 of file __ARRAY.cpp.

281{
282 Iterator it = begin();
283 for ( ; it != end(); it++)
284 {
285 if (*it == _element)
286 break;
287 }
288 return it;
289}
ELEMENT_T * Iterator
Definition __ARRAY.h:62

◆ index()

size_t ARRAY_T::index ( Iterator _pos) const
inline

Definition at line 195 of file __ARRAY.h.

196{
197 __DCL_ASSERT_PARAM(__pData <= _pos);
198 return _pos - __pData;
199}

◆ insert() [1/2]

ARRAY_T::Iterator ARRAY_T::insert ( Iterator _pos,
CONST_ELEMENT_REF _element )

Definition at line 214 of file __ARRAY.cpp.

215{
216 __DCL_ASSERT_PARAM(begin() <= _pos);
217 __DCL_ASSERT_PARAM(_pos <= end());
218
219 size_t index = _pos - __pData;
220 insert(index, _element);
221 return __pData + index + 1;
222}

◆ insert() [2/2]

ARRAY_T & ARRAY_T::insert ( size_t _index,
CONST_ELEMENT_REF _element )

Definition at line 225 of file __ARRAY.cpp.

226{
227 __DCL_ASSERT_HANDLE(__pData != NULL);
228 __DCL_ASSERT_PARAM(_index <= size());
229
230 size_t newSize = size() + 1;
231 if (__maxSize() < newSize)
232 {
233 Buffer* buf = (Buffer*) realloc(__buf(), sizeof(Buffer) + newSize * sizeof(ELEMENT_T));
234 // FIXME!
235 // if (buf == NULL)
236 // throw new BadAllocException();
238
239 buf->__maxSize = newSize;
240 __pData = buf->data();
241
242 if (_index < buf->__size)
243 memmove((void*)(__pData + _index + 1), (const void*)(__pData + _index),
244 sizeof(ELEMENT_T) * (buf->__size - _index));
245 }
246
247 constructElements(__pData + _index, 1);
248 __size() = newSize;
249 __pData[_index] = (ELEMENT_T) _element;
250 return *this;
251}
#define __DCL_ASSERT_HANDLE(expr)
Definition Object.h:383

◆ isEmpty()

bool ARRAY_T::isEmpty ( ) const
inline

Definition at line 210 of file __ARRAY.h.

211{
212 return size() == 0;
213}

◆ operator=()

const ARRAY_T & ARRAY_T::operator= ( const ARRAY_T & _src)

Definition at line 129 of file __ARRAY.cpp.

130{
131 if (&_src != this)
132 {
133 resize(_src.size());
134 for(size_t i = 0; i < _src.size(); i++)
135 __pData[i] = _src.__pData[i];
136 }
137 return *this;
138}
void resize(size_t _size)
Definition __ARRAY.cpp:167

◆ operator[]() [1/2]

ELEMENT_T & ARRAY_T::operator[] ( size_t _index)
inline

Definition at line 217 of file __ARRAY.h.

218{
219 __DCL_ASSERT_PARAM(_index < size());
220 return __pData[_index];
221}

◆ operator[]() [2/2]

ELEMENT_T ARRAY_T::operator[] ( size_t _index) const
inline

Definition at line 225 of file __ARRAY.h.

226{
227 __DCL_ASSERT_PARAM(_index < size());
228 return __pData[_index];
229}

◆ resize()

void ARRAY_T::resize ( size_t _size)

Definition at line 167 of file __ARRAY.cpp.

168{
169 if (__pData != NULL)
170 {
171 if (size() == _size)
172 return;
173
174 if (size() > _size)
175 {
176 destructElements(__pData + _size, size() - _size);
177 __size() = _size;
178 return;
179 }
180 }
181
182 if (__pData == NULL || __maxSize() < _size)
183 {
184 Buffer* buf = NULL;
185 if (__pData == NULL)
186 {
187 buf = (Buffer*) malloc(sizeof(Buffer) + _size * sizeof(ELEMENT_T));
188 // FIXME!
189 // if (buf == NULL)
190 // throw new BadAllocException();
192
193 buf->__size = 0;
194 }
195 else
196 {
197 buf = (Buffer*) realloc(__buf(), sizeof(Buffer) + _size * sizeof(ELEMENT_T));
198 // FIXME!
199 // if (buf == NULL)
200 // throw new BadAllocException();
202 }
203
204 buf->__maxSize = _size;
205 __pData = buf->data();
206 memset((void*)(__pData + buf->__size), 0, (_size - buf->__size) * sizeof(ELEMENT_T));
207 }
208
209 constructElements(__pData + size(), _size - size());
210 __size() = _size;
211}

◆ shrink()

void ARRAY_T::shrink ( )

Definition at line 151 of file __ARRAY.cpp.

152{
153 if (size() <__maxSize())
154 {
155 Buffer* buf = (Buffer*) realloc(__buf(), sizeof(Buffer) + size() * sizeof(ELEMENT_T));
156 // FIXME!
157 // if (buf == NULL)
158 // throw new BadAllocException();
160
161 buf->__maxSize = buf->__size;
162 __pData = buf->data();
163 }
164}

◆ size() [1/3]

size_t ARRAY_T::size ( ) const
inline

Definition at line 203 of file __ARRAY.h.

204{
205 return __buf()->__size;;
206}

◆ size() [2/3]

size_t ARRAY_T::size ( ConstIterator _first,
ConstIterator _last ) const
inline

Definition at line 240 of file __ARRAY.h.

241{
242 __DCL_ASSERT_PARAM(_first <= _last);
243 return _last - _first;
244}

◆ size() [3/3]

size_t ARRAY_T::size ( Iterator _first,
Iterator _last ) const
inline

Definition at line 248 of file __ARRAY.h.

249{
250 __DCL_ASSERT_PARAM(_first <= _last);
251 return _last - _first;
252}

Member Data Documentation

◆ __pData

ELEMENT_T* ARRAY_T::__pData
protected

Definition at line 104 of file __ARRAY.h.


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