OpenClonk
C4IDList.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* A dynamic list of C4IDs */
19 
20 #ifndef INC_C4IDList
21 #define INC_C4IDList
22 
23 #include "object/C4Id.h"
24 
25 // note that setting the chunk size for ID-Lists so low looks like an enormous waste
26 // at first glance - however, due there's an incredibly large number of small ID-Lists
27 // (99% of the lists have only one to three items!)
28 const size_t C4IDListChunkSize = 5; // size of id-chunks
29 
31 {
32 public:
35 
36  C4IDListChunk *pNext; // next chunk
37 
38 public:
39  C4IDListChunk(); // ctor
40  ~C4IDListChunk(); // dtor
41 
42 public:
43  void Clear(); // empty chunk and all behind
44 };
45 
46 class C4IDList : protected C4IDListChunk
47 {
48 public:
49  C4IDList();
50  C4IDList(const C4IDList &rCopy); // copy ctor
51  C4IDList &operator = (const C4IDList &rCopy); // assignment
52  ~C4IDList();
53  bool operator==(const C4IDList& rhs) const;
54 protected:
55  size_t Count; // number of IDs in this list
56 public:
57  // General
58  void Default();
59  void Clear();
60  bool IsClear() const;
61  // Access by direct index
62  C4ID GetID(size_t index, int32_t *ipCount=nullptr) const;
63  int32_t GetCount(size_t index) const;
64  bool SetCount(size_t index, int32_t iCount);
65  // Access by ID
66  int32_t GetIDCount(C4ID c_id, int32_t iZeroDefVal=0) const;
67  bool SetIDCount(C4ID c_id, int32_t iCount, bool fAddNewID=false);
68  bool IncreaseIDCount(C4ID c_id, bool fAddNewID=true, int32_t IncreaseBy=1, bool fRemoveEmpty=false);
69  bool DecreaseIDCount(C4ID c_id, bool fRemoveEmptyID=true)
70  { return IncreaseIDCount(c_id, false, -1, fRemoveEmptyID); }
71  int32_t GetNumberOfIDs() const;
72  int32_t GetIndex(C4ID c_id) const;
73  // Access by category-sorted index
74  C4ID GetID(C4DefList &rDefs, int32_t dwCategory, int32_t index, int32_t *ipCount=nullptr) const;
75  int32_t GetCount(C4DefList &rDefs, int32_t dwCategory, int32_t index) const;
76  bool SetCount(C4DefList &rDefs, int32_t dwCategory, int32_t index, int32_t iCount);
77  int32_t GetNumberOfIDs(C4DefList &rDefs, int32_t dwCategory) const;
78  // IDList merge
79  bool Add(C4IDList &rList);
80  // Aux
81  bool ConsolidateValids(C4DefList &rDefs, int32_t dwCategory = 0);
82  // Item operation
83  bool DeleteItem(size_t iIndex);
84  // Graphics
85  void Draw(C4Facet &cgo, int32_t iSelection,
86  C4DefList &rDefs, DWORD dwCategory,
87  bool fCounts=true, int32_t iAlign=0) const;
88  // Compiling
89  void CompileFunc(StdCompiler *pComp, bool fValues = true);
90 };
91 
92 #endif
const size_t C4IDListChunkSize
Definition: C4IDList.h:28
uint32_t DWORD
Definition: C4Id.h:26
void Clear()
Definition: C4IDList.cpp:40
C4IDListChunk * pNext
Definition: C4IDList.h:36
int32_t Count[C4IDListChunkSize]
Definition: C4IDList.h:34
bool DecreaseIDCount(C4ID c_id, bool fRemoveEmptyID=true)
Definition: C4IDList.h:69
int32_t GetCount(size_t index) const
Definition: C4IDList.cpp:125
bool IsClear() const
Definition: C4IDList.cpp:98
bool Add(C4IDList &rList)
Definition: C4IDList.cpp:422
void CompileFunc(StdCompiler *pComp, bool fValues=true)
Definition: stub-handle.cpp:69
bool SetCount(size_t index, int32_t iCount)
Definition: C4IDList.cpp:143
int32_t GetIndex(C4ID c_id) const
Definition: C4IDList.cpp:236
bool ConsolidateValids(C4DefList &rDefs, int32_t dwCategory=0)
Definition: C4IDList.cpp:439
bool SetIDCount(C4ID c_id, int32_t iCount, bool fAddNewID=false)
Definition: stub-handle.cpp:68
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
Definition: C4IDList.cpp:103
void Clear()
Definition: stub-handle.cpp:64
bool IncreaseIDCount(C4ID c_id, bool fAddNewID=true, int32_t IncreaseBy=1, bool fRemoveEmpty=false)
Definition: C4IDList.cpp:258
int32_t GetNumberOfIDs() const
Definition: C4IDList.cpp:231
bool operator==(const C4IDList &rhs) const
Definition: stub-handle.cpp:66
bool DeleteItem(size_t iIndex)
Definition: C4IDList.cpp:498
void Default()
Definition: stub-handle.cpp:63
size_t Count
Definition: C4IDList.h:55
void Draw(C4Facet &cgo, int32_t iSelection, C4DefList &rDefs, DWORD dwCategory, bool fCounts=true, int32_t iAlign=0) const
Definition: C4IDList.cpp:467
int32_t GetIDCount(C4ID c_id, int32_t iZeroDefVal=0) const
Definition: stub-handle.cpp:67
C4IDList & operator=(const C4IDList &rCopy)
Definition: stub-handle.cpp:65