Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cECPGroupPrefs.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cECPGroupPrefs_H
6 #define _INC_cECPGroupPrefs_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "cECPGroupParams.h"
12 
13 namespace GrayLib
14 {
15  class cECPGroupPrefs // GRAYLIB_LINK
16  {
19 
20  private:
21  ECPGroup_TYPE* m_pGroupId;
22  bool m_bAllocated;
23 
24  public:
25  cECPGroupPrefs(const ECPGroup_TYPE* pGroupId = nullptr)
26  : m_pGroupId(const_cast<ECPGroup_TYPE*>(pGroupId))
27  , m_bAllocated(false)
28  {
29  }
31  {
32  SetNull();
33  }
34 
35  bool isNull() const
36  {
37  return m_pGroupId == nullptr;
38  }
39  bool isEmpty() const
40  {
41  return(isNull() || m_pGroupId[0] == ECPGroup_NONE);
42  }
43  ECPGroup_TYPE GetAt(int i) const
44  {
45  if (m_pGroupId == nullptr)
46  return ECPGroup_NONE;
47  return m_pGroupId[i];
48  }
49 
50  bool HasId(ECPGroup_TYPE id) const
51  {
52  ASSERT(m_pGroupId != nullptr);
53  for (int i = 0; m_pGroupId[i] != ECPGroup_NONE; i++)
54  {
55  if (m_pGroupId[i] == id)
56  return true;
57  }
58  return false;
59  }
60 
62  {
64  if (isNull())
65  return ECPGroup_NONE;
66  if (!prefs.isNull())
67  {
68  for (int i = 0; ; i++)
69  {
70  ECPGroup_TYPE id = prefs.GetAt(i);
71  if (HasId(id))
72  return id;
73  }
74  }
75  return GetAt(0); // just take the first i guess.
76  }
77 
78  void SetAt(int i, ECPGroup_TYPE id)
79  {
80  ASSERT(m_pGroupId != nullptr);
81  m_pGroupId[i] = id;
82  }
83 
84  void SetNull()
85  {
86  if (m_bAllocated)
87  {
88  delete m_pGroupId;
89  m_bAllocated = false;
90  }
91  m_pGroupId = nullptr;
92  }
93  void SetAllocQty(int iQty)
94  {
95  SetNull();
96  m_pGroupId = new ECPGroup_TYPE[iQty];
97  m_bAllocated = true;
98  }
99  };
100 }
101 
102 #endif
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cECPGroupPrefs.h:16
bool isEmpty() const
Definition: cECPGroupPrefs.h:39
bool isNull() const
Definition: cECPGroupPrefs.h:35
void SetAllocQty(int iQty)
Definition: cECPGroupPrefs.h:93
ECPGroup_TYPE GetAt(int i) const
Definition: cECPGroupPrefs.h:43
bool HasId(ECPGroup_TYPE id) const
Definition: cECPGroupPrefs.h:50
void SetAt(int i, ECPGroup_TYPE id)
Definition: cECPGroupPrefs.h:78
cECPGroupPrefs(const ECPGroup_TYPE *pGroupId=nullptr)
Definition: cECPGroupPrefs.h:25
void SetNull()
Definition: cECPGroupPrefs.h:84
~cECPGroupPrefs()
Definition: cECPGroupPrefs.h:30
ECPGroup_TYPE FindBestMatch(const cECPGroupPrefs &prefs) const
Definition: cECPGroupPrefs.h:61
Definition: cMesh.h:22
ECPGroup_TYPE
Definition: cECPGroupParams.h:28