DCL 4.0
Loading...
Searching...
No Matches
__LIST.cpp
Go to the documentation of this file.
1#ifdef __DCL_INTERNAL__
2
3#ifdef __COMPILE_StringList__
4 #define THIS_NAME __szStringList_cpp__
5 #define THIS_VALUE __T("dcl/__LIST.cpp/String")
6 #define LIST_T StringList
7 #define ELEMENT_T String
8 #define ELEMENT_T_CAST
9 #define CONST_ELEMENT_REF const String&
10 #define HAVE_CONSTRUCTOR_ELEMENT 1
11#elif defined(__COMPILE_ByteStringList__)
12 #define THIS_NAME __szByteStringList_cpp__
13 #define THIS_VALUE __T("dcl/__LIST.cpp/ByteString")
14 #define LIST_T ByteStringList
15 #define ELEMENT_T ByteString
16 #define ELEMENT_T_CAST
17 #define CONST_ELEMENT_REF const ByteString&
18 #define HAVE_CONSTRUCTOR_ELEMENT 1
19#elif defined(__COMPILE_PointerList__)
20 #define THIS_NAME __szPointerList_cpp__
21 #define THIS_VALUE __T("dcl/__LIST.cpp/void*")
22 #define LIST_T PointerList
23 #define ELEMENT_T void*
24 #define ELEMENT_T_CAST (void*)
25 #define CONST_ELEMENT_REF const void*
26 #define HAVE_CONSTRUCTOR_ELEMENT 0
27#endif
28
29#if __DCL_HAVE_THIS_FILE__
30 static const char_t THIS_NAME[] = THIS_VALUE;
31 #undef __THIS_FILE__
32 #define __THIS_FILE__ THIS_NAME
33#endif
34
35#if __DCL_HAVE_ALLOC_DEBUG
36 #undef __DCL_ALLOC_LEVEL
37 #define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
38#endif
39
41
43
44String LIST_T::toString() const
45{
46 StringBuilder r = __T("{");
47 for (ConstIterator it = begin(); it != end(); it++)
48 {
49 if (it != begin())
50 r += __T(", ");
51#ifdef __COMPILE_StringList__
52 r += __T("\"");
53 r += String::escape((*it), (*it).length());
54 r += __T("\"");
55#elif defined(__COMPILE_ByteStringList__)
56 r += __T("\"");
57 r += String::tryString((*it), 8);
58 r += __T("\"");
59#elif defined(__COMPILE_PointerList__)
60 r.format(__T("%p"), (*it));
61#else
62 r += (*it).toString();
63#endif
64 }
65 r += __T("}");
66 return r;
67}
68
70{
71 if (!isEmpty())
72 clear();
73 free(__pMasterNode);
74}
75
77{
78 __pMasterNode = (NodeBase*) malloc(sizeof(NodeBase));
79 // FIXME!
80 // if (pNode == NULL)
81 // throw new BadAllocException(sizeof(HashNode), __THIS_FILE__, __LINE__);
83
86 __size = 0;
87}
88
90{
91 __pMasterNode = (NodeBase*) malloc(sizeof(NodeBase));
92 // FIXME!
93 // if (pNode == NULL)
94 // throw new BadAllocException(sizeof(HashNode), __THIS_FILE__, __LINE__);
96
99 __size = 0;
100
101 insert(end(), _src.begin(), _src.end());
102}
103
104const LIST_T&
106{
107 if (&_src != this)
108 {
109 if (!isEmpty())
110 clear();
111 insert(end(), _src.begin(), _src.end());
112 }
113 return *this;
114}
115
117LIST_T::createNode(CONST_ELEMENT_REF _element)
118{
119 ListNode* pNode = (ListNode*) malloc(sizeof(ListNode));
120 // FIXME!
121 // if (pNode == NULL)
122 // throw new BadAllocException(sizeof(HashNode), __THIS_FILE__, __LINE__);
123
124#if __DCL_HAVE_ALLOC_DEBUG
125#undef new
126#endif
127
128#if HAVE_CONSTRUCTOR_ELEMENT
129 new(&(pNode->data)) ELEMENT_T;
130#endif
131
132#if __DCL_HAVE_ALLOC_DEBUG
133#define new __DCL_DEBUG_NEW
134#endif
135
136 pNode->data = ELEMENT_T_CAST _element;
137 return pNode;
138}
139
140void
142{
143#if HAVE_CONSTRUCTOR_ELEMENT
144 _pNode->data.~ELEMENT_T();
145#endif
146 free(_pNode);
147}
148
150LIST_T::insert(Iterator _pos, CONST_ELEMENT_REF _element)
151{
152 ListNode* pNewNode = createNode(_element);
153 pNewNode->pPrev = _pos.__pNode->pPrev;
154 pNewNode->pNext = _pos.__pNode;
155 _pos.__pNode->pPrev->pNext = pNewNode;
156 _pos.__pNode->pPrev = pNewNode;
157
158 __size++;
159
160 return (ListNode*)pNewNode;
161}
162
163void
165{
166 for(; _first != _last; _first++)
167 {
168 insert(_pos, *_first);
169 }
170}
171
173LIST_T::find(CONST_ELEMENT_REF _element)
174{
175 Iterator it = begin();
176 for (; it != end(); it++)
177 {
178 if (*it == _element)
179 break;
180 }
181 return it;
182}
183
184void
186{
187 ListNode* pNodeTemp = NULL;
188 NodeBase* pNode = __pMasterNode->pNext;
189 while(pNode != __pMasterNode)
190 {
191 pNodeTemp = (ListNode*)pNode;
192 pNode = pNode->pNext;
193 destroyNode(pNodeTemp);
194 }
197 __size = 0;
198}
199
202{
203 __DCL_ASSERT(_pos != end());
204 ListNode* pNodeTemp = (ListNode*)_pos.__pNode;
205 NodeBase* pNext = pNodeTemp->pNext;
206 pNodeTemp->pPrev->pNext = pNodeTemp->pNext;
207 pNodeTemp->pNext->pPrev = pNodeTemp->pPrev;
208 destroyNode(pNodeTemp);
209 __size--;
210 return (ListNode*)pNext;
211}
212
213ELEMENT_T
215{
217 ELEMENT_T result = *begin();
218 erase(begin());
219 return result;
220}
221
222ELEMENT_T
224{
226 Iterator it = end();
227 ELEMENT_T result = *(--it);
228 erase(it);
229 return result;
230}
231
232void
234{
235 if (_pos != _last)
236 {
237 _last.__pNode->pPrev->pNext = _pos.__pNode;
238 _first.__pNode->pPrev->pNext = _last.__pNode;
239 _pos.__pNode->pPrev->pNext = _first.__pNode;
240
241 NodeBase* pTemp = _pos.__pNode->pPrev;
242 _pos.__pNode->pPrev = _last.__pNode->pPrev;
243 _last.__pNode->pPrev = _first.__pNode->pPrev;
244 _first.__pNode->pPrev = pTemp;
245 }
246}
247
248void
250 LIST_T& _other, Iterator _otherFirst, Iterator _otherLast)
251{
252 size_t nMoveCount = size((ListNode*)(_otherFirst.__pNode),
253 (ListNode*)(_otherLast.__pNode));
254 __size += nMoveCount;
255 _other.__size -= nMoveCount;
256
257 move(_pos, _otherFirst, _otherLast);
258}
259
260size_t
262{
263 size_t nCount = 0;
264 for(; _first != _last; _first++)
265 nCount++;
266 return nCount;
267}
268
269#if __DCL_HAVE_THIS_FILE__
270 #undef __THIS_FILE__
271 #define __THIS_FILE__ __T(__FILE__)
272#endif
273
274#undef THIS_NAME
275#undef THIS_VALUE
276#undef LIST_T
277#undef ELEMENT_T
278#undef ELEMENT_T_CAST
279#undef CONST_ELEMENT_REF
280#undef HAVE_CONSTRUCTOR_ELEMENT
281
282#endif // __DCL_INTERNAL__
#define NULL
Definition Config.h:340
wchar_t char_t
Definition Config.h:275
#define __DCL_ASSERT(expr)
Definition Object.h:371
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:228
#define __T(str)
Definition Object.h:44
ByteString r
return result
ListNode * createNode(CONST_ELEMENT_REF _element)
Definition __LIST.cpp:117
LIST_T()
Definition __LIST.cpp:76
void move(Iterator posTo, Iterator _first, Iterator _last)
Definition __LIST.cpp:233
void destroyNode(ListNode *_pNode)
Definition __LIST.cpp:141
void splice(Iterator _pos, LIST_T &_other, Iterator _otherFirst, Iterator _otherLast)
Definition __LIST.cpp:249
virtual ~LIST_T()
ConstIterator end() const
Definition __LIST.h:513
ELEMENT_T removeHead()
Definition __LIST.cpp:214
const LIST_T & operator=(const LIST_T &_src)
Definition __LIST.cpp:105
Iterator find(CONST_ELEMENT_REF _element)
Definition __LIST.cpp:173
Iterator erase(Iterator _pos)
Definition __LIST.cpp:201
ELEMENT_T removeTail()
Definition __LIST.cpp:223
ConstIterator begin() const
Definition __LIST.h:506
size_t size() const
Definition __LIST.h:569
bool isEmpty() const
Definition __LIST.h:562
NodeBase * __pMasterNode
Definition __LIST.h:169
size_t __size
Definition __LIST.h:170
void clear()
Definition __LIST.cpp:185
Iterator insert(Iterator _pos, CONST_ELEMENT_REF _element)
Definition __LIST.cpp:150
NodeBase * __pNode
Definition ListBase.h:30
virtual String toString() const
Definition Object.cpp:187
ELEMENT_T data
Definition __LIST.h:60
NodeBase * pPrev
Definition ListBase.h:18
NodeBase * pNext
Definition ListBase.h:19