xoreos  0.0.5
gff3writer.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_GFF3WRITER_H
26 #define AURORA_GFF3WRITER_H
27 
28 #include <list>
29 
30 #include <boost/noncopyable.hpp>
31 #include <boost/shared_ptr.hpp>
32 
33 #include "glm/glm.hpp"
34 
35 #include "src/aurora/gff3file.h"
36 #include "src/aurora/locstring.h"
37 
38 namespace Aurora {
39 
40 class GFF3WriterStruct;
42 
43 typedef boost::shared_ptr<GFF3WriterStruct> GFF3WriterStructPtr;
44 typedef boost::shared_ptr<GFF3WriterList> GFF3WriterListPtr;
45 
46 class GFF3Writer : boost::noncopyable {
47 public:
48  // TODO: Add a constructor consuming a GFF3File object.
49  GFF3Writer(uint32 id, uint32 version = MKTAG('V', '3', '.', '2'));
50 
53 
55  void write(Common::WriteStream &stream);
56 
57 private:
59  struct Field : boost::noncopyable {
62 
65 
68 
69  float floatValue;
70  double doubleValue;
71 
72  glm::vec4 vectorValue;
73 
75 
77 
80  };
81 
82  typedef boost::shared_ptr<Field> FieldPtr;
83 
86 
87  std::vector<GFF3WriterStructPtr> _structs;
88  std::vector<GFF3WriterListPtr> _lists;
89 
90  std::vector<Common::UString> _labels;
91  std::vector<FieldPtr> _fields;
92 
93  friend class GFF3WriterList;
94  friend class GFF3WriterStruct;
95 
97  uint32 addLabel(const Common::UString &label);
99  static uint32 getFieldDataSize(FieldPtr field);
100 
101  size_t createField(GFF3Struct::FieldType type, const Common::UString &label);
102 };
103 
105 class GFF3WriterList : boost::noncopyable {
106 public:
107  GFF3WriterList(GFF3Writer *parent);
108 
111 
112  size_t getSize() const;
113 
114 private:
115  friend class GFF3Writer;
116  friend class GFF3WriterStruct;
117 
119  std::vector<size_t> _strcts;
120 };
121 
126 class GFF3WriterStruct : boost::noncopyable {
127 public:
128  GFF3WriterStruct(GFF3Writer *parent, uint32 id = 0xFFFFFFFF);
129 
131  uint32 getID() const;
133  size_t getFieldCount() const;
134 
139 
141  void addByte(const Common::UString &label, byte value);
143  void addChar(const Common::UString &label, char value);
145  void addFloat(const Common::UString &label, float value);
147  void addDouble(const Common::UString &label, double value);
149  void addUint16(const Common::UString &label, uint16 value);
151  void addUint32(const Common::UString &label, uint32 value);
153  void addUint64(const Common::UString &label, uint64 value);
155  void addSint16(const Common::UString &label, int16 value);
157  void addSint32(const Common::UString &label, int32 value);
159  void addSint64(const Common::UString &label, int64 value);
161  void addExoString(const Common::UString &label, const Common::UString &value);
163  void addStrRef(const Common::UString &label, uint32 value);
165  void addResRef(const Common::UString &label, const Common::UString &value);
167  void addVoid(const Common::UString &label, const byte *data, uint32 size);
169  void addVector(const Common::UString &label, glm::vec3 value);
171  void addOrientation(const Common::UString &label, glm::vec4 value);
173  void addLocString(const Common::UString &label, const LocString &value);
174 
175 private:
177 
180  std::vector<size_t> _fieldIndices;
181 
182  friend class GFF3Writer;
183  friend class GFF3WriterList;
184 };
185 
186 } // End of namespace Aurora
187 
188 #endif // AURORA_GFF3WRITER_H
Handling version V3.2/V3.3 of BioWare&#39;s GFFs (generic file format).
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like &#39;DATA&#39;, to ensure portability.
Definition: endianness.h:140
void addOrientation(const Common::UString &label, glm::vec4 value)
Add a new Orientation.
Definition: gff3writer.cpp:445
A class holding an UTF-8 string.
Definition: ustring.h:48
An implementation for a field.
Definition: gff3writer.h:59
A localized string.
Definition: locstring.h:43
GFF3WriterStruct(GFF3Writer *parent, uint32 id=0xFFFFFFFF)
Definition: gff3writer.cpp:459
uint64_t uint64
Definition: types.h:206
boost::shared_ptr< Field > FieldPtr
Definition: gff3writer.h:82
GFF3WriterListPtr addList(const Common::UString &label)
Create a new list.
Definition: gff3writer.cpp:360
void addVoid(const Common::UString &label, const byte *data, uint32 size)
Add new void data.
Definition: gff3writer.cpp:434
size_t getSize() const
Definition: gff3writer.cpp:322
size_t createField(GFF3Struct::FieldType type, const Common::UString &label)
Definition: gff3writer.cpp:286
Common::ScopedArray< byte > voidData
Definition: gff3writer.h:78
boost::shared_ptr< GFF3WriterStruct > GFF3WriterStructPtr
Definition: gff3writer.h:41
Common::UString stringValue
Definition: gff3writer.h:74
void addFloat(const Common::UString &label, float value)
Add a new float.
Definition: gff3writer.cpp:390
GFF3WriterList(GFF3Writer *parent)
Definition: gff3writer.cpp:326
int16_t int16
Definition: types.h:201
void addChar(const Common::UString &label, char value)
Add a new char.
Definition: gff3writer.cpp:386
GFF3Struct::FieldType type
Definition: gff3writer.h:60
FieldType
The type of a GFF3 field.
Definition: gff3file.h:167
void addResRef(const Common::UString &label, const Common::UString &value)
Add a new Resource reference.
Definition: gff3writer.cpp:430
std::vector< Common::UString > _labels
Definition: gff3writer.h:90
void addStrRef(const Common::UString &label, uint32 value)
Add a new String reference.
Definition: gff3writer.cpp:426
void addLocString(const Common::UString &label, const LocString &value)
Add a new LocString.
Definition: gff3writer.cpp:449
GFF3WriterStructPtr addStruct(const Common::UString &label)
Create a new struct.
Definition: gff3writer.cpp:337
GFF3WriterStructPtr addStruct(const Common::UString &label)
Add a new struct to the list.
Definition: gff3writer.cpp:299
void addExoString(const Common::UString &label, const Common::UString &value)
Add a new ExoString.
Definition: gff3writer.cpp:422
uint16_t uint16
Definition: types.h:202
std::vector< size_t > _strcts
Definition: gff3writer.h:119
void addSint16(const Common::UString &label, int16 value)
Add a new sint16.
Definition: gff3writer.cpp:410
uint32 addLabel(const Common::UString &label)
Adds a label to the writer and returns the corresponding index.
Definition: gff3writer.cpp:252
void write(Common::WriteStream &stream)
Write the GFF3 to stream.
Definition: gff3writer.cpp:44
void addUint64(const Common::UString &label, uint64 value)
Add a new uint64.
Definition: gff3writer.cpp:406
void addVector(const Common::UString &label, glm::vec3 value)
Add a new Vector.
Definition: gff3writer.cpp:441
Handling BioWare&#39;s localized strings.
std::vector< GFF3WriterListPtr > _lists
Definition: gff3writer.h:88
Generic interface for a writable data stream.
Definition: writestream.h:64
A GFF3 struct containing GFF3 fields.
Definition: gff3writer.h:126
int64_t int64
Definition: types.h:205
void addByte(const Common::UString &label, byte value)
Add a new byte.
Definition: gff3writer.cpp:382
std::vector< GFF3WriterStructPtr > _structs
Definition: gff3writer.h:87
void addUint32(const Common::UString &label, uint32 value)
Add a new uint32.
Definition: gff3writer.cpp:402
uint32_t uint32
Definition: types.h:204
size_t getFieldCount() const
Get the count of fields.
Definition: gff3writer.cpp:333
std::vector< size_t > _fieldIndices
Definition: gff3writer.h:180
GFF3Writer * _parent
Definition: gff3writer.h:118
A GFF3 list containing GFF3 structs.
Definition: gff3writer.h:105
static uint32 getFieldDataSize(FieldPtr field)
Get the actual size of the field.
Definition: gff3writer.cpp:262
GFF3WriterStructPtr getTopLevel()
Get the top-level struct.
Definition: gff3writer.cpp:40
GFF3Writer::FieldPtr createField(GFF3Struct::FieldType type, const Common::UString &label)
Definition: gff3writer.cpp:453
GFF3Writer(uint32 id, uint32 version=MKTAG('V', '3', '.', '2'))
Definition: gff3writer.cpp:36
boost::shared_ptr< GFF3WriterList > GFF3WriterListPtr
Definition: gff3writer.h:44
std::vector< FieldPtr > _fields
Definition: gff3writer.h:91
void addUint16(const Common::UString &label, uint16 value)
Add a new uint16.
Definition: gff3writer.cpp:398
uint32 getID() const
Get ID of the struct.
Definition: gff3writer.cpp:329
void addSint64(const Common::UString &label, int64 value)
Add a new sint64.
Definition: gff3writer.cpp:418
void addDouble(const Common::UString &label, double value)
Add a new double.
Definition: gff3writer.cpp:394
uint8 byte
Definition: types.h:209
int32_t int32
Definition: types.h:203
void addSint32(const Common::UString &label, int32 value)
Add a new sint32.
Definition: gff3writer.cpp:414