Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cArrayRef.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cArrayRef_H
7 #define _INC_cArrayRef_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cArray.h"
13 #include "cRefPtr.h"
14 
15 namespace Gray
16 {
17 #define GRAY_FOREACH_S(a,b,c) GRAY_FOREACH( cRefPtr<a>, b, c )
18 
19  template<class TYPE>
20  class cArrayRef : public cArrayFacade < cRefPtr<TYPE>, TYPE* >
21  {
26 
28 
29  public:
30  void DisposeAll()
31  {
35 
36  ITERATE_t iSize = this->GetSize();
37  if (iSize <= 0)
38  return;
39  {
40  // save original list, call DisposeThis on everything from original list. In case Dispose removes itself from the list.
41  SUPER_t orig;
42  orig.SetCopy(*this);
43 
44  ASSERT(orig.GetSize() == iSize);
45  for (ITERATE_t i = iSize - 1; i >= 0; i--) // reverse order they got added?
46  {
47  TYPE* pObj = orig.GetAt(i);
48  if (pObj != nullptr)
49  {
50  pObj->DisposeThis();
51  }
52  }
53  }
54  this->RemoveAll();
55  }
56  };
57 }
58 #endif
#define TYPE
Definition: StrT.cpp:38
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cArray.h:99
void RemoveAll()
Clean up.
Definition: cArray.h:230
const TYPE & GetAt(ITERATE_t nIndex) const
Definition: cArray.h:162
ITERATE_t GetSize() const noexcept
Definition: cArray.h:137
Definition: cArray.h:804
Definition: cArrayRef.h:21
void DisposeAll()
Definition: cArrayRef.h:30
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int ITERATE_t
like size_t but signed
Definition: Index.h:28