File: biff.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (135 lines) | stat: -rw-r--r-- 3,498 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef STARK_FORMATS_BIFF_H
#define STARK_FORMATS_BIFF_H

#include "common/array.h"
#include "common/scummsys.h"

namespace Stark {

class ArchiveReadStream;

namespace Formats {

class BiffObject;

/**
 * A tree-style container for BiffObjects
 *
 * Users of this class must provide a factory method for the BiffObject subclasses
 * contained in the archive. This class can only read the archive's structure
 * and not specific object types.
 */
class BiffArchive {
public:
	typedef BiffObject *(*ObjectBuilder)(uint32 type);

	BiffArchive(ArchiveReadStream *stream, ObjectBuilder objectBuilder);
	~BiffArchive();

	/** List the objects at the root level of the archive */
	Common::Array<BiffObject *> listObjects();

	/** List objects recursively matching the template parameter type */
	template<class T>
	Common::Array<T *> listObjectsRecursive();

private:
	void read(ArchiveReadStream *stream);
	BiffObject *readObject(ArchiveReadStream *stream, BiffObject *parent);

	ObjectBuilder _objectBuilder;
	uint32 _version;

	Common::Array<BiffObject *> _rootObjects;
};

/**
 * An object which can be read from a BiffArchive
 *
 * Each object has a list of children objects, resulting in a tree structure
 */
class BiffObject {
public:
	BiffObject();
	virtual ~BiffObject();

	/**
	 * Used to read the object data from the stream
	 */
	virtual void readData(ArchiveReadStream *stream, uint32 dataLength) = 0;

	/** Get the object type */
	uint32 getType() const;

	/** List children recursively matching the template parameter type */
	template<class T>
	Common::Array<T *> listChildrenRecursive();

	/** Add an object to the children list */
	void addChild(BiffObject *child);

protected:
	uint32 _type;
	uint32 _u3;
	uint32 _version;

	BiffObject *_parent;
	Common::Array<BiffObject *> _children;

	friend class BiffArchive;
};

template<class T>
Common::Array<T *> BiffArchive::listObjectsRecursive() {
	Common::Array<BiffObject *> objects = listObjects();

	Common::Array<T *> array;
	for (uint i = 0; i < objects.size(); i++) {
		array.push_back(objects[i]->listChildrenRecursive<T>());
	}

	return array;
}

template<class T>
Common::Array<T *> BiffObject::listChildrenRecursive() {
	Common::Array<T *> list;

	for (uint i = 0; i < _children.size(); i++) {
		if (_children[i]->getType() == T::TYPE) {
			// Found a matching child
			list.push_back(static_cast<T *>(_children[i]));
		}

		// Look for matching resources in the child's children
		list.push_back(_children[i]->listChildrenRecursive<T>());
	}

	return list;
}

} // End of namespace Formats
} // End of namespace Stark

#endif // STARK_FORMATS_BIFF_H