X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FTypeDescription.h;h=0f530d8a6ab1910f6dd43f9b9610f116817e0f94;hb=8fd08e32d902b1340dd686ba0d7990fb1be3b861;hp=01070394d8b54e0ccc9f9140a04202aad105a6c2;hpb=22be995eefbf6e27f76606226422aaf3fbaa5b80;p=l2e.git diff --git a/src/loader/TypeDescription.h b/src/loader/TypeDescription.h index 0107039..0f530d8 100644 --- a/src/loader/TypeDescription.h +++ b/src/loader/TypeDescription.h @@ -8,6 +8,7 @@ #ifndef LOADER_TYPEDESCRIPTION_H_ #define LOADER_TYPEDESCRIPTION_H_ +#include #include #include #include @@ -18,15 +19,21 @@ namespace loader { class FieldDescription { public: - FieldDescription(std::ptrdiff_t offset, int type, bool reference = true, bool aggregate = false) - : offset(offset), type(type), reference(reference), aggregate(aggregate) { } + FieldDescription(std::ptrdiff_t offset, int type) + : description(0), offset(offset), type(type), reference(false), aggregate(false) { } std::ptrdiff_t Offset() const { return offset; }; int TypeId() const { return type; } bool IsReferenced() const { return reference; } bool IsAggregate() const { return aggregate; } + const char *Description() const { return description; } + + FieldDescription &SetReferenced() { reference = true; return *this; } + FieldDescription &SetAggregate() { aggregate = true; return *this; } + FieldDescription &SetDescription(const char *d) { description = d; return *this; } private: + const char *description; std::ptrdiff_t offset; int type; bool reference; @@ -39,7 +46,11 @@ 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 Load(void *) const; + void SetConstructor(void (*ctor)(void *)) { constructor = ctor; } + void SetLoader(void (*ld)(void *)) { loader = ld; } void AddSupertype(int id, std::ptrdiff_t offset); bool IsSubtypeOf(int id) const; bool IsSubtypeOf(const TypeDescription &other) const { return IsSubtypeOf(other.TypeId()); } @@ -52,21 +63,34 @@ public: void SetSize(int s) { size = s; } int Size() const { return size; } - static TypeDescription &CreateOrGet(const std::string &name); + void SetDescription(const char *d) { description = d; } + const char *Description() const { return description; } + + typedef std::map::const_iterator FieldIterator; + FieldIterator FieldsBegin() const { return fields.begin(); } + FieldIterator FieldsEnd() const { return fields.end(); } + + static TypeDescription &Create(int id, const std::string &name); static int GetTypeId(const std::string &); static const TypeDescription &Get(int id); + static void WriteSourceWiki(std::ostream &); + private: - TypeDescription(int id, const std::string &name) : name(name), id(id), size(0) { } + TypeDescription(int id, const std::string &name) : constructor(0), loader(0), description(0), name(name), id(id), size(0) { } private: + void (*constructor)(void *); + void (*loader)(void *); + const char *description; std::string name; std::map fields; std::map supertypes; int id; int size; - static std::vector typeDescriptions; + static std::map typeDescriptions; + static std::map typeName2ID; };