Debian Codegraph @

engine/core/vfs/zip/zipnode.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21 #ifndef FIFE_VFS_ZIP_ZIPNODE_H
22 #define FIFE_VFS_ZIP_ZIPNODE_H
23
24 // Standard C++ library includes
25 #include <string>
26 #include <vector>
27 #include <ostream>
28
29 // 3rd party library includes
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/base/fife_stdint.h"
36
37 namespace FIFE {
38
39 struct ZipContentType {
40 enum Enum
41 {
42 File = 0, // specifies files as content type
43 Directory, // specifies directories as content type
44 All // specifies everything as content type (no filter)
45 };
46 };
47
48 struct ZipEntryData {
49 /** constructor
50 */
51 ZipEntryData();
52
53 uint16_t comp;
54 uint32_t crc32;
55 uint32_t size_comp;
56 uint32_t size_real;
57 uint32_t offset;
58 };
59
60 // convenience typedef
61 class ZipNode;
62 typedef std::vector<ZipNode*> ZipNodeContainer;
63
64 class ZipNode {
65 public:
66 /** constructor for creating a node
67 * @param name the name of the node
68 * @param parent the parent of this node, defaults to NULL
69 */
70 ZipNode(const std::string& name, ZipNode* parent=0);
71
72 /** destructor
73 */
74 ~ZipNode();
75
76 /** accessor for the name of this node
77 *
78 */
79 std::string getName() const;
80
81 /** accessor for the absolute path name of this node
82 */
83 std::string getFullName() const;
84
85 /** accessor for the content type of this node
86 * @return ZipContentType enumeration
87 */
88 ZipContentType::Enum getContentType() const;
89
90 /** accessor for the parent node of this node
91 * will be NULL if this node has no parent
92 */
93 ZipNode* getParent() const;
94
95 /** gives access to retrieve the children of this node
96 * @param contentType allows filtering on the type of nodes
97 * returned, @see ZipContentType for description
98 * @return vector of ZipNode pointers matching the request
99 */
100 std::vector<ZipNode*> getChildren(ZipContentType::Enum contentType=ZipContentType::All) const;
101
102 /** gives access to retrieving a specific child node by name
103 * @param name the name of the child node to search for
104 * @param contentType optional for filtering on the type of node to return
105 * @return the ZipNode pointer matching the child (NULL if not found)
106 */
107 ZipNode* getChild(const std::string& name,
108 ZipContentType::Enum contentType=ZipContentType::All) const;
109
110 /** allows adding a child node to this node
111 * @note this should only be used internally by the FIFE zip classes
112 * @param child the name to add as a child node
113 * @return the newly created child ZipNode
114 */
115 ZipNode* addChild(const std::string& child);
116
117 /** allows removing a child from this node
118 * @param child the child node to remove
119 */
120 void removeChild(ZipNode* child);
121
122 /** allows removing a child node by name
123 * @param name the name of the child to remove
124 */
125 void removeChild(const std::string& name);
126
127 /** accessor for checking if this node has any children
128 * @return true if node has no children
129 * false if node has children
130 */
131 bool isLeaf() const;
132
133 /** accessor for checking if this node has children
134 * @return true if node has children
135 * false if node does not have children
136 */
137 bool isBranch() const;
138
139 /** sets the zip file entry information for this
140 * node in the zip archive
141 * @param entryData the entry data that goes with this node
142 */
143 void setZipEntryData(const ZipEntryData& entryData);
144
145 /** accessor for the entry data associated with this node
146 * in the zip archive
147 * @return ZipEntryData for this node
148 */
149 const ZipEntryData& getZipEntryData() const;
150
151 private:
152 std::string m_name;
153 ZipContentType::Enum m_contentType;
154 ZipEntryData m_entryData;
155
156 ZipNode* m_parent;
157 ZipNodeContainer m_fileChildren;
158 ZipNodeContainer m_directoryChildren;
159 };
160 }
161
162 /** debug stream for a zip node
163 * useful for debugging
164 * @param os output stream
165 * @param node the ZipNode to output
166 * @return os output stream to allow for chaining
167 */
168 std::ostream& operator<<(std::ostream& os, const FIFE::ZipNode& node);
169
170 #endif