ScummVM API documentation
dbase.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 * This file is dual-licensed.
22 * In addition to the GPLv3 license mentioned above, this code is also
23 * licensed under LGPL 2.1. See LICENSES/COPYING.LGPL file for the
24 * full text of the license.
25 *
26 */
27
28#ifndef GOB_DBASE_H
29#define GOB_DBASE_H
30
31#include "common/system.h"
32#include "common/util.h"
33#include "common/str.h"
34#include "common/stream.h"
35#include "common/array.h"
36
37namespace Gob {
38
45
46public:
49
50 bool load(Common::SeekableReadStream &stream);
51 void clear();
52
54 public:
55 FieldReference() : _fieldName(""), _maxLength(0) {}
56 FieldReference(const Common::String &fieldName, size_t maxLength) : _fieldName(fieldName), _maxLength(maxLength) {}
57
58 const Common::String &getFieldName() const { return _fieldName; }
59 size_t getMaxLength() const { return _maxLength; }
60
61 private:
62 Common::String _fieldName;
63 size_t _maxLength;
64 };
65
66 static Common::Array<FieldReference> parseKeyDefinition(const Common::String &keyDefinition);
67
68 const Common::Array<FieldReference>* getTagKeyDefinition(Common::String tagName) const;
69
70private:
71 byte _version;
72 TimeDate _creationDate;
73 Common::String _dataFilename;
74 uint16 _nbrOfTagsInUse;
75 TimeDate _lastUpdate;
76
77 static const uint16 INDEX_PAGE_SIZE = 512;
79};
80
87class dBase {
88public:
89 enum Type {
90 kTypeString = 0x43, // 'C'
91 kTypeDate = 0x44, // 'D'
92 kTypeBool = 0x4C, // 'L'
93 kTypeMemo = 0x4D, // 'M'
94 kTypeNumber = 0x4E // 'N'
95 };
96
98 struct Field {
100
101 Type type;
102 uint8 size;
103 uint8 decimals;
104 };
105
107 struct Record {
108 bool deleted;
110 };
111
113 size_t fieldIndex;
114 size_t maxLength;
115 Common::String pattern;
116 };
117
118 dBase();
119 ~dBase();
120
121 bool load(Common::SeekableReadStream &stream);
122 bool loadMemo(Common::SeekableReadStream &stream);
123 bool loadMultipleIndex(Common::SeekableReadStream &stream);
124 void clear();
125
126 byte getVersion() const;
127 bool hasMemo() const;
128
131
132 const Common::Array<Field> &getFields() const;
133 const Common::Array<Record> &getRecords() const;
134
136 Common::String getString(const Record &record, int field) const;
137
138 void setQuery(const Common::String &query);
139 void setCurrentIndex(const Common::String &tagName);
140 void findFirstMatchingRecord();
141 void findNextMatchingRecord();
142 bool hasMatchingRecord();
143 Common::String getFieldOfMatchingRecord(Common::String fieldName);
144
145private:
146 byte _version;
147 byte _versionMajor;
148 bool _hasMemo;
149
150 TimeDate _lastUpdate;
151
152 Common::Array<Field> _fields;
153 Common::Array<Record> _records;
154
155 int _currentRecordIndex;
156 Common::Array<FieldPattern> _currentFieldFilter;
157
158 byte *_recordData;
159
161
162 Common::String _currentIndexTag;
163 bool _hasMultipleIndex;
164 dbaseMultipeIndex _multipleIndex;
165
166 static const uint16 MEMO_BLOCK_SIZE = 512;
167
168 static inline uint32 stringLength(const byte *data, uint32 max);
169 static inline Common::String readString(Common::SeekableReadStream &stream, int n);
170};
171
172} // End of namespace Gob
173
174#endif // GOB_DBASE_H
Definition: array.h:52
Definition: hashmap.h:85
Definition: stream.h:745
Definition: str.h:59
Definition: dbase.h:87
TimeDate getLastUpdate() const
Common::String getString(const Record &record, int field) const
Definition: dbase.h:44
Definition: dbase.h:98
Common::String name
Name of the field.
Definition: dbase.h:99
uint8 decimals
Number of decimals the field holds.
Definition: dbase.h:103
Type type
Type of the field.
Definition: dbase.h:101
uint8 size
Size of raw field data in bytes.
Definition: dbase.h:102
Definition: dbase.h:112
Definition: dbase.h:107
Common::Array< const byte * > fields
Raw field data.
Definition: dbase.h:109
bool deleted
Has this record been deleted?
Definition: dbase.h:108
Definition: system.h:111