1
0
forked from 0ad/0ad
0ad/source/tools/atlas/AtlasObject/AtlasObjectImpl.h
Ykkrosh d0146135c4 Initial Actor Editor code
This was SVN commit r2025.
2005-03-19 22:29:32 +00:00

59 lines
1.7 KiB
C++

#include "AtlasObject.h"
#include <string>
#include <map>
// AtNode is an immutable tree node, with a string and and multimap of children.
class AtNode
{
friend class AtSmartPtr<AtNode>;
friend class AtSmartPtr<const AtNode>;
public:
typedef AtSmartPtr<const AtNode> Ptr;
AtNode() : refcount(0) {}
explicit AtNode(const AtNode* n) { *this = *n; refcount = 0; }
explicit AtNode(const wchar_t* text) : refcount(0), value(text) {}
// Create a new AtNode (since AtNodes are immutable, so it's not possible
// to just change this one), with the relevant alterations to its content.
const AtNode::Ptr setValue(const wchar_t* value) const;
const AtNode::Ptr addChild(const char* key, const AtNode::Ptr &data) const;
const AtNode::Ptr setChild(const char* key, const AtNode::Ptr &data) const;
const AtIter getChild(const char* key) const;
// Check recursively for any 'value' data
bool hasContent() const;
//private: // (but not actually private, since I'm still too lazy to waste
// time with dozens of friends)
std::wstring value;
typedef std::multimap<const std::string, const AtNode::Ptr> child_maptype;
typedef std::pair<const std::string, const AtNode::Ptr> child_pairtype;
child_maptype children;
private:
mutable unsigned int refcount;
};
// Implementation of AtIter
class AtIterImpl
{
friend class AtSmartPtr<AtIterImpl>;
public:
AtIterImpl() : refcount(0) {}
AtIterImpl(AtNode::child_maptype::const_iterator it, AtNode::child_maptype::const_iterator up)
: refcount(0), iter(it), iter_upperbound(up) {}
AtNode::child_maptype::const_iterator iter, iter_upperbound;
private:
mutable unsigned int refcount;
};