#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string>
#include <vector>
#include <iostream>
class Node;
class CustomObject;
class CustomObject
{
public:
std::string name;
Node* parent;
CustomObject(std::string n_name);
std::string getName();
void setParent(Node* pparent);
Node* getParent();
};
CustomObject::CustomObject(std::string n_name)
{
name = n_name;
}
std::string CustomObject::getName()
{
return name;
}
void CustomObject::setParent(Node* pparent)
{
parent = pparent;
}
Node* CustomObject::getParent()
{
return parent;
}
class Node
{
public:
std::string name;
Node* parent;
std::vector<Node> childs;
Node(std::string n_name);
void attach(Node* nd);
void attach(CustomObject* anm);
std::string getName();
void setParent(Node* pparent);
Node* getParent();
std::vector<CustomObject> mCustomObjects;
};
Node::Node(std::string n_name)
{
name = n_name;
}
std::string Node::getName()
{
return name;
}
void Node::setParent(Node* pparent)
{
parent = pparent;
}
Node* Node::getParent()
{
return parent;
}
void Node::attach(Node* nd)
{
childs.push_back(*nd);
nd->setParent(this);
}
void Node::attach(CustomObject* anm)
{
mCustomObjects.push_back(*anm);
anm->setParent(this);
}
class Game
{
std::string name;
public:
std::vector<Node> nodes;
std::vector<CustomObject> mCustomObjects;
Game(std::string nm);
};
Game::Game(std::string nm)
{
name = nm;
}
void show_message(CustomObject* anm)
{
std::cout << anm->getName().c_str() << "\n";
std::cout << anm->getParent()->getName().c_str() << "\n";
}
int main()
{
Game* mGame = new Game("MyGame");
Node* mNode = new Node("MyNode");
mGame->nodes.push_back(*mNode);
CustomObject* mCustomObject = new CustomObject("Object1");
mGame->mCustomObjects.push_back(*mCustomObject);
mNode->attach(mCustomObject);
show_message(mCustomObject);
for (std::vector<CustomObject>::iterator itr = mGame->mCustomObjects.begin(); itr != mGame->mCustomObjects.end(); ++itr)
{
CustomObject* cObj;
cObj = &(*itr);
show_message(cObj);
}
}