ScummVM API documentation
biff.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef STARK_FORMATS_BIFF_H
23 #define STARK_FORMATS_BIFF_H
24 
25 #include "common/array.h"
26 #include "common/scummsys.h"
27 
28 namespace Stark {
29 
30 class ArchiveReadStream;
31 
32 namespace Formats {
33 
34 class BiffObject;
35 
43 class BiffArchive {
44 public:
45  typedef BiffObject *(*ObjectBuilder)(uint32 type);
46 
47  BiffArchive(ArchiveReadStream *stream, ObjectBuilder objectBuilder);
48  ~BiffArchive();
49 
52 
54  template<class T>
56 
57 private:
58  void read(ArchiveReadStream *stream);
59  BiffObject *readObject(ArchiveReadStream *stream, BiffObject *parent);
60 
61  ObjectBuilder _objectBuilder;
62  uint32 _version;
63 
64  Common::Array<BiffObject *> _rootObjects;
65 };
66 
72 class BiffObject {
73 public:
74  BiffObject();
75  virtual ~BiffObject();
76 
80  virtual void readData(ArchiveReadStream *stream, uint32 dataLength) = 0;
81 
83  uint32 getType() const;
84 
86  template<class T>
87  Common::Array<T *> listChildrenRecursive();
88 
90  void addChild(BiffObject *child);
91 
92 protected:
93  uint32 _type;
94  uint32 _u3;
95  uint32 _version;
96 
97  BiffObject *_parent;
99 
100  friend class BiffArchive;
101 };
102 
103 template<class T>
106 
107  Common::Array<T *> array;
108  for (uint i = 0; i < objects.size(); i++) {
109  array.push_back(objects[i]->listChildrenRecursive<T>());
110  }
111 
112  return array;
113 }
114 
115 template<class T>
117  Common::Array<T *> list;
118 
119  for (uint i = 0; i < _children.size(); i++) {
120  if (_children[i]->getType() == T::TYPE) {
121  // Found a matching child
122  list.push_back(static_cast<T *>(_children[i]));
123  }
124 
125  // Look for matching resources in the child's children
126  list.push_back(_children[i]->listChildrenRecursive<T>());
127  }
128 
129  return list;
130 }
131 
132 } // End of namespace Formats
133 } // End of namespace Stark
134 
135 #endif // STARK_FORMATS_BIFF_H
Definition: biff.h:72
Common::Array< T * > listChildrenRecursive()
Definition: biff.h:116
Definition: array.h:52
Definition: biff.h:43
void push_back(const T &element)
Definition: array.h:180
Common::Array< T * > listObjectsRecursive()
Definition: biff.h:104
Definition: console.h:27
size_type size() const
Definition: array.h:315
Common::Array< BiffObject * > listObjects()
Definition: archiveloader.h:46