ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

biff.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef STARK_FORMATS_BIFF_H
00024 #define STARK_FORMATS_BIFF_H
00025 
00026 #include "common/array.h"
00027 #include "common/scummsys.h"
00028 
00029 namespace Stark {
00030 
00031 class ArchiveReadStream;
00032 
00033 namespace Formats {
00034 
00035 class BiffObject;
00036 
00044 class BiffArchive {
00045 public:
00046     typedef BiffObject *(*ObjectBuilder)(uint32 type);
00047 
00048     BiffArchive(ArchiveReadStream *stream, ObjectBuilder objectBuilder);
00049     ~BiffArchive();
00050 
00052     Common::Array<BiffObject *> listObjects();
00053 
00055     template<class T>
00056     Common::Array<T *> listObjectsRecursive();
00057 
00058 private:
00059     void read(ArchiveReadStream *stream);
00060     BiffObject *readObject(ArchiveReadStream *stream, BiffObject *parent);
00061 
00062     ObjectBuilder _objectBuilder;
00063     uint32 _version;
00064 
00065     Common::Array<BiffObject *> _rootObjects;
00066 };
00067 
00073 class BiffObject {
00074 public:
00075     BiffObject();
00076     virtual ~BiffObject();
00077 
00081     virtual void readData(ArchiveReadStream *stream, uint32 dataLength) = 0;
00082 
00084     uint32 getType() const;
00085 
00087     template<class T>
00088     Common::Array<T *> listChildrenRecursive();
00089 
00091     void addChild(BiffObject *child);
00092 
00093 protected:
00094     uint32 _type;
00095     uint32 _u3;
00096     uint32 _version;
00097 
00098     BiffObject *_parent;
00099     Common::Array<BiffObject *> _children;
00100 
00101     friend class BiffArchive;
00102 };
00103 
00104 template<class T>
00105 Common::Array<T *> BiffArchive::listObjectsRecursive() {
00106     Common::Array<BiffObject *> objects = listObjects();
00107 
00108     Common::Array<T *> array;
00109     for (uint i = 0; i < objects.size(); i++) {
00110         array.push_back(objects[i]->listChildrenRecursive<T>());
00111     }
00112 
00113     return array;
00114 }
00115 
00116 template<class T>
00117 Common::Array<T *> BiffObject::listChildrenRecursive() {
00118     Common::Array<T *> list;
00119 
00120     for (uint i = 0; i < _children.size(); i++) {
00121         if (_children[i]->getType() == T::TYPE) {
00122             // Found a matching child
00123             list.push_back(static_cast<T *>(_children[i]));
00124         }
00125 
00126         // Look for matching resources in the child's children
00127         list.push_back(_children[i]->listChildrenRecursive<T>());
00128     }
00129 
00130     return list;
00131 }
00132 
00133 } // End of namespace Formats
00134 } // End of namespace Stark
00135 
00136 #endif // STARK_FORMATS_BIFF_H


Generated on Sat Apr 20 2019 05:02:01 for ResidualVM by doxygen 1.7.1
curved edge   curved edge