Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cThreadArray.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cThreadArray_H
8 #define _INC_cThreadArray_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cThreadLock.h"
14 #include "cArraySortRef.h"
15 #include "cArrayRef.h"
16 
17 namespace Gray
18 {
19  template <class TYPE>
21  : protected cArrayPtr < TYPE >
22  {
25 
26  public:
28  typedef typename SUPER_t::REF_t REF_t;
29  typedef typename SUPER_t::ELEM_t ELEM_t;
30  public:
32  public:
34  {
35  }
37  {
38  }
40  {
42  return SUPER_t::GetSize(); // just for stats purposes.
43  }
44  void SetSize(ITERATE_t nNewSize)
45  {
46  cThreadGuard threadguard(m_Lock); // thread sync critical section.
47  SUPER_t::SetSize(nNewSize); // just for stats purposes.
48  }
50  {
51  // add to tail
52  cThreadGuard threadguard(m_Lock); // thread sync critical section.
53  return SUPER_t::Add(pObj); // add to tail
54  }
55  REF_t GetAtCheck(ITERATE_t nIndex) const
56  {
57  cThreadGuard threadguard(m_Lock); // thread sync critical section.
58  return SUPER_t::GetAtCheck(nIndex);
59  }
60  bool HasArg(TYPE* pObj) const
61  {
63  cThreadGuard threadguard(m_Lock); // thread sync critical section.
64  return(SUPER_t::FindIFor(pObj) >= 0);
65  }
67  {
68  cThreadGuard threadguard(m_Lock); // thread sync critical section.
69  return SUPER_t::PopHead();
70  }
72  {
73  cThreadGuard threadguard(m_Lock); // thread sync critical section.
74  return SUPER_t::PopTail();
75  }
76  void DeleteAll()
77  {
78  cThreadGuard threadguard(m_Lock); // thread sync critical section.
79  for (int i = 0; i < this->GetSize(); i++)
80  {
81  delete this->GetAt(i);
82  }
84  }
85  bool RemoveArg(TYPE* pObj)
86  {
88  cThreadGuard threadguard(m_Lock); // thread sync critical section.
89  return SUPER_t::RemoveArg(pObj);
90  }
91  };
92 
93  template<class TYPE>
95  : protected cArrayRef < TYPE >
96  {
99  typedef cArrayRef<TYPE> SUPER_t;
100  public:
102  public:
104  {
105  }
107  {
108  }
109 
111  {
113  return SUPER_t::GetSize(); // just for stats purposes.
114  }
115 
116  // Locking helpers
118  {
123  cThreadGuard threadguard(m_Lock); // thread sync critical section.
124  return SUPER_t::GetAtCheck(nIndex);
125  }
127  {
128  // a queue.
129  cThreadGuard threadguard(m_Lock); // thread sync critical section.
130  return SUPER_t::PopHead(); // pop off head
131  }
133  {
134  // stack form = tail = latest.
135  cThreadGuard threadguard(m_Lock); // thread sync critical section.
136  return SUPER_t::PopTail(); // pop off tail
137  }
138  bool HasArg(TYPE* pObj) const
139  {
141  cThreadGuard threadguard(m_Lock); // thread sync critical section.
142  return SUPER_t::FindIFor(pObj) >= 0 ;
143  }
145  {
146  // add to tail
147  cThreadGuard threadguard(m_Lock); // thread sync critical section.
148  return SUPER_t::Add(pObj); // add to tail
149  }
151  {
152  // add to tail = latest. aka Push to stack.
153  cThreadGuard threadguard(m_Lock); // thread sync critical section.
154  return SUPER_t::AddTail(pObj); // add to tail
155  }
156  bool RemoveArg(TYPE* pObj)
157  {
159  cThreadGuard threadguard(m_Lock); // thread sync critical section.
160  return SUPER_t::RemoveArg(pObj);
161  }
162  void RemoveAll()
163  {
164  cThreadGuard threadguard(m_Lock); // thread sync critical section.
166  }
167  void DisposeAll()
168  {
170  cThreadGuard threadguard(m_Lock); // thread sync critical section.
172  }
173  // FindIForKey, RemoveAt must use a lock outside as well ! (for index to be meaningful)
174  };
175 
176  //*************************************************
177 
178  template<class TYPE, typename _TYPECH = TCHAR >
180  : protected cArraySortName < TYPE, _TYPECH >
181  {
187 
189  public:
191  public:
193  {
194  }
196  {
197  }
198 
199  // Locking helpers
201  {
206  cThreadGuard threadguard(m_Lock); // thread sync critical section.
207  return SUPER_t::GetAtCheck(nIndex);
208  }
209  cRefPtr<TYPE> FindArgForKey(const _TYPECH* pszKey) const
210  {
211  cThreadGuard threadguard(m_Lock); // thread sync critical section.
212  return(SUPER_t::FindArgForKey(pszKey));
213  }
215  {
216  cThreadGuard threadguard(m_Lock); // thread sync critical section.
217  return(SUPER_t::Add(pObj));
218  }
219  bool RemoveArgKey(TYPE* pObj)
220  {
221  cThreadGuard threadguard(m_Lock); // thread sync critical section.
222  return SUPER_t::RemoveArgKey(pObj);
223  }
225  {
227  return SUPER_t::GetSize(); // just for stats purposes.
228  }
229  void RemoveAll()
230  {
231  cThreadGuard threadguard(m_Lock); // thread sync critical section.
233  }
234  // FindIForKey, RemoveAt must use a lock outside as well ! (for index to be meaningful)
235  };
236 
237  template<class TYPE, typename _TYPE_HASH = HASHCODE_t>
239  : protected cArraySortHash < TYPE, _TYPE_HASH >
240  {
245 
246  // friend class cPtrTraceMgr;
248  public:
250  public:
252  {
253  }
255  {
256  }
257 
258  bool IsEmpty() const
259  {
261  return SUPER_t::IsEmpty();
262  }
264  {
266  return SUPER_t::GetSize();
267  }
269  {
275  cThreadGuard threadguard(m_Lock); // thread sync critical section.
276  return SUPER_t::GetAtCheck(nIndex);
277  }
279  {
280  cThreadGuard threadguard(m_Lock); // thread sync critical section.
281  return SUPER_t::Add(pObj); // AddTail
282  }
284  {
285  cThreadGuard threadguard(m_Lock); // thread sync critical section.
286  return SUPER_t::PopHead(); // pull off head
287  }
289  {
290  cThreadGuard threadguard(m_Lock); // thread sync critical section.
291  return SUPER_t::PopTail();
292  }
293  bool RemoveArgKey(TYPE* pObj)
294  {
295  cThreadGuard threadguard(m_Lock); // thread sync critical section.
296  return SUPER_t::RemoveArgKey(pObj);
297  }
298  void RemoveAll()
299  {
300  cThreadGuard threadguard(m_Lock); // thread sync critical section.
302  }
303  void DisposeAll()
304  {
306  cThreadGuard threadguard(m_Lock); // thread sync critical section.
308  }
309  cRefPtr<TYPE> FindArgForKey(_TYPE_HASH hashcode) const
310  {
311  cThreadGuard threadguard(m_Lock); // thread sync critical section.
312  return SUPER_t::FindArgForKey(hashcode);
313  }
314 
315 #if 0
316  ITERATE_t FindIForAK(const TYPE* pBase) const
317  {
318  // NOTE: Index must be considered invalid immediately!!
319  cThreadGuard threadguard(m_Lock); // thread sync critical section.
320  return SUPER_t::FindIForAK(pBase);
321  }
322 #endif
323 
324  // FindIForKey, RemoveAt must use a lock outside as well ! (for index to be meaningful)
325  };
326 
327  template<class TYPE, class _TYPE_KEY = ITERATE_t>
329  : protected cArraySortValue < TYPE, _TYPE_KEY >
330  {
336  public:
338  public:
340  {
341  }
343  {
344  }
345 
347  {
349  return SUPER_t::GetSize();
350  }
352  {
357  cThreadGuard threadguard(m_Lock); // thread sync critical section.
358  return SUPER_t::GetAtCheck(nIndex);
359  }
361  {
362  cThreadGuard threadguard(m_Lock); // thread sync critical section.
363  return SUPER_t::Add(pObj) ; // AddTail
364  }
366  {
367  cThreadGuard threadguard(m_Lock); // thread sync critical section.
368  return SUPER_t::AddAfter(pObj); // AddAfter
369  }
371  {
372  cThreadGuard threadguard(m_Lock); // thread sync critical section.
373  return SUPER_t::PopHead(); // pull off tail
374  }
376  {
377  cThreadGuard threadguard(m_Lock); // thread sync critical section.
378  return SUPER_t::PopTail();
379  }
380  bool RemoveArg(TYPE* pObj)
381  {
384  cThreadGuard threadguard(m_Lock); // thread sync critical section.
385  return SUPER_t::RemoveArg(pObj);
386  }
387  void RemoveAll()
388  {
389  cThreadGuard threadguard(m_Lock); // thread sync critical section.
391  }
392  void DisposeAll()
393  {
395  cThreadGuard threadguard(m_Lock); // thread sync critical section.
397  }
398 #if 0
399  ITERATE_t FindIForAK(const TYPE* pBase) const
400  {
401  // NOTE: Index must be considered invalid immediately!!
402  cThreadGuard threadguard(m_Lock); // thread sync critical section.
403  return(SUPER_t::FindIForAK(pBase));
404  }
405 #endif
407  {
408  cThreadGuard threadguard(m_Lock); // thread sync critical section.
410  }
411 
412  // FindIForKey, RemoveAt must use a lock outside as well ! (for index to be meaningful)
413  };
414 
415 #if 0
416  template<class TYPE>
417  class cThreadLockArrayWait
418  : protected cArrayRef < TYPE >
419  {
424  };
425 #endif
426 };
427 #endif
#define TYPE
Definition: StrT.cpp:38
Definition: cArray.h:99
void RemoveAll()
Clean up.
Definition: cArray.h:230
bool IsEmpty() const noexcept
Definition: cArray.h:145
ITERATE_t Add(const TYPE & newElement)
Definition: cArray.h:199
ITERATE_t GetSize() const noexcept
Definition: cArray.h:137
void SetSize(ITERATE_t nNewSize)
Definition: cArray.h:248
TYPE * PopHead()
Definition: cArray.h:844
REF_t GetAtCheck(ITERATE_t index) const
Definition: cArray.h:834
REF_t GetAt(ITERATE_t index) const
Definition: cArray.h:830
TYPE * PopTail()
Definition: cArray.h:852
Definition: cArray.h:864
SUPER_t::REF_t REF_t
Definition: cArray.h:871
SUPER_t::ELEM_t ELEM_t
Definition: cArray.h:872
Definition: cArrayRef.h:21
void DisposeAll()
Definition: cArrayRef.h:30
TYPE_PTR FindArgForKey(TYPE_KEY key1) const noexcept
Definition: cArraySort.h:455
ELEM_t PopHead()
Definition: cArraySort.h:477
ELEM_t PopTail()
Definition: cArraySort.h:485
REF_t GetAtCheck(ITERATE_t nIndex) const
Definition: cArraySort.h:445
Definition: cArraySortRef.h:60
ITERATE_t FindIForAK(const TYPE *pBase) const
Definition: cArraySortRef.h:93
bool RemoveArgKey(TYPE *pBase)
Definition: cArraySortRef.h:101
Definition: cArraySortRef.h:199
bool RemoveArgKey(TYPE *pBase)
Definition: cArraySortRef.h:237
void DisposeAll()
Definition: cArraySortRef.h:30
Definition: cArraySortRef.h:113
ITERATE_t FindIForAK(const TYPE *pBase) const
Definition: cArraySortRef.h:150
ITERATE_t AddAfter(TYPE *pBase)
Definition: cArraySortRef.h:179
Definition: cArraySort.h:24
ITERATE_t Add(TYPE pNew)
Definition: cArraySort.h:186
ARG_TYPE REF_t
How to refer to this? value or ref or pointer?
Definition: cArray.h:449
bool RemoveArg(ARG_TYPE arg)
Definition: cArray.h:650
ITERATE_t AddTail(ARG_TYPE newElement)
Definition: cArray.h:666
ITERATE_t FindIFor(ARG_TYPE arg) const
Definition: cArray.h:614
TYPE ELEM_t
What type is stored.
Definition: cArray.h:448
Definition: cLocker.h:72
Definition: cThreadArray.h:240
ITERATE_t Add(TYPE *pObj)
Definition: cThreadArray.h:278
cThreadLockCount m_Lock
Definition: cThreadArray.h:249
cRefPtr< TYPE > PopTail()
Definition: cThreadArray.h:288
ITERATE_t GetSize() const
Definition: cThreadArray.h:263
cRefPtr< TYPE > PopHead()
Definition: cThreadArray.h:283
cRefPtr< TYPE > FindArgForKey(_TYPE_HASH hashcode) const
Definition: cThreadArray.h:309
void RemoveAll()
Definition: cThreadArray.h:298
cRefPtr< TYPE > GetAtCheck(ITERATE_t nIndex) const
Definition: cThreadArray.h:268
~cThreadLockArrayHash()
Definition: cThreadArray.h:254
bool RemoveArgKey(TYPE *pObj)
Definition: cThreadArray.h:293
void DisposeAll()
Definition: cThreadArray.h:303
bool IsEmpty() const
Definition: cThreadArray.h:258
cThreadLockArrayHash()
Definition: cThreadArray.h:251
Definition: cThreadArray.h:181
bool RemoveArgKey(TYPE *pObj)
Definition: cThreadArray.h:219
ITERATE_t Add(TYPE *pObj)
Definition: cThreadArray.h:214
cThreadLockArrayName()
Definition: cThreadArray.h:192
cThreadLockCount m_Lock
Definition: cThreadArray.h:190
cRefPtr< TYPE > GetAtCheck(ITERATE_t nIndex) const
Definition: cThreadArray.h:200
void RemoveAll()
Definition: cThreadArray.h:229
cRefPtr< TYPE > FindArgForKey(const _TYPECH *pszKey) const
Definition: cThreadArray.h:209
~cThreadLockArrayName()
Definition: cThreadArray.h:195
ITERATE_t GetSize() const
Definition: cThreadArray.h:224
Definition: cThreadArray.h:22
cThreadLockArrayPtr()
Definition: cThreadArray.h:33
SUPER_t::REF_t REF_t
Definition: cThreadArray.h:28
SUPER_t::ELEM_t ELEM_t
Definition: cThreadArray.h:29
cThreadLockCount m_Lock
Definition: cThreadArray.h:31
bool HasArg(TYPE *pObj) const
Definition: cThreadArray.h:60
ITERATE_t Add(REF_t pObj)
Definition: cThreadArray.h:49
ELEM_t PopHead()
Definition: cThreadArray.h:66
cArrayPtr< TYPE > SUPER_t
Definition: cThreadArray.h:27
void SetSize(ITERATE_t nNewSize)
Definition: cThreadArray.h:44
~cThreadLockArrayPtr()
Definition: cThreadArray.h:36
ELEM_t PopTail()
Definition: cThreadArray.h:71
void DeleteAll()
Definition: cThreadArray.h:76
bool RemoveArg(TYPE *pObj)
Definition: cThreadArray.h:85
REF_t GetAtCheck(ITERATE_t nIndex) const
Definition: cThreadArray.h:55
ITERATE_t GetSize() const
Definition: cThreadArray.h:39
Definition: cThreadArray.h:96
bool HasArg(TYPE *pObj) const
Definition: cThreadArray.h:138
cRefPtr< TYPE > GetAtCheck(ITERATE_t nIndex) const
Definition: cThreadArray.h:117
void RemoveAll()
Definition: cThreadArray.h:162
cRefPtr< TYPE > PopTail()
Definition: cThreadArray.h:132
cThreadLockArraySmart()
Definition: cThreadArray.h:103
ITERATE_t AddTail(TYPE *pObj)
Definition: cThreadArray.h:150
~cThreadLockArraySmart()
Definition: cThreadArray.h:106
void DisposeAll()
Definition: cThreadArray.h:167
cRefPtr< TYPE > PopHead()
Definition: cThreadArray.h:126
ITERATE_t GetSize() const
Definition: cThreadArray.h:110
bool RemoveArg(TYPE *pObj)
Definition: cThreadArray.h:156
cThreadLockCount m_Lock
Definition: cThreadArray.h:101
ITERATE_t Add(TYPE *pObj)
Definition: cThreadArray.h:144
Definition: cThreadArray.h:330
cRefPtr< TYPE > FindArgForKey(_TYPE_KEY index) const
Definition: cThreadArray.h:406
ITERATE_t Add(TYPE *pObj)
Definition: cThreadArray.h:360
cRefPtr< TYPE > PopTail()
Definition: cThreadArray.h:375
~cThreadLockArrayValue()
Definition: cThreadArray.h:342
cThreadLockCount m_Lock
Definition: cThreadArray.h:337
bool RemoveArg(TYPE *pObj)
Definition: cThreadArray.h:380
ITERATE_t GetSize() const
Definition: cThreadArray.h:346
cRefPtr< TYPE > PopHead()
Definition: cThreadArray.h:370
cRefPtr< TYPE > GetAtCheck(ITERATE_t nIndex) const
Definition: cThreadArray.h:351
ITERATE_t AddAfter(TYPE *pObj)
Definition: cThreadArray.h:365
cThreadLockArrayValue()
Definition: cThreadArray.h:339
void RemoveAll()
Definition: cThreadArray.h:387
void DisposeAll()
Definition: cThreadArray.h:392
Definition: cThreadLock.h:498
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int ITERATE_t
like size_t but signed
Definition: Index.h:28
uint16 index
Definition: sample3.cpp:29