Add Boost.Typeof library to repository
[senf.git] / Console / Node.hh
index 154bc97..d081ffd 100644 (file)
 
 // Custom includes
 #include <map>
-#include <boost/intrusive_ptr.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/enable_shared_from_this.hpp>
 #include <boost/utility.hpp>
-#include "../Utils/intrusive_refcount.hh"
+#include <boost/range/iterator_range.hpp>
 #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<GenericNode>
+        : public boost::enable_shared_from_this<GenericNode>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
         // Types
 
-        typedef boost::intrusive_ptr<GenericNode> ptr;
+        typedef boost::shared_ptr<GenericNode> ptr;
+        typedef boost::shared_ptr<GenericNode const> cptr;
+        typedef boost::weak_ptr<GenericNode> weak_ptr;
 
         ///////////////////////////////////////////////////////////////////////////
 
+        virtual ~GenericNode();
+
         std::string const & name() const;
-        DirectoryNode & parent() const;
+        boost::shared_ptr<DirectoryNode> 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<std::string, GenericNode::ptr> ChildMap;
+
     public:
-        typedef boost::intrusive_ptr<DirectoryNode> ptr;
+        ///////////////////////////////////////////////////////////////////////////
+        // Types
+
+        typedef boost::shared_ptr<DirectoryNode> ptr;
+        typedef boost::shared_ptr<DirectoryNode const> cptr;
+        typedef boost::weak_ptr<DirectoryNode> weak_ptr;
+
+        typedef boost::iterator_range<ChildMap::const_iterator> ChildrenRange;
+        typedef ChildMap::const_iterator child_iterator;
 
-        void add(std::auto_ptr<GenericNode> node, bool uniquify = true);
-        void add(GenericNode & node, bool uniquify = true);
+        ///////////////////////////////////////////////////////////////////////////
+
+        GenericNode & add(std::auto_ptr<GenericNode> 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 <class ForwardRange>
+        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<std::string, GenericNode::ptr> 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<CommandNode> ptr;
+        ///////////////////////////////////////////////////////////////////////////
+        // Types
+
+        typedef boost::shared_ptr<CommandNode> ptr;
+        typedef boost::shared_ptr<CommandNode const> cptr;
+        typedef boost::weak_ptr<CommandNode> 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