OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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
C4IDList & operator=(const C4IDList &rCopy)
Definition: stub-handle.cpp:65
void Draw(C4Facet &cgo, int32_t iSelection, C4DefList &rDefs, DWORD dwCategory, bool fCounts=true, int32_t iAlign=0) const
Definition: C4IDList.cpp:394
int32_t GetIDCount(C4ID c_id, int32_t iZeroDefVal=0) const
Definition: stub-handle.cpp:67
void Clear()
Definition: stub-handle.cpp:64
bool ConsolidateValids(C4DefList &rDefs, int32_t dwCategory=0)
Definition: C4IDList.cpp:367
int32_t Count[C4IDListChunkSize]
Definition: C4IDList.h:34
int32_t GetCount(size_t index) const
Definition: C4IDList.cpp:111
bool SetCount(size_t index, int32_t iCount)
Definition: C4IDList.cpp:122
bool IsClear() const
Definition: C4IDList.cpp:94
C4IDListChunk * pNext
Definition: C4IDList.h:36
bool Add(C4IDList &rList)
Definition: C4IDList.cpp:351
bool DecreaseIDCount(C4ID c_id, bool fRemoveEmptyID=true)
Definition: C4IDList.h:69
void Default()
Definition: stub-handle.cpp:63
bool IncreaseIDCount(C4ID c_id, bool fAddNewID=true, int32_t IncreaseBy=1, bool fRemoveEmpty=false)
Definition: C4IDList.cpp:220
void Clear()
Definition: C4IDList.cpp:40
void CompileFunc(StdCompiler *pComp, bool fValues=true)
Definition: stub-handle.cpp:69
Definition: C4Id.h:28
const size_t C4IDListChunkSize
Definition: C4IDList.h:28
bool operator==(const C4IDList &rhs) const
Definition: stub-handle.cpp:66
bool SetIDCount(C4ID c_id, int32_t iCount, bool fAddNewID=false)
Definition: stub-handle.cpp:68
bool DeleteItem(size_t iIndex)
Definition: C4IDList.cpp:423
size_t Count
Definition: C4IDList.h:55
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
Definition: C4IDList.cpp:99
uint32_t DWORD
int32_t GetNumberOfIDs() const
Definition: C4IDList.cpp:197
int32_t GetIndex(C4ID c_id) const
Definition: C4IDList.cpp:202