OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4GroupSet.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // a set of group files
17 // manages system file overwriting by scearios or folders
18 
19 #ifndef INC_C4GroupSet
20 #define INC_C4GroupSet
21 
22 // group set priorities
23 #define C4GSPrio_Base 0 // lowest priority for global system files
24 #define C4GSPrio_Pack 1 // overloads by object packs
25 #define C4GSPrio_ExtraRoot 2 // overloads by Extra.ocg root folder
26 #define C4GSPrio_Extra 3 // overloads by Extra.ocg
27 #define C4GSPrio_Definition 4 // overloads by definition file - latter defined definition files have higher priority
28 #define C4GSPrio_Definition2 99 // highest priority a given definition may have
29 #define C4GSPrio_Folder 100 // overloads by local scenario folder - each child folder has higher priority
30 #define C4GSPrio_Folder2 199 // highest priority a folder may have
31 #define C4GSPrio_Scenario 200 // overloads by scenario: highest priority
32 
33 // group node contents
34 #define C4GSCnt_Graphics 1 // contains Graphics.ocg
35 #define C4GSCnt_Loaders 2 // contains loader files
36 #define C4GSCnt_Material 4 // contains Material.ocg
37 #define C4GSCnt_Music 8 // contains music
38 #define C4GSCnt_Definitions 16 // contains definition files
39 #define C4GSCnt_FontDefs 32 // contains font definitions
40 #define C4GSCnt_Language 64 // contains language files
41 #define C4GSCnt_Component 128 // other components
42 
43 #define C4GSCnt_Folder (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
44 #define C4GSCnt_OriginFolder (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
45 #define C4GSCnt_Directory (C4GSCnt_Loaders | C4GSCnt_Music)
46 #define C4GSCnt_Scenario C4GSCnt_Folder
47 #define C4GSCnt_Root (C4GSCnt_Graphics | C4GSCnt_Material)
48 #define C4GSCnt_Extra (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
49 #define C4GSCnt_ExtraRoot (C4GSCnt_Graphics | C4GSCnt_Loaders | C4GSCnt_Material | C4GSCnt_Music | C4GSCnt_FontDefs)
50 
51 #define C4GSCnt_All ~0
52 
53 // one node in the group set holds one group
55 {
56 protected:
57  class C4GroupSet *pParent; // owning set
58  C4GroupSetNode *pPrev, *pNext; // linked list - always valid
59 
60  C4Group *pGroup; // ptr to group owned by this node
61  bool fGrpOwned; // flag if group ptr is owned
62 
63  int32_t id; // group node ID
64 
65 public:
66  C4GroupSetNode(class C4GroupSet &rParent, C4GroupSetNode *pPrev, C4Group &rGroup, bool fGrpOwned, int32_t id); // ctor
67  ~C4GroupSetNode(); // dtor
68 
69  int32_t Priority; // group priority
70  int32_t Contents; // content held by this group
71 
72  friend class C4GroupSet;
73 };
74 
75 // a group set manages file overloading within several groups
77 {
78 protected:
79  C4GroupSetNode *pFirst, *pLast; // linked list
80  int32_t iIndex; // index to keep track of group node IDs
81 
82 public:
83  bool UnregisterGroup(int32_t iIndex);
84  void Clear();
85  void Default();
86 
87  C4GroupSet(); // ctor
88  C4GroupSet(const C4GroupSet &rCopy); // copy-constructor that registers all groups with all contents
89  ~C4GroupSet(); // dtor
90 
91  bool RegisterGroup(C4Group &rGroup, bool fOwnGrp, int32_t Priority, int32_t Contents, bool fCheckContent=true); // add group to list
92  bool RegisterGroups(const C4GroupSet &rCopy, int32_t Contents, const char *szFilename=nullptr, int32_t iMaxSkipID=0); // add all matching (child-)groups of the set
93  C4Group *FindGroup(int32_t Contents, C4Group *pAfter=nullptr, bool fSamePrio=false); // search for suitable group in list
94  C4Group *FindEntry(const char *szWildcard, int32_t *pPriority=nullptr, int32_t *pID=nullptr); // find entry in groups; store priority of group if ptr is given
95  C4Group *FindSuitableFile(const char *szName, const char * const extensions[], char *szFileName, int32_t *pID=nullptr);
96  int32_t GetGroupCount();
97  C4Group *GetGroup(int32_t iIndex);
98  bool LoadEntry(const char *szEntryName, char **lpbpBuf, size_t *ipSize=nullptr, int32_t iAppendZeros=0);
99  bool LoadEntryString(const char *szEntryName, StdStrBuf * rBuf);
100  bool LoadEntryString(const StdStrBuf & name, StdStrBuf * Buf) { return LoadEntryString(name.getData(), Buf); }
101  C4Group *RegisterParentFolders(const char *szScenFilename); // register all parent .ocf groups to the given scenario filename and return an open group file of the innermost parent ocf
102  int32_t PreCacheEntries(const char *szEntryMask); // pre-cache all entries matching mask for packed files in all groups.
103 
104  static int32_t CheckGroupContents(C4Group &rGroup, int32_t Contents);
105  int32_t GetLastID() { return iIndex; } // return ID assigned to the last added group
106 
107  bool CloseFolders(); // remove all groups associated with scenario folders
108 
109  friend class C4GroupSetNode;
110 };
111 
112 #endif
const char * getData() const
Definition: StdBuf.h:442
void Default()
Definition: C4GroupSet.cpp:57
bool RegisterGroup(C4Group &rGroup, bool fOwnGrp, int32_t Priority, int32_t Contents, bool fCheckContent=true)
Definition: C4GroupSet.cpp:88
class C4GroupSet * pParent
Definition: C4GroupSet.h:57
int32_t PreCacheEntries(const char *szEntryMask)
Definition: C4GroupSet.cpp:375
C4GroupSetNode * pPrev
Definition: C4GroupSet.h:58
C4Group * FindSuitableFile(const char *szName, const char *const extensions[], char *szFileName, int32_t *pID=nullptr)
Definition: C4GroupSet.cpp:191
bool RegisterGroups(const C4GroupSet &rCopy, int32_t Contents, const char *szFilename=nullptr, int32_t iMaxSkipID=0)
Definition: C4GroupSet.cpp:128
C4GroupSetNode * pLast
Definition: C4GroupSet.h:79
int32_t GetGroupCount()
Definition: C4GroupSet.cpp:251
int32_t iIndex
Definition: C4GroupSet.h:80
bool UnregisterGroup(int32_t iIndex)
Definition: C4GroupSet.cpp:274
bool LoadEntryString(const StdStrBuf &name, StdStrBuf *Buf)
Definition: C4GroupSet.h:100
int32_t id
Definition: C4GroupSet.h:63
C4Group * FindEntry(const char *szWildcard, int32_t *pPriority=nullptr, int32_t *pID=nullptr)
Definition: C4GroupSet.cpp:175
int32_t GetLastID()
Definition: C4GroupSet.h:105
int32_t Contents
Definition: C4GroupSet.h:70
C4GroupSetNode * pFirst
Definition: C4GroupSet.h:79
C4Group * RegisterParentFolders(const char *szScenFilename)
Definition: C4GroupSet.cpp:294
void Clear()
Definition: C4GroupSet.cpp:50
bool LoadEntry(const char *szEntryName, char **lpbpBuf, size_t *ipSize=nullptr, int32_t iAppendZeros=0)
Definition: C4GroupSet.cpp:215
bool LoadEntryString(const char *szEntryName, StdStrBuf *rBuf)
Definition: C4GroupSet.cpp:225
int32_t Priority
Definition: C4GroupSet.h:69
C4GroupSetNode(class C4GroupSet &rParent, C4GroupSetNode *pPrev, C4Group &rGroup, bool fGrpOwned, int32_t id)
Definition: C4GroupSet.cpp:25
C4GroupSetNode * pNext
Definition: C4GroupSet.h:58
C4Group * FindGroup(int32_t Contents, C4Group *pAfter=nullptr, bool fSamePrio=false)
Definition: C4GroupSet.cpp:155
static int32_t CheckGroupContents(C4Group &rGroup, int32_t Contents)
Definition: C4GroupSet.cpp:106
bool CloseFolders()
Definition: C4GroupSet.cpp:235
C4Group * pGroup
Definition: C4GroupSet.h:60
C4Group * GetGroup(int32_t iIndex)
Definition: C4GroupSet.cpp:259