xoreos  0.0.5
gdafile.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_GDAFILE_H
26 #define AURORA_GDAFILE_H
27 
28 #include <vector>
29 #include <map>
30 
31 #include <boost/noncopyable.hpp>
32 
33 #include "src/common/ustring.h"
34 #include "src/common/ptrvector.h"
35 
36 #include "src/aurora/types.h"
37 
38 namespace Common {
39  class UString;
40  class SeekableReadStream;
41 }
42 
43 namespace Aurora {
44 
62 class GDAFile : boost::noncopyable {
63 public:
64  static const size_t kInvalidColumn = SIZE_MAX;
65  static const size_t kInvalidRow = SIZE_MAX;
66 
67  enum Type {
68  kTypeEmpty = -1,
70  kTypeInt = 1,
72  kTypeBool = 3,
74  };
75 
76  struct Header {
79 
81 
82  Header() : hash(0), type(kTypeEmpty), field(0xFFFFFFFF) { }
83  };
84  typedef std::vector<Header> Headers;
85 
86 
89  ~GDAFile();
90 
100  void add(Common::SeekableReadStream *gda);
101 
103  size_t getColumnCount() const;
105  size_t getRowCount() const;
106 
108  bool hasRow(size_t row) const;
109 
111  const Headers &getHeaders() const;
112 
114  const GFF4Struct *getRow(size_t row) const;
115 
117  size_t findRow(uint32 id) const;
118 
120  size_t findColumn(const Common::UString &name) const;
122  size_t findColumn(uint32 hash) const;
123 
124  Common::UString getString(size_t row, uint32 columnHash, const Common::UString &def = "") const;
125  Common::UString getString(size_t row, const Common::UString &columnName,
126  const Common::UString &def = "") const;
127 
128  int32 getInt(size_t row, uint32 columnHash, int32 def = 0) const;
129  int32 getInt(size_t row, const Common::UString &columnName, int32 def = 0) const;
130 
131  float getFloat(size_t row, uint32 columnHash, float def = 0.0f) const;
132  float getFloat(size_t row, const Common::UString &columnName, float def = 0.0f) const;
133 
134 
135 private:
137  typedef const GFF4List * Columns;
138  typedef const GFF4List * Row;
139  typedef std::vector<Row> Rows;
140  typedef std::vector<size_t> RowStarts;
141 
142  typedef std::map<uint32, size_t> ColumnHashMap;
143  typedef std::map<Common::UString, size_t> ColumnNameMap;
144 
145 
147 
149 
152 
153  size_t _rowCount;
154 
156 
159 
160 
161  void load(Common::SeekableReadStream *gda);
162 
163  Type identifyType(const Columns &columns, const Row &rows, size_t column) const;
164 
165  const GFF4Struct *getRowColumn(size_t row, uint32 hash, size_t &column) const;
166  const GFF4Struct *getRowColumn(size_t row, const Common::UString &name, size_t &column) const;
167 };
168 
169 } // End of namespace Aurora
170 
171 #endif // AURORA_GDAFILE_H
Common::PtrVector< GFF4File > GFF4s
Definition: gdafile.h:136
std::vector< size_t > RowStarts
Definition: gdafile.h:140
int32 getInt(size_t row, uint32 columnHash, int32 def=0) const
Definition: gdafile.cpp:184
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
float getFloat(size_t row, uint32 columnHash, float def=0.0f) const
Definition: gdafile.cpp:202
std::vector< Row > Rows
Definition: gdafile.h:139
RowStarts _rowStarts
Definition: gdafile.h:155
const GFF4List * Row
Definition: gdafile.h:138
size_t findRow(uint32 id) const
Find a row by its ID value.
Definition: gdafile.cpp:95
ColumnNameMap _columnNameMap
Definition: gdafile.h:158
void load(Common::SeekableReadStream *gda)
Definition: gdafile.cpp:274
std::vector< const GFF4Struct * > GFF4List
Definition: types.h:453
GFF4s _gff4s
Definition: gdafile.h:146
void add(Common::SeekableReadStream *gda)
Add another GDA with the same column structure to the bottom of this GDA.
Definition: gdafile.cpp:306
const GFF4Struct * getRowColumn(size_t row, uint32 hash, size_t &column) const
Definition: gdafile.cpp:149
static const size_t kInvalidColumn
Definition: gdafile.h:64
Headers _headers
Definition: gdafile.h:148
A vector storing pointer to objects, with automatic deletion.
const GFF4List * Columns
Definition: gdafile.h:137
std::map< uint32, size_t > ColumnHashMap
Definition: gdafile.h:142
std::map< Common::UString, size_t > ColumnNameMap
Definition: gdafile.h:143
size_t getRowCount() const
Return the number of rows in the array.
Definition: gdafile.cpp:61
size_t getColumnCount() const
Return the number of columns in the array.
Definition: gdafile.cpp:57
Unicode string handling.
GDAFile(Common::SeekableReadStream *gda)
Take over this stream and read a GDA file out of it.
Definition: gdafile.cpp:48
const GFF4Struct * getRow(size_t row) const
Get a row as a GFF4 struct.
Definition: gdafile.cpp:73
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
size_t findColumn(const Common::UString &name) const
Find a column by its name.
Definition: gdafile.cpp:118
Common::UString getString(size_t row, uint32 columnHash, const Common::UString &def="") const
Definition: gdafile.cpp:165
ColumnHashMap _columnHashMap
Definition: gdafile.h:157
size_t _rowCount
Definition: gdafile.h:153
uint32_t uint32
Definition: types.h:204
Columns _columns
Definition: gdafile.h:150
static const size_t kInvalidRow
Definition: gdafile.h:65
bool hasRow(size_t row) const
Does this row exist in the GDA?
Definition: gdafile.cpp:69
#define SIZE_MAX
Definition: types.h:172
std::vector< Header > Headers
Definition: gdafile.h:84
const Headers & getHeaders() const
Get the column headers.
Definition: gdafile.cpp:65
Type identifyType(const Columns &columns, const Row &rows, size_t column) const
Definition: gdafile.cpp:220
Interface for a seekable & readable data stream.
Definition: readstream.h:265
Class to hold the GFF&#39;d two-dimensional array of a GDA file.
Definition: gdafile.h:62
int32_t int32
Definition: types.h:203