paysages3d/src/definition/DefinitionNode.h

76 lines
2.1 KiB
C
Raw Normal View History

#ifndef DEFINITIONNODE_H
#define DEFINITIONNODE_H
#include "definition_global.h"
namespace paysages {
namespace definition {
/**
* Base class for all nodes of the definition tree.
*/
class DEFINITIONSHARED_EXPORT DefinitionNode
{
public:
DefinitionNode(DefinitionNode* parent, const std::string &name, const std::string &type_name = "");
virtual ~DefinitionNode();
2013-11-15 23:27:40 +00:00
virtual void save(PackStream* stream) const;
virtual void load(PackStream* stream);
virtual void copy(DefinitionNode* destination) const;
2013-10-31 16:59:18 +00:00
virtual void validate();
inline const std::string &getName() const {return name;}
virtual void setName(const std::string &name);
2013-10-31 16:59:18 +00:00
inline const std::string &getTypeName() const {return type_name;}
virtual Scenery* getScenery();
inline const DefinitionNode* getParent() const {return parent;}
inline const DefinitionNode* getRoot() const {return root;}
2015-08-12 17:29:28 +00:00
inline int getChildrenCount() const {return children.size();}
2013-10-31 21:53:22 +00:00
/**
* Return a string representation of the tree (mainly for debugging purposes).
*/
virtual std::string toString(int indent = 0) const;
/**
* Apply a diff to the internal value of this node.
*
* All internal node modifications should be done using this method, to be reversible.
*
* If *backward* is true, the diff will be reversed, instead of applied.
*
* Return true if the diff could be applied.
*/
virtual bool applyDiff(const DefinitionDiff *diff, bool backward=false);
2013-10-30 14:39:56 +00:00
protected:
void addChild(DefinitionNode* child);
void removeChild(DefinitionNode* child);
virtual DefinitionNode *findChildByName(const std::string name);
/**
* Get the size in bytes this child will consume when serialized to a stream.
*
* Return -1 if it can't be known. In this case, the saving will be done in a temporary
* stream to know the exact size, which will not be very efficient.
*/
int getStreamSize() const;
2013-10-30 14:39:56 +00:00
private:
DefinitionNode* parent;
DefinitionNode* root;
std::string type_name;
std::string name;
std::vector<DefinitionNode*> children;
};
}
}
#endif // DEFINITIONNODE_H