X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FScopedDirectory.hh;h=c6038cfb54d408051f2f939d66c5e3e2d9bf0090;hb=4101c2b818ec67e7469ebb44f030eed2185c4ab0;hp=0613d10d5eae37933724a1b2758c1ffdbf2dea42;hpb=084d18afd1abb3c6b19de612dbdf4dbc40ffd795;p=senf.git diff --git a/senf/Utils/Console/ScopedDirectory.hh b/senf/Utils/Console/ScopedDirectory.hh index 0613d10..c6038cf 100644 --- a/senf/Utils/Console/ScopedDirectory.hh +++ b/senf/Utils/Console/ScopedDirectory.hh @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -33,37 +33,13 @@ #include "LazyDirectory.hh" // For ScopedDirectory template default arg //#include "ScopedDirectory.mpp" -///////////////////////////////hh.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { namespace console { - /** \brief Internal: Node creation helper traits (ScopedDirectory proxy) - - This class is used like NodeCreateTraits to customize the child node creation. This trait - class is used however by the ScopedDirectory proxy. - */ - template - struct OwnerNodeCreateTraits - { - typedef BOOST_TYPEOF_TPL( senf_console_add_node( - * static_cast(0), - * static_cast(0), - * static_cast(0), - * static_cast(0), - * static_cast(0)) ) base_type; - typedef typename senf::remove_cvref::type value_type; - - typedef typename value_type::node_type NodeType; - typedef typename value_type::return_type result_type; - - /// Internal - struct Creator { - static result_type create(DirectoryNode & node, Owner & owner, - std::string const & name, Object & ob); - }; - }; - + namespace detail { struct OwnedNodeFactory {}; } + /** \brief Internal: Marker base class for all ScopedDirectory proxies */ class ScopedDirectoryBase @@ -72,9 +48,9 @@ namespace console { DirectoryNode & node() const; ///< Access the proxied DirectoryNode operator DirectoryNode & () const; ///< Access the proxied DirectoryNode - /////////////////////////////////////////////////////////////////////////// + //-//////////////////////////////////////////////////////////////////////// ///\name Proxied members (see DirectoryNode) - ///\{ + //\{ GenericNode::ptr remove(std::string const & name); bool hasChild(std::string const & name) const; @@ -83,12 +59,18 @@ namespace console { CommandNode & getCommand(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); - void link(std::string const & name, GenericNode & node); DirectoryNode::ChildrenRange children() const; DirectoryNode & doc(std::string const & doc); + std::string const & name() const; + bool active() const; + std::string path() const; + std::string path(DirectoryNode const & root) const; + boost::shared_ptr parent() const; + GenericNode::ptr unlink(); + void help(std::ostream & output) const; + std::string shorthelp() const; - ///\} + //\} protected: ScopedDirectoryBase(); @@ -112,9 +94,9 @@ namespace console { public: ScopedDirectory configDir; - MyClass() : configDir(this) + MyClass() : configDir(this) { - configDIr.add(...); + configDir.add(...); } }; \endcode @@ -136,35 +118,32 @@ namespace console { class ScopedDirectory : public ScopedDirectoryBase { public: - /////////////////////////////////////////////////////////////////////////// + //-//////////////////////////////////////////////////////////////////////// // Types - + typedef Owner owner; - /////////////////////////////////////////////////////////////////////////// + //-//////////////////////////////////////////////////////////////////////// ///\name Structors and default members - ///@{ + //\{ explicit ScopedDirectory(Owner * owner); - ///@} - /////////////////////////////////////////////////////////////////////////// - - template - typename OwnerNodeCreateTraits::result_type add( - std::string const & name, Object const & ob); - ///< Create new child node - /**< Adds a new child node to the (proxied) - DirectoryNode. How the node is added is configured - using the OwnerNodeCreateTraits template. The default - implementation just forwards the call to the proxied - directory node. */ - - template - typename OwnerNodeCreateTraits::result_type add( - std::string const & name, Object & ob); - ///< Create new child node - /**< \see add() */ + //\} + //-//////////////////////////////////////////////////////////////////////// + + template + NodeType & add(std::string const & name, boost::shared_ptr node); + template + NodeType & add(std::string const & name, NodeType & node, + typename boost::enable_if< boost::is_convertible >::type * = 0); + template + typename Factory::result_type add(std::string const & name, Factory const & factory, + typename boost::enable_if< boost::is_convertible >::type * = 0); + template + typename Factory::result_type add(std::string const & name, Factory const & factory, + typename boost::enable_if< boost::is_convertible >::type * = 0, + typename boost::disable_if< boost::is_convertible >::type * = 0); protected: @@ -178,38 +157,21 @@ namespace console { class ScopedDirectory : public ScopedDirectoryBase { public: - template - typename NodeCreateTraits::result_type add(std::string const & name, - Object const & ob); - - template - typename NodeCreateTraits::result_type add(std::string const & name, - Object & ob); + template + NodeType & add(std::string const & name, boost::shared_ptr node); + template + NodeType & add(std::string const & name, NodeType & node, + typename boost::enable_if< boost::is_convertible >::type * = 0); + template + typename Factory::result_type add(std::string const & name, Factory const & factory, + typename boost::enable_if< boost::is_convertible >::type * = 0); }; - template - SimpleCommandNode & senf_console_add_node( - DirectoryNode & node, Owner & owner, std::string const & name, - SimpleCommandNode::Function fn, int); - - template - SimpleCommandNode & senf_console_add_node( - DirectoryNode & node, Owner & owner, std::string const & name, - void (Owner::*fn)(std::ostream &, ParseCommandInfo const &), int); - - template - DirectoryNode & senf_console_add_node(DirectoryNode & node, Owner & owner, - std::string const & name, DirectoryNode & dir, int); - - template - DirectoryNode & senf_console_add_node( - DirectoryNode & dir, std::string const & name, Node const & node, int, - typename boost::enable_if< boost::is_convertible >::type * = 0); #endif }} -///////////////////////////////hh.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #include "ScopedDirectory.cci" //#include "ScopedDirectory.ct" #include "ScopedDirectory.cti"