X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FTypeDescription.h;h=fb1b07890a8fe57bff4b46d58e540d7734e583eb;hb=8c8061a4f8b88410d6d93c039afe6affc4b69cf2;hp=b7f4ba9e05bd08daaf7aa16b888b8cdbad5a3541;hpb=cddc8a96cce6117dac14248455ac70d332a4a9f8;p=l2e.git diff --git a/src/loader/TypeDescription.h b/src/loader/TypeDescription.h index b7f4ba9..fb1b078 100644 --- a/src/loader/TypeDescription.h +++ b/src/loader/TypeDescription.h @@ -1,13 +1,7 @@ -/* - * TypeDescription.h - * - * Created on: Sep 4, 2012 - * Author: holy - */ - #ifndef LOADER_TYPEDESCRIPTION_H_ #define LOADER_TYPEDESCRIPTION_H_ +#include #include #include #include @@ -18,15 +12,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; @@ -40,8 +40,11 @@ public: bool HasField(const std::string &name) const; const FieldDescription &GetField(const std::string &name) const; void Construct(void *) const; + void Load(void *) const; + bool NeedsLinking() const { return link; } 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()); } @@ -54,29 +57,40 @@ public: void SetSize(int s) { size = s; } int Size() const { return size; } + 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 &CreateOrGet(const std::string &name); + static TypeDescription &Create(int id, const std::string &name); static int GetTypeId(const std::string &); static const TypeDescription &Get(int id); + static int GetMaxSize(); + + static void WriteSourceWiki(std::ostream &); + private: - TypeDescription(int id, const std::string &name) : constructor(0), 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), link(false) { } private: void (*constructor)(void *); + void (*loader)(void *); + const char *description; std::string name; std::map fields; std::map supertypes; int id; int size; + bool link; - static std::vector typeDescriptions; + static std::map typeDescriptions; + static std::map typeName2ID; }; } -#endif /* LOADER_TYPEDESCRIPTION_H_ */ +#endif