X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FNode.hh;h=c2c8be560738d1029a8865494e15209d0fbd1657;hb=5e9e6057a4e5c1241ff3f1b75b0f797eb570725d;hp=154bc9790dc4d15ca51a5dde95c81269e914c9bf;hpb=327ff174bdc67db20c64d92c9a171abfa5443333;p=senf.git diff --git a/Console/Node.hh b/Console/Node.hh index 154bc97..c2c8be5 100644 --- a/Console/Node.hh +++ b/Console/Node.hh @@ -28,9 +28,11 @@ // Custom includes #include -#include +#include +#include +#include #include -#include "../Utils/intrusive_refcount.hh" +#include #include "../Utils/Exception.hh" //#include "Node.mpp" @@ -45,59 +47,77 @@ namespace console { /** \brief */ class GenericNode - : public intrusive_refcount_t + : public boost::enable_shared_from_this { public: /////////////////////////////////////////////////////////////////////////// // Types - typedef boost::intrusive_ptr ptr; + typedef boost::shared_ptr ptr; + typedef boost::weak_ptr weak_ptr; /////////////////////////////////////////////////////////////////////////// + virtual ~GenericNode(); + std::string const & name() const; - DirectoryNode & parent() const; + boost::shared_ptr parent() const; bool managed() const; + std::string path() const; + protected: - explicit GenericNode(std::string const & name, bool managed = false); + explicit GenericNode(std::string const & name); void name(std::string const & name); static void name(GenericNode & node, std::string const & name); void parent(DirectoryNode * parent); private: - bool release(); - std::string name_; - bool managed_; DirectoryNode * parent_; friend class intrusive_refcount_base; + friend class DirectoryNode; }; /** \brief */ class DirectoryNode : public GenericNode { + typedef std::map ChildMap; + public: - typedef boost::intrusive_ptr ptr; + /////////////////////////////////////////////////////////////////////////// + // Types + + typedef boost::shared_ptr ptr; + typedef boost::weak_ptr weak_ptr; + + typedef boost::iterator_range ChildrenRange; + typedef ChildMap::const_iterator child_iterator; + + /////////////////////////////////////////////////////////////////////////// - void add(std::auto_ptr node, bool uniquify = true); - void add(GenericNode & node, bool uniquify = true); + GenericNode & add(std::auto_ptr node, bool uniquify = true); DirectoryNode & operator[](std::string const & name) const; CommandNode & operator()(std::string const & name) const; + DirectoryNode & mkdir(std::string const & name); + + ChildrenRange children() const; + protected: - explicit DirectoryNode(std::string const & name, bool managed = false); + explicit DirectoryNode(std::string const & name); private: void add(GenericNode::ptr node, bool uniquify); GenericNode & lookup(std::string const & name) const; - typedef std::map ChildMap; ChildMap children_; + + friend DirectoryNode & root(); }; struct DuplicateNodeNameException : public senf::Exception @@ -111,15 +131,23 @@ namespace console { class CommandNode : public GenericNode { public: - typedef boost::intrusive_ptr ptr; + /////////////////////////////////////////////////////////////////////////// + // Types + + typedef boost::shared_ptr ptr; + typedef boost::weak_ptr weak_ptr; + + /////////////////////////////////////////////////////////////////////////// protected: - explicit CommandNode(std::string const & name, bool managed = false); + explicit CommandNode(std::string const & name); private: }; + DirectoryNode & root(); + }} ///////////////////////////////hh.e////////////////////////////////////////