Newer
Older
invertedlogic / InvertedLogic / iLFramework / toolkit / src / GL / Objects.cpp
@John Ryland John Ryland on 10 Nov 2019 3 KB rename
#include <map>
#include <string>
#include "GL/Objects.h"


BEGIN_NAMESPACE


enum EnumOfEnums;


struct EnumType
{
	EnumOfEnums m_enumType;
	int         m_enumValue;
};


enum ObjectPropertyType
{
	OPT_String,
	OPT_Int,
	OPT_Float,
	OPT_Bool,
	OPT_Enum,
};


class ObjectProperty
{
public:
	std::string          m_name;
	ObjectPropertyType   m_type;

	// Another variant type
	union {
	  std::string&  u_string;
	  int           u_int;
	  float         u_float;
	  bool          u_bool;
	  EnumType      u_enum;
	}                    m_value;
};

	
struct Object::Pimpl
{
	std::string                  m_name;
	std::vector<const Object*>   m_children;
	std::vector<ObjectProperty>  m_properties;
	bool                         m_expanded;
};


Object::Object(const char* name)
{
	m_data = new Object::Pimpl;
	m_data->m_expanded = false;
	m_data->m_name = name;
}


Object::Object()
{
	m_data = new Object::Pimpl;
	m_data->m_expanded = false;
}


Object::~Object()
{
	delete m_data;
}


const char* Object::type() const
{
	return "Object";
}


const char* Object::text() const
{
	return m_data->m_name.c_str();
}


bool Object::hasChildren() const
{
	return (m_data->m_children.size() > 0);
}


const std::vector<const Object*>& Object::children() const
{
	return m_data->m_children;
}


void Object::addChild(const Object* a_child)
{
	m_data->m_children.push_back(a_child);
}


Object* g_objectTree = 0;




#define DECLARE_TEST_ENUM \
			DECLARE_ENUM_BEGIN(TestEnum) \
			  DECLARE_ENUM_VALUE(blah1, 0) \
			  DECLARE_ENUM_VALUE(blah2, 5) \
			  DECLARE_ENUM_VALUE(blah3, 7) \
			DECLARE_ENUM_END(TestEnum)

#define ALL_ENUMS \
			DECLARE_TEST_ENUM

#define DECLARE_ENUM_BEGIN(type)		EE_##type,
#define DECLARE_ENUM_VALUE(name, val)
#define DECLARE_ENUM_END(type)

enum EnumOfEnums
{
	ALL_ENUMS
};

#undef  DECLARE_ENUM_BEGIN
#undef  DECLARE_ENUM_VALUE
#undef  DECLARE_ENUM_END
#define DECLARE_ENUM_BEGIN(type)		enum type {
#define DECLARE_ENUM_VALUE(name, val)		name = val,
#define DECLARE_ENUM_END(type)			};

ALL_ENUMS

#undef  DECLARE_ENUM_BEGIN
#undef  DECLARE_ENUM_VALUE
#undef  DECLARE_ENUM_END
#define DECLARE_ENUM_BEGIN(type)		enumValueNameMap.clear();
#define DECLARE_ENUM_VALUE(name, val)	enumValueNameMap[val] = #name;
#define DECLARE_ENUM_END(type)			g_enumValueNameMap[EE_##type] = enumValueNameMap;

std::map<int,std::map<int,std::string>>  g_enumValueNameMap;
class RegisterAllEnums {
public:
	RegisterAllEnums()
	{
		std::map<int,std::string> enumValueNameMap;
		ALL_ENUMS
	}
} g_runOnStartup;



// Register Types
//   Basic types
//   Generic types
//   Compound Types (structs)
// introspection
//
// void DeclareType(const char* typeName, const char* description, members, ui_editor etc);


class RegisterTestObjects {
public:
	RegisterTestObjects()
	{
		Object* testObj1 = new Object("TestObject1");
		Object* testObj2 = new Object("TestObject2");
		Object* testObj3 = new Object("TestObject3");
		Object* testObj4 = new Object("TestObject4");
		Object* testObj21 = new Object("TestObject21");
		Object* testObj22 = new Object("TestObject22");
		Object* testObj23 = new Object("TestObject23");
		Object* testObj41 = new Object("TestObject41");
		g_objectTree = new Object("Root Object");
		g_objectTree->addChild(testObj1);
		g_objectTree->addChild(testObj2);
		g_objectTree->addChild(testObj3);
		g_objectTree->addChild(testObj4);
		testObj2->addChild(testObj21);
		testObj2->addChild(testObj22);
		testObj22->addChild(testObj23);
		testObj4->addChild(testObj41);
	}
} g_runOnStartup2;


END_NAMESPACE