#include "Common.h"
#include "Object.h"
#include "Widget.h"
//#include <assert.h>
//#include <stdio.h>
//#include <typeinfo>
BEGIN_NAMESPACE
Object::Object(Object* a_parent, const char* a_name)
: m_parent(a_parent)
{
m_name = a_name ? a_name : "Unnamed";
if (m_parent)
m_parent->addChild(this);
}
Object::~Object()
{
Object* obj = (m_children.size()) ? m_children.front() : 0;
while (obj)
{
delete obj;
obj = (m_children.size()) ? m_children.front() : 0;
}
if (m_parent)
m_parent->m_children.remove(this);
}
void Object::addChild(Object* a_object)
{
m_children.push_back(a_object);
childAdded(a_object);
}
void Object::childAdded(Object* a_object)
{
}
Map<String,ReflectionDataInterface*>& Object::getReflectionDataMap()
{
static Map<String,ReflectionDataInterface*> reflectionDataMap;
return reflectionDataMap;
}
void Object::dumpReflectionInformation()
{
for (auto t : objectTypes())
{
const ReflectionDataInterface* i = t.second;
if (i) {
printf("Type: %i Name: %s Size: %zu\n", i->getTypeId(), i->getType().c_str(), i->getSize());
for (auto p : i->getMembersMap())
{
Member& m = p.second;
printf("Prop: %s -> { %p, %s, %s, %s }\n",
p.first.c_str(), m.offset, m.typeName.c_str(), m.memberName.c_str(), m.description.c_str() );
}
} else {
printf("Invalid reflection factory\n");
}
}
printf("Inheritance hierarchy:\n");
for (auto t : Object::getInheritanceMap())
{
printf(" Type: %s Inherits: %s\n", t.first.c_str(), t.second.c_str());
}
}
END_NAMESPACE