int stringId(TypeDescription::GetTypeId("String"));
TypeDescription &td(TypeDescription::CreateOrGet("Hero"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Hero));
td.AddField("name", FieldDescription(((char *)&h.name) - ((char *)&h), stringId, true));
td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true));
}
+void Hero::Construct(void *data) {
+ new (data) Hero;
+}
+
}
void SetSpellAnimation(const graphics::Animation *a) { spellAnimation = a; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
const char *name;
int stringId(TypeDescription::GetTypeId("String"));
TypeDescription &td(TypeDescription::CreateOrGet("Monster"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Monster));
td.AddField("name", FieldDescription(((char *)&m.name) - ((char *)&m), stringId, true));
td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), animationId, true));
}
+void Monster::Construct(void *data) {
+ new (data) Monster;
+}
+
}
const AttackChoice &GetAttackChoice() const { return attackChoice; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
const char *name;
int vectorId(TypeDescription::GetTypeId("Vector"));
TypeDescription &td(TypeDescription::CreateOrGet("PartyLayout"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(PartyLayout));
td.AddField("positions", FieldDescription(((char *)&p.positions) - ((char *)&p), vectorId, true, true));
}
+void PartyLayout::Construct(void *data) {
+ new (data) PartyLayout;
+}
+
}
}
static void CreateTypeDescription();
+ static void Construct(void *);
private:
const geometry::Vector<int> *positions;
int stringId(TypeDescription::GetTypeId("String"));
TypeDescription &td(TypeDescription::CreateOrGet("BattleResources"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Resources));
td.AddField("swapCursor", FieldDescription(((char *)&r.swapCursor) - ((char *)&r), spriteId, true));
td.AddField("heroesBgColor", FieldDescription(((char *)&r.heroesBgColor) - ((char *)&r), colorId, false));
}
+void Resources::Construct(void *data) {
+ new (data) Resources;
+}
+
}
Resources();
static void CreateTypeDescription();
+ static void Construct(void *);
};
int numberId(TypeDescription::GetTypeId("Number"));
TypeDescription &td(TypeDescription::CreateOrGet("Stats"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Stats));
td.AddField("atp", FieldDescription(((char *)&s.attack) - ((char *)&s), numberId, false));
td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), numberId, false));
}
+void Stats::Construct(void *data) {
+ new (data) Stats;
+}
+
}
void SetMagicResistance(Uint16 m) { magicResistance = m; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
int attack;
int targetsId(TypeDescription::GetTypeId("TargetingMode"));
TypeDescription &td(TypeDescription::CreateOrGet("Ikari"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Ikari));
td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), stringId, true));
td.AddField("type", FieldDescription(((char *)&i.isPhysical) - ((char *)&i), boolId, true));
}
+void Ikari::Construct(void *data) {
+ new (data) Ikari;
+}
+
}
void SetPhysical() { isPhysical = true; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
const char *name;
int targetsId(TypeDescription::GetTypeId("TargetingMode"));
TypeDescription &td(TypeDescription::CreateOrGet("Item"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Item));
td.AddField("name", FieldDescription(((char *)&i.name) - ((char *)&i), stringId, true));
td.AddField("attackanimation", FieldDescription(((char *)&i.attackAnimation) - ((char *)&i), animationId, true));
}
+void Item::Construct(void *data) {
+ new (data) Item;
+}
+
}
void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
enum Equipable {
int targetsId(TypeDescription::GetTypeId("TargetingMode"));
TypeDescription &td(TypeDescription::CreateOrGet("Spell"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Spell));
td.AddField("name", FieldDescription(((char *)&s.name) - ((char *)&s), stringId, true));
td.AddField("targets", FieldDescription(((char *)&s.targetingMode) - ((char *)&s), targetsId, false));
}
+void Spell::Construct(void *data) {
+ new (data) Spell;
+}
+
}
void SetUsableInBattle() { usability |= USABILITY_BATTLE; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
enum Usability {
int numberId(TypeDescription::GetTypeId("Number"));
TypeDescription &td(TypeDescription::CreateOrGet("TargetingMode"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(TargetingMode));
td.AddField("faction", FieldDescription(((char *)&t.ally) - ((char *)&t), boolId, true));
td.AddField("mode", FieldDescription(((char *)&t.mode) - ((char *)&t), numberId, true));
}
+void TargetingMode::Construct(void *data) {
+ new (data) TargetingMode;
+}
+
}
void TargetEnemy() { ally = false; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
enum {
int frameId(TypeDescription::GetTypeId("ComplexAnimationFrame"));
int numberId(TypeDescription::GetTypeId("Number"));
int spriteId(TypeDescription::GetTypeId("Sprite"));
+ int vectorId(TypeDescription::GetTypeId("Vector"));
TypeDescription &td(TypeDescription::CreateOrGet("ComplexAnimation"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(ComplexAnimation));
td.AddSupertype(animationId, ((char *)a) - ((char *)&ca));
FrameProp fp;
- int numberId(TypeDescription::GetTypeId("Number"));
- int vectorId(TypeDescription::GetTypeId("Vector"));
-
TypeDescription &ftd(TypeDescription::CreateOrGet("ComplexAnimationFrame"));
ftd.SetSize(sizeof(FrameProp));
ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), vectorId, false));
}
+void ComplexAnimation::Construct(void *data) {
+ new (data) ComplexAnimation;
+}
+
}
void SetFrames(const FrameProp *f, int num) { frames = f; numFrames = num; }
static void CreateTypeDescription();
+ static void Construct(void *);
protected:
virtual int NumFrames() const { return numFrames; };
int spriteId(TypeDescription::GetTypeId("Sprite"));
TypeDescription &td(TypeDescription::CreateOrGet("Font"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Font));
td.AddField("sprite", FieldDescription(((char *)&f.sprite) - ((char *)&f), spriteId, true));
td.AddField("rowoffset", FieldDescription(((char *)&f.rowOffset) - ((char *)&f), numberId, false));
}
+void Font::Construct(void *data) {
+ new (data) Font;
+}
+
}
void SetRowOffset(int n) { rowOffset = n; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
const Sprite *sprite;
int vectorId(TypeDescription::GetTypeId("Vector"));
TypeDescription &td(TypeDescription::CreateOrGet("Frame"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Frame));
td.AddField("image", FieldDescription(((char *)&f.surface) - ((char *)&f), imageId, true));
td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), vectorId, false));
}
+void Frame::Construct(void *data) {
+ new (data) Frame;
+}
+
}
void SetOffset(const geometry::Vector<int> &o) { offset = o; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
SDL_Surface *surface;
int vectorId(TypeDescription::GetTypeId("Vector"));
TypeDescription &td(TypeDescription::CreateOrGet("Gauge"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Gauge));
td.AddField("image", FieldDescription(((char *)&g.surface) - ((char *)&g), imageId, true));
td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), numberId, false));
}
+void Gauge::Construct(void *data) {
+ new (data) Gauge;
+}
+
}
void SetEndWidth(int w) { endWidth = w; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
SDL_Surface *surface;
int stringId(TypeDescription::GetTypeId("String"));
TypeDescription &td(TypeDescription::CreateOrGet("MenuProperties"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(MenuProperties));
td.AddField("font", FieldDescription(((char *)&p.font) - ((char *)&p), fontId, true));
td.AddField("additionalTextGap", FieldDescription(((char *)&p.additionalTextGap) - ((char *)&p), numberId, false));
}
+void MenuProperties::Construct(void *data) {
+ new (data) MenuProperties;
+}
+
}
: font(font), disabledFont(disabledFont), cursor(cursor), charsPerEntry(charsPerEntry), rows(rows), rowGap(rowGap), iconSpace(iconSpace), cols(cols), colGap(colGap), charsPerNumber(charsPerNumber), charsPerAdditionalText(charsPerAdditionalText), additionalTextGap(additionalTextGap), delimiter(delimiter) { }
static void CreateTypeDescription();
+ static void Construct(void *);
+
};
template<class T>
int spriteId(TypeDescription::GetTypeId("Sprite"));
TypeDescription &td(TypeDescription::CreateOrGet("SimpleAnimation"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(SimpleAnimation));
td.AddSupertype(animationId, ((char *)a) - ((char *)&sa));
td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), numberId, false));
}
+void SimpleAnimation::Construct(void *data) {
+ new (data) SimpleAnimation;
+}
+
}
void SetRow(int r) { row = r; }
static void CreateTypeDescription();
+ static void Construct(void *);
protected:
virtual int NumFrames() const { return numFrames; };
int vectorId(TypeDescription::GetTypeId("Vector"));
TypeDescription &td(TypeDescription::CreateOrGet("Sprite"));
+ td.SetConstructor(&Construct);
td.SetSize(sizeof(Sprite));
td.AddField("image", FieldDescription(((char *)&s.surface) - ((char *)&s), imageId, true));
td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), vectorId, false));
}
+void Sprite::Construct(void *data) {
+ new (data) Sprite;
+}
+
}
void SetOffset(const geometry::Vector<int> &o) { offset = o; }
static void CreateTypeDescription();
+ static void Construct(void *);
private:
SDL_Surface *surface;
int typeId(TypeDescription::GetTypeId(v.GetLiteral().GetTypeName()));
const TypeDescription &td(TypeDescription::Get(typeId));
char *object(new char[td.Size()]);
+ td.Construct(object);
int id(values[typeId].size());
values[typeId].push_back(object);
ReadObject(typeId, id, object, *v.GetLiteral().GetProperties());
const TypeDescription &td(TypeDescription::Get(typeId));
id = values[typeId].size();
char *object(new char[td.Size()]);
+ td.Construct(object);
ReadObject(typeId, id, object, *v.GetLiteral().GetProperties());
}
break;
const TypeDescription &td(TypeDescription::Get(typeId));
int id(values[typeId].size());
char *object(new char[td.Size()]);
+ td.Construct(object);
values[typeId].push_back(object);
ReadObject(typeId, id, object, *dfn.GetProperties());
parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, typeId, id)));
char *iter(aggregate);
vector<PropertyList *> list(i->second->GetLiteral().GetPropertyLists());
for (vector<PropertyList *>::const_iterator j(list.begin()), end(list.end()); j != end; ++j, iter += fieldType.Size()) {
+ fieldType.Construct(iter);
ReadObject(fieldType.TypeId(), -1, iter, **j);
}
if (fd.IsReferenced()) {
#include "TypeDescription.h"
#include <cassert>
+#include <cstring>
#include <stdexcept>
using std::map;
}
}
+void TypeDescription::Construct(void *data) const {
+ if (constructor) {
+ (*constructor)(data);
+ } else {
+ std::memset(data, 0, Size());
+ }
+}
+
void TypeDescription::AddSupertype(int id, std::ptrdiff_t offset) {
supertypes[id] = offset;
void AddField(const std::string &name, const FieldDescription &f);
bool HasField(const std::string &name) const;
const FieldDescription &GetField(const std::string &name) const;
+ void Construct(void *) const;
+ void SetConstructor(void (*ctor)(void *)) { constructor = ctor; }
void AddSupertype(int id, std::ptrdiff_t offset);
bool IsSubtypeOf(int id) const;
bool IsSubtypeOf(const TypeDescription &other) const { return IsSubtypeOf(other.TypeId()); }
static const TypeDescription &Get(int id);
private:
- TypeDescription(int id, const std::string &name) : name(name), id(id), size(0) { }
+ TypeDescription(int id, const std::string &name) : constructor(0), name(name), id(id), size(0) { }
private:
+ void (*constructor)(void *);
std::string name;
std::map<std::string, FieldDescription> fields;
std::map<int, std::ptrdiff_t> supertypes;