From b02da898c7c8a08141df4e797774a61cf5e0163f Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 10 Sep 2012 22:32:10 +0200 Subject: [PATCH] added constructors for described types --- src/battle/Hero.cpp | 5 +++++ src/battle/Hero.h | 1 + src/battle/Monster.cpp | 5 +++++ src/battle/Monster.h | 1 + src/battle/PartyLayout.cpp | 5 +++++ src/battle/PartyLayout.h | 1 + src/battle/Resources.cpp | 5 +++++ src/battle/Resources.h | 1 + src/battle/Stats.cpp | 5 +++++ src/battle/Stats.h | 1 + src/common/Ikari.cpp | 5 +++++ src/common/Ikari.h | 1 + src/common/Item.cpp | 5 +++++ src/common/Item.h | 1 + src/common/Spell.cpp | 5 +++++ src/common/Spell.h | 1 + src/common/TargetingMode.cpp | 5 +++++ src/common/TargetingMode.h | 1 + src/graphics/ComplexAnimation.cpp | 9 ++++++--- src/graphics/ComplexAnimation.h | 1 + src/graphics/Font.cpp | 5 +++++ src/graphics/Font.h | 1 + src/graphics/Frame.cpp | 5 +++++ src/graphics/Frame.h | 1 + src/graphics/Gauge.cpp | 5 +++++ src/graphics/Gauge.h | 1 + src/graphics/Menu.cpp | 5 +++++ src/graphics/Menu.h | 2 ++ src/graphics/SimpleAnimation.cpp | 5 +++++ src/graphics/SimpleAnimation.h | 1 + src/graphics/Sprite.cpp | 5 +++++ src/graphics/Sprite.h | 1 + src/loader/Interpreter.cpp | 4 ++++ src/loader/TypeDescription.cpp | 9 +++++++++ src/loader/TypeDescription.h | 5 ++++- 35 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/battle/Hero.cpp b/src/battle/Hero.cpp index fdf8125..8138bc1 100644 --- a/src/battle/Hero.cpp +++ b/src/battle/Hero.cpp @@ -164,6 +164,7 @@ void Hero::CreateTypeDescription() { 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)); @@ -182,4 +183,8 @@ void Hero::CreateTypeDescription() { td.AddField("meleeAnimation", FieldDescription(((char *)&h.meleeAnimation) - ((char *)&h), animationId, true)); } +void Hero::Construct(void *data) { + new (data) Hero; +} + } diff --git a/src/battle/Hero.h b/src/battle/Hero.h index 122ee94..c15c2dc 100644 --- a/src/battle/Hero.h +++ b/src/battle/Hero.h @@ -131,6 +131,7 @@ public: void SetSpellAnimation(const graphics::Animation *a) { spellAnimation = a; } static void CreateTypeDescription(); + static void Construct(void *); private: const char *name; diff --git a/src/battle/Monster.cpp b/src/battle/Monster.cpp index dd65338..7cb4185 100644 --- a/src/battle/Monster.cpp +++ b/src/battle/Monster.cpp @@ -62,6 +62,7 @@ void Monster::CreateTypeDescription() { 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)); @@ -79,4 +80,8 @@ void Monster::CreateTypeDescription() { td.AddField("meleeAnimation", FieldDescription(((char *)&m.meleeAnimation) - ((char *)&m), animationId, true)); } +void Monster::Construct(void *data) { + new (data) Monster; +} + } diff --git a/src/battle/Monster.h b/src/battle/Monster.h index c5c75ca..db37dfe 100644 --- a/src/battle/Monster.h +++ b/src/battle/Monster.h @@ -85,6 +85,7 @@ public: const AttackChoice &GetAttackChoice() const { return attackChoice; } static void CreateTypeDescription(); + static void Construct(void *); private: const char *name; diff --git a/src/battle/PartyLayout.cpp b/src/battle/PartyLayout.cpp index 78d2999..c2bb452 100644 --- a/src/battle/PartyLayout.cpp +++ b/src/battle/PartyLayout.cpp @@ -42,9 +42,14 @@ void PartyLayout::CreateTypeDescription() { 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; +} + } diff --git a/src/battle/PartyLayout.h b/src/battle/PartyLayout.h index b2454f2..e4f7d1b 100644 --- a/src/battle/PartyLayout.h +++ b/src/battle/PartyLayout.h @@ -33,6 +33,7 @@ public: } static void CreateTypeDescription(); + static void Construct(void *); private: const geometry::Vector *positions; diff --git a/src/battle/Resources.cpp b/src/battle/Resources.cpp index 340f57c..6c46946 100644 --- a/src/battle/Resources.cpp +++ b/src/battle/Resources.cpp @@ -95,6 +95,7 @@ void Resources::CreateTypeDescription() { 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)); @@ -165,4 +166,8 @@ void Resources::CreateTypeDescription() { td.AddField("heroesBgColor", FieldDescription(((char *)&r.heroesBgColor) - ((char *)&r), colorId, false)); } +void Resources::Construct(void *data) { + new (data) Resources; +} + } diff --git a/src/battle/Resources.h b/src/battle/Resources.h index 7286e0d..9654fdc 100644 --- a/src/battle/Resources.h +++ b/src/battle/Resources.h @@ -102,6 +102,7 @@ struct Resources { Resources(); static void CreateTypeDescription(); + static void Construct(void *); }; diff --git a/src/battle/Stats.cpp b/src/battle/Stats.cpp index cdf3210..a2a442c 100644 --- a/src/battle/Stats.cpp +++ b/src/battle/Stats.cpp @@ -43,6 +43,7 @@ void Stats::CreateTypeDescription() { 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)); @@ -54,4 +55,8 @@ void Stats::CreateTypeDescription() { td.AddField("mgr", FieldDescription(((char *)&s.magicResistance) - ((char *)&s), numberId, false)); } +void Stats::Construct(void *data) { + new (data) Stats; +} + } diff --git a/src/battle/Stats.h b/src/battle/Stats.h index 5f0d17d..e53111d 100644 --- a/src/battle/Stats.h +++ b/src/battle/Stats.h @@ -36,6 +36,7 @@ public: void SetMagicResistance(Uint16 m) { magicResistance = m; } static void CreateTypeDescription(); + static void Construct(void *); private: int attack; diff --git a/src/common/Ikari.cpp b/src/common/Ikari.cpp index e91f12f..604ca5b 100644 --- a/src/common/Ikari.cpp +++ b/src/common/Ikari.cpp @@ -31,6 +31,7 @@ void Ikari::CreateTypeDescription() { 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)); @@ -39,4 +40,8 @@ void Ikari::CreateTypeDescription() { td.AddField("type", FieldDescription(((char *)&i.isPhysical) - ((char *)&i), boolId, true)); } +void Ikari::Construct(void *data) { + new (data) Ikari; +} + } diff --git a/src/common/Ikari.h b/src/common/Ikari.h index 76730de..979015b 100644 --- a/src/common/Ikari.h +++ b/src/common/Ikari.h @@ -36,6 +36,7 @@ public: void SetPhysical() { isPhysical = true; } static void CreateTypeDescription(); + static void Construct(void *); private: const char *name; diff --git a/src/common/Item.cpp b/src/common/Item.cpp index 9d04836..9a1a735 100644 --- a/src/common/Item.cpp +++ b/src/common/Item.cpp @@ -48,6 +48,7 @@ void Item::CreateTypeDescription() { 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)); @@ -66,4 +67,8 @@ void Item::CreateTypeDescription() { td.AddField("attackanimation", FieldDescription(((char *)&i.attackAnimation) - ((char *)&i), animationId, true)); } +void Item::Construct(void *data) { + new (data) Item; +} + } diff --git a/src/common/Item.h b/src/common/Item.h index ffa50e3..1af15f3 100644 --- a/src/common/Item.h +++ b/src/common/Item.h @@ -89,6 +89,7 @@ public: void SetAttackAnimation(graphics::Animation *a) { attackAnimation = a; } static void CreateTypeDescription(); + static void Construct(void *); private: enum Equipable { diff --git a/src/common/Spell.cpp b/src/common/Spell.cpp index a0b3b9d..8f8784a 100644 --- a/src/common/Spell.cpp +++ b/src/common/Spell.cpp @@ -29,6 +29,7 @@ void Spell::CreateTypeDescription() { 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)); @@ -36,4 +37,8 @@ void Spell::CreateTypeDescription() { td.AddField("targets", FieldDescription(((char *)&s.targetingMode) - ((char *)&s), targetsId, false)); } +void Spell::Construct(void *data) { + new (data) Spell; +} + } diff --git a/src/common/Spell.h b/src/common/Spell.h index 9bf0a4b..eb8fa02 100644 --- a/src/common/Spell.h +++ b/src/common/Spell.h @@ -39,6 +39,7 @@ public: void SetUsableInBattle() { usability |= USABILITY_BATTLE; } static void CreateTypeDescription(); + static void Construct(void *); private: enum Usability { diff --git a/src/common/TargetingMode.cpp b/src/common/TargetingMode.cpp index 82b2853..4763588 100644 --- a/src/common/TargetingMode.cpp +++ b/src/common/TargetingMode.cpp @@ -21,10 +21,15 @@ void TargetingMode::CreateTypeDescription() { 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; +} + } diff --git a/src/common/TargetingMode.h b/src/common/TargetingMode.h index 83d1d83..ef29698 100644 --- a/src/common/TargetingMode.h +++ b/src/common/TargetingMode.h @@ -31,6 +31,7 @@ public: void TargetEnemy() { ally = false; } static void CreateTypeDescription(); + static void Construct(void *); private: enum { diff --git a/src/graphics/ComplexAnimation.cpp b/src/graphics/ComplexAnimation.cpp index ab19fd0..cb125f5 100644 --- a/src/graphics/ComplexAnimation.cpp +++ b/src/graphics/ComplexAnimation.cpp @@ -23,8 +23,10 @@ void ComplexAnimation::CreateTypeDescription() { 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)); @@ -34,9 +36,6 @@ void ComplexAnimation::CreateTypeDescription() { FrameProp fp; - int numberId(TypeDescription::GetTypeId("Number")); - int vectorId(TypeDescription::GetTypeId("Vector")); - TypeDescription &ftd(TypeDescription::CreateOrGet("ComplexAnimationFrame")); ftd.SetSize(sizeof(FrameProp)); @@ -45,4 +44,8 @@ void ComplexAnimation::CreateTypeDescription() { ftd.AddField("disposition", FieldDescription(((char *)&fp.disposition) - ((char *)&fp), vectorId, false)); } +void ComplexAnimation::Construct(void *data) { + new (data) ComplexAnimation; +} + } diff --git a/src/graphics/ComplexAnimation.h b/src/graphics/ComplexAnimation.h index a548cdb..e35895d 100644 --- a/src/graphics/ComplexAnimation.h +++ b/src/graphics/ComplexAnimation.h @@ -32,6 +32,7 @@ public: 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; }; diff --git a/src/graphics/Font.cpp b/src/graphics/Font.cpp index d151f25..e4e538d 100644 --- a/src/graphics/Font.cpp +++ b/src/graphics/Font.cpp @@ -82,6 +82,7 @@ void Font::CreateTypeDescription() { 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)); @@ -89,4 +90,8 @@ void Font::CreateTypeDescription() { td.AddField("rowoffset", FieldDescription(((char *)&f.rowOffset) - ((char *)&f), numberId, false)); } +void Font::Construct(void *data) { + new (data) Font; +} + } diff --git a/src/graphics/Font.h b/src/graphics/Font.h index 8b36525..3fcc7d2 100644 --- a/src/graphics/Font.h +++ b/src/graphics/Font.h @@ -37,6 +37,7 @@ public: void SetRowOffset(int n) { rowOffset = n; } static void CreateTypeDescription(); + static void Construct(void *); private: const Sprite *sprite; diff --git a/src/graphics/Frame.cpp b/src/graphics/Frame.cpp index db771e5..683bfcb 100644 --- a/src/graphics/Frame.cpp +++ b/src/graphics/Frame.cpp @@ -126,6 +126,7 @@ void Frame::CreateTypeDescription() { 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)); @@ -134,4 +135,8 @@ void Frame::CreateTypeDescription() { td.AddField("offset", FieldDescription(((char *)&f.offset) - ((char *)&f), vectorId, false)); } +void Frame::Construct(void *data) { + new (data) Frame; +} + } diff --git a/src/graphics/Frame.h b/src/graphics/Frame.h index 75bd605..c6fb602 100644 --- a/src/graphics/Frame.h +++ b/src/graphics/Frame.h @@ -38,6 +38,7 @@ public: void SetOffset(const geometry::Vector &o) { offset = o; } static void CreateTypeDescription(); + static void Construct(void *); private: SDL_Surface *surface; diff --git a/src/graphics/Gauge.cpp b/src/graphics/Gauge.cpp index 6925c2f..b7023d4 100644 --- a/src/graphics/Gauge.cpp +++ b/src/graphics/Gauge.cpp @@ -91,6 +91,7 @@ void Gauge::CreateTypeDescription() { 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)); @@ -102,4 +103,8 @@ void Gauge::CreateTypeDescription() { td.AddField("end", FieldDescription(((char *)&g.endWidth) - ((char *)&g), numberId, false)); } +void Gauge::Construct(void *data) { + new (data) Gauge; +} + } diff --git a/src/graphics/Gauge.h b/src/graphics/Gauge.h index 82b8952..5938a02 100644 --- a/src/graphics/Gauge.h +++ b/src/graphics/Gauge.h @@ -35,6 +35,7 @@ public: void SetEndWidth(int w) { endWidth = w; } static void CreateTypeDescription(); + static void Construct(void *); private: SDL_Surface *surface; diff --git a/src/graphics/Menu.cpp b/src/graphics/Menu.cpp index ebb76ff..92fc898 100644 --- a/src/graphics/Menu.cpp +++ b/src/graphics/Menu.cpp @@ -23,6 +23,7 @@ void MenuProperties::CreateTypeDescription() { 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)); @@ -40,4 +41,8 @@ void MenuProperties::CreateTypeDescription() { td.AddField("additionalTextGap", FieldDescription(((char *)&p.additionalTextGap) - ((char *)&p), numberId, false)); } +void MenuProperties::Construct(void *data) { + new (data) MenuProperties; +} + } diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index 7aa2e94..e962738 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -45,6 +45,8 @@ struct 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 diff --git a/src/graphics/SimpleAnimation.cpp b/src/graphics/SimpleAnimation.cpp index f1c1a72..cdd3a8e 100644 --- a/src/graphics/SimpleAnimation.cpp +++ b/src/graphics/SimpleAnimation.cpp @@ -24,6 +24,7 @@ void SimpleAnimation::CreateTypeDescription() { int spriteId(TypeDescription::GetTypeId("Sprite")); TypeDescription &td(TypeDescription::CreateOrGet("SimpleAnimation")); + td.SetConstructor(&Construct); td.SetSize(sizeof(SimpleAnimation)); td.AddSupertype(animationId, ((char *)a) - ((char *)&sa)); @@ -33,4 +34,8 @@ void SimpleAnimation::CreateTypeDescription() { td.AddField("row", FieldDescription(((char *)&sa.row) - ((char *)&sa), numberId, false)); } +void SimpleAnimation::Construct(void *data) { + new (data) SimpleAnimation; +} + } diff --git a/src/graphics/SimpleAnimation.h b/src/graphics/SimpleAnimation.h index 81d6244..8374f08 100644 --- a/src/graphics/SimpleAnimation.h +++ b/src/graphics/SimpleAnimation.h @@ -27,6 +27,7 @@ public: void SetRow(int r) { row = r; } static void CreateTypeDescription(); + static void Construct(void *); protected: virtual int NumFrames() const { return numFrames; }; diff --git a/src/graphics/Sprite.cpp b/src/graphics/Sprite.cpp index 28d3b5c..434679c 100644 --- a/src/graphics/Sprite.cpp +++ b/src/graphics/Sprite.cpp @@ -48,6 +48,7 @@ void Sprite::CreateTypeDescription() { 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)); @@ -55,4 +56,8 @@ void Sprite::CreateTypeDescription() { td.AddField("offset", FieldDescription(((char *)&s.offset) - ((char *)&s), vectorId, false)); } +void Sprite::Construct(void *data) { + new (data) Sprite; +} + } diff --git a/src/graphics/Sprite.h b/src/graphics/Sprite.h index 257d2df..c22965a 100644 --- a/src/graphics/Sprite.h +++ b/src/graphics/Sprite.h @@ -44,6 +44,7 @@ public: void SetOffset(const geometry::Vector &o) { offset = o; } static void CreateTypeDescription(); + static void Construct(void *); private: SDL_Surface *surface; diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 42fb121..f9f57bf 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -175,6 +175,7 @@ void *Interpreter::GetObject(int typeId, const Value &v) { 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()); @@ -250,6 +251,7 @@ void *Interpreter::GetObject(int typeId, const Value &v) { 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; @@ -268,6 +270,7 @@ void Interpreter::ReadObject(const Definition &dfn) { 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))); @@ -290,6 +293,7 @@ void Interpreter::ReadObject(int typeId, int id, char *object, const PropertyLis char *iter(aggregate); vector list(i->second->GetLiteral().GetPropertyLists()); for (vector::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()) { diff --git a/src/loader/TypeDescription.cpp b/src/loader/TypeDescription.cpp index 07be7b2..ed88e8e 100644 --- a/src/loader/TypeDescription.cpp +++ b/src/loader/TypeDescription.cpp @@ -8,6 +8,7 @@ #include "TypeDescription.h" #include +#include #include using std::map; @@ -37,6 +38,14 @@ const FieldDescription &TypeDescription::GetField(const std::string &n) const { } } +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; diff --git a/src/loader/TypeDescription.h b/src/loader/TypeDescription.h index 0107039..8f2f46c 100644 --- a/src/loader/TypeDescription.h +++ b/src/loader/TypeDescription.h @@ -39,7 +39,9 @@ public: 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()); } @@ -57,9 +59,10 @@ public: 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 fields; std::map supertypes; -- 2.39.2