scummvm/engine/lab.h

79 lines
2.1 KiB
C
Raw Normal View History

2006-04-02 14:20:45 +00:00
/* Residual - Virtual machine to run LucasArts' 3D adventure games
*
* Residual is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
2006-04-02 14:20:45 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* $URL$
* $Id$
*
*/
2003-08-15 18:00:22 +00:00
#ifndef LAB_H
#define LAB_H
2003-08-15 18:00:22 +00:00
#include <string>
2005-01-01 09:57:33 +00:00
#include <cstring>
2003-08-15 18:00:22 +00:00
#include <cstdio>
2004-02-21 15:20:01 +00:00
#include <map>
2003-08-15 18:00:22 +00:00
class Block {
public:
2004-12-09 23:55:43 +00:00
Block(const char *data, int len) : _data(data), _len(len) {}
const char *data() const { return _data; }
int len() const { return _len; }
2003-08-15 18:00:22 +00:00
2004-12-09 23:55:43 +00:00
~Block() { delete[] _data; }
2003-08-15 18:00:22 +00:00
private:
Block();
2004-12-09 23:55:43 +00:00
const char *_data;
int _len;
bool _owner;
2003-08-15 18:00:22 +00:00
};
class Lab {
public:
2004-12-09 23:55:43 +00:00
Lab() : _f(NULL) { }
explicit Lab(const char *filename) : _f(NULL) { open(filename); }
bool open(const char *filename);
2004-12-09 23:55:43 +00:00
bool isOpen() const { return _f != NULL; }
void close();
bool fileExists(const char *filename) const;
Block *getFileBlock(const char *filename) const;
std::FILE *openNewStream(const char *filename) const;
int fileLength(const char *filename) const;
2003-08-15 18:00:22 +00:00
~Lab() { close(); }
2003-08-15 18:00:22 +00:00
private:
struct LabEntry {
LabEntry(int the_offset, int the_len) :
offset(the_offset), len(the_len) {}
int offset, len;
};
2003-08-15 18:00:22 +00:00
2004-12-09 23:55:43 +00:00
std::FILE *_f;
2004-12-10 07:26:03 +00:00
typedef std::map<std::string, LabEntry> FileMapType;
FileMapType _fileMap;
2005-01-01 09:57:33 +00:00
std::string _labFileName;
2003-08-15 18:00:22 +00:00
2004-12-10 07:26:03 +00:00
FileMapType::const_iterator findFilename(const char *filename) const;
2003-08-15 18:00:22 +00:00
};
#endif