-/*
- * TypeDescription.h
- *
- * Created on: Sep 4, 2012
- * Author: holy
- */
-
#ifndef LOADER_TYPEDESCRIPTION_H_
#define LOADER_TYPEDESCRIPTION_H_
+#include <iosfwd>
#include <map>
#include <memory>
#include <string>
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;
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()); }
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<std::string, FieldDescription>::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 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) { }
private:
void (*constructor)(void *);
+ void (*loader)(void *);
+ const char *description;
std::string name;
std::map<std::string, FieldDescription> fields;
std::map<int, std::ptrdiff_t> supertypes;
int id;
int size;
- static std::vector<TypeDescription> typeDescriptions;
+ static std::map<int, TypeDescription> typeDescriptions;
+ static std::map<std::string, int> typeName2ID;
};
}
-#endif /* LOADER_TYPEDESCRIPTION_H_ */
+#endif