X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FTypeDescription.cpp;h=27906fab758b486c247edcc0d86be6b6d03f2591;hb=77915e0186f4fc0788054eb34651c726b80d981c;hp=c69efbe9b443170d6472d065c6ff717afa93bd42;hpb=22be995eefbf6e27f76606226422aaf3fbaa5b80;p=l2e.git diff --git a/src/loader/TypeDescription.cpp b/src/loader/TypeDescription.cpp index c69efbe..27906fa 100644 --- a/src/loader/TypeDescription.cpp +++ b/src/loader/TypeDescription.cpp @@ -7,9 +7,13 @@ #include "TypeDescription.h" +#include #include +#include +#include #include +using std::endl; using std::map; using std::string; using std::vector; @@ -37,6 +41,20 @@ 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::Load(void *data) const { + if (loader) { + (*loader)(data); + } +} + void TypeDescription::AddSupertype(int id, std::ptrdiff_t offset) { supertypes[id] = offset; @@ -51,10 +69,10 @@ std::ptrdiff_t TypeDescription::SupertypeOffset(int id) const { } -vector Interpreter::typeDescriptions; +vector TypeDescription::typeDescriptions; TypeDescription &TypeDescription::CreateOrGet(const std::string &name) { - for (vector::const_iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) { + for (vector::iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) { if (i->name == name) { return *i; } @@ -74,8 +92,56 @@ int TypeDescription::GetTypeId(const std::string &name) { } const TypeDescription &TypeDescription::Get(int id) { - assert(id >= 0 && id < typeDescriptions.size()); + assert(id >= 0 && id < int(typeDescriptions.size())); return typeDescriptions[id]; } + +void TypeDescription::WriteSourceWiki(std::ostream &out) { + vector types; + for (vector::const_iterator i(typeDescriptions.begin()), end(typeDescriptions.end()); i != end; ++i) { + if (i->name != "Animation") { + types.push_back(i->name); + } + } + std::sort(types.begin(), types.end()); + + out << "h2. Data types" << endl << endl; + + for (vector::const_iterator i(types.begin()), end(types.end()); i != end; ++i) { + out << "* [[LoaderSource#" << *i << "|" << *i << "]]" << endl; + } + out << endl << endl; + + for (vector::const_iterator i(types.begin()), end(types.end()); i != end; ++i) { + const TypeDescription &td(Get(GetTypeId(*i))); + out << "h3. " << td.TypeName() << endl << endl; + + if (td.Description()) { + out << td.Description() << endl << endl; + } + + if (td.FieldsBegin() == td.FieldsEnd()) { + out << "No properties." << endl << endl; + } else { + out << "| *Property* | *Type* | *Description* |" << endl; + for (FieldIterator field(td.FieldsBegin()); field != td.FieldsEnd(); ++field) { + const FieldDescription &fd(field->second); + out << "| " << field->first << " | "; + if (fd.IsAggregate()) { + out << "Array<" << Get(fd.TypeId()).TypeName() << ">"; + } else { + out << Get(fd.TypeId()).TypeName(); + } + out << " | "; + if (fd.Description()) { + out << fd.Description(); + } + out << " |" << endl; + } + out << endl; + } + } +} + }