summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tags.h
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2010-09-06 12:23:25 +0200
committerAdam Borowski <kilobyte@angband.pl>2010-09-06 12:23:25 +0200
commit79115ccbe604db26b47ab1d21f88ff751f487716 (patch)
tree9dd1451bc5431599b0e063ce64bb9ee4568ca933 /crawl-ref/source/tags.h
parentddf65d876d24150ca38a9aec9b66282b06615add (diff)
parenta087ed692319114f86589f392593ae50d704d48d (diff)
downloadcrawl-ref-79115ccbe604db26b47ab1d21f88ff751f487716.tar.gz
crawl-ref-79115ccbe604db26b47ab1d21f88ff751f487716.zip
Merge branch 'save-package'
Diffstat (limited to 'crawl-ref/source/tags.h')
-rw-r--r--crawl-ref/source/tags.h56
1 files changed, 28 insertions, 28 deletions
diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h
index 9dde3289cf..88fc8193bd 100644
--- a/crawl-ref/source/tags.h
+++ b/crawl-ref/source/tags.h
@@ -11,6 +11,7 @@
#include <stdint.h>
#include "tag-version.h"
+#include "package.h"
struct show_type;
struct monster_info;
@@ -19,16 +20,10 @@ struct map_cell;
enum tag_type // used during save/load process to identify data blocks
{
TAG_NO_TAG = 0, // should NEVER be read in!
- TAG_YOU = 1, // 'you' structure
- TAG_YOU_ITEMS, // your items
- TAG_YOU_DUNGEON, // dungeon specs (stairs, branches, features)
- TAG_LEVEL, // various grids & clouds
- TAG_LEVEL_ITEMS, // items/traps
- TAG_LEVEL_MONSTERS, // monsters
+ TAG_CHR = 1, // basic char info
+ TAG_YOU, // the main part of the save
+ TAG_LEVEL, // a single dungeon level
TAG_GHOST, // ghost
- TAG_LOST_MONSTERS, // monsters in transit
- TAG_LEVEL_TILES,
- TAG_GAME_STATE,
NUM_TAGS,
// Returned when a known tag was deliberately not read. This value is
@@ -36,15 +31,6 @@ enum tag_type // used during save/load process to identify data blocks
TAG_SKIP
};
-enum tag_file_type // file types supported by tag system
-{
- TAGTYPE_PLAYER = 0, // Foo.sav
- TAGTYPE_LEVEL, // Foo.00a, .01a, etc.
- TAGTYPE_GHOST, // bones.xxx
-
- TAGTYPE_PLAYER_NAME, // Used only to read the player name
-};
-
struct enum_info
{
void (*collect)(std::vector<std::pair<int,std::string> >& prs);
@@ -96,14 +82,23 @@ class writer
public:
writer(const std::string &filename, FILE* output,
bool ignore_errors = false)
- : _filename(filename), _file(output),
+ : _filename(filename), _file(output), _chunk(0),
_ignore_errors(ignore_errors), _pbuf(0), failed(false)
{
ASSERT(output);
}
writer(std::vector<unsigned char>* poutput)
- : _filename(), _file(0), _ignore_errors(false),
+ : _filename(), _file(0), _chunk(0), _ignore_errors(false),
_pbuf(poutput), failed(false) { ASSERT(poutput); }
+ writer(package *save, const std::string &chunkname)
+ : _filename(), _file(0), _chunk(0), _ignore_errors(false),
+ failed(false)
+ {
+ ASSERT(save);
+ _chunk = save->writer(chunkname);
+ }
+
+ ~writer() { if (_chunk) delete _chunk; }
void writeByte(unsigned char byte);
void write(const void *data, size_t size);
@@ -117,6 +112,7 @@ private:
private:
std::string _filename;
FILE* _file;
+ chunk_writer *_chunk;
bool _ignore_errors;
std::vector<unsigned char>* _pbuf;
@@ -161,12 +157,14 @@ class reader
public:
reader(const std::string &filename, int minorVersion = TAG_MINOR_VERSION);
reader(FILE* input, int minorVersion = TAG_MINOR_VERSION)
- : _file(input), opened_file(false), _pbuf(0), _read_offset(0),
- _minorVersion(minorVersion) {}
+ : _file(input), _chunk(0), opened_file(false), _pbuf(0),
+ _read_offset(0), _minorVersion(minorVersion) {}
reader(const std::vector<unsigned char>& input,
int minorVersion = TAG_MINOR_VERSION)
- : _file(0), opened_file(false), _pbuf(&input), _read_offset(0),
- _minorVersion(minorVersion) {}
+ : _file(0), _chunk(0), opened_file(false), _pbuf(&input),
+ _read_offset(0), _minorVersion(minorVersion) {}
+ reader(package *save, const std::string &chunkname,
+ int minorVersion = TAG_MINOR_VERSION);
~reader();
unsigned char readByte();
@@ -174,9 +172,11 @@ public:
void advance(size_t size);
int getMinorVersion();
bool valid() const;
+ void fail_if_not_eof(const std::string name);
private:
FILE* _file;
+ chunk_reader *_chunk;
bool opened_file;
const std::vector<unsigned char>* _pbuf;
unsigned int _read_offset;
@@ -186,6 +186,8 @@ private:
friend int unmarshallEnumVal(reader &, const enum_info *);
};
+class short_read_exception : std::exception {};
+
int8_t unmarshallByte (reader &);
int16_t unmarshallShort (reader &);
int32_t unmarshallInt (reader &);
@@ -226,10 +228,8 @@ static inline void unmarshallSigned(reader& th, T& v)
* Tag interface
* *********************************************************************** */
-tag_type tag_read(FILE* inf, int minorVersion, int8_t expected_tags[NUM_TAGS]);
-void tag_write(const std::string &filename, tag_type tagID, FILE* outf);
-void tag_set_expected(int8_t tags[], int fileType);
-void tag_missing(int tag, int minorVersion);
+void tag_read(reader &inf, int minorVersion, tag_type tag_id);
+void tag_write(tag_type tagID, writer &outf);
/* ***********************************************************************
* misc