X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Console%2FNode.hh;h=d081ffd6476ce849a441ea64fd565d03879e4308;hb=16d94efc2159cba35fc44e5b26747ae0a2ab237b;hp=154bc9790dc4d15ca51a5dde95c81269e914c9bf;hpb=327ff174bdc67db20c64d92c9a171abfa5443333;p=senf.git diff --git a/Console/Node.hh b/Console/Node.hh index 154bc97..d081ffd 100644 --- a/Console/Node.hh +++ b/Console/Node.hh @@ -28,10 +28,13 @@ // Custom includes #include -#include +#include +#include +#include #include -#include "../Utils/intrusive_refcount.hh" +#include #include "../Utils/Exception.hh" +#include "Parse.hh" //#include "Node.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -45,59 +48,88 @@ 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::shared_ptr cptr; + 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; + + ptr thisptr(); + cptr thisptr() 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::shared_ptr cptr; + 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; + GenericNode & get(std::string const & name) const; + + DirectoryNode & mkdir(std::string const & name); + + ChildrenRange children() const; + + template + GenericNode & traverse(ForwardRange const & range); + + ptr thisptr(); + cptr thisptr() 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,20 +143,35 @@ namespace console { class CommandNode : public GenericNode { public: - typedef boost::intrusive_ptr ptr; + /////////////////////////////////////////////////////////////////////////// + // Types + + typedef boost::shared_ptr ptr; + typedef boost::shared_ptr cptr; + typedef boost::weak_ptr weak_ptr; + + /////////////////////////////////////////////////////////////////////////// + + virtual void operator()(std::ostream & output, + ParseCommandInfo::ArgumentsRange const & arguments) = 0; + + ptr thisptr(); + cptr thisptr() const; protected: - explicit CommandNode(std::string const & name, bool managed = false); + explicit CommandNode(std::string const & name); private: }; + DirectoryNode & root(); + }} ///////////////////////////////hh.e//////////////////////////////////////// #include "Node.cci" -//#include "Node.ct" +#include "Node.ct" //#include "Node.cti" #endif