X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FConsole%2FScopedDirectory.hh;h=ea0926c55d68335786e551d05da44155cd3aba96;hb=0003d55730b447329342161d12cf2ed23b63459e;hp=1712f9f325f3251746cb41373f06c200b43334b4;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Utils/Console/ScopedDirectory.hh b/senf/Utils/Console/ScopedDirectory.hh index 1712f9f..ea0926c 100644 --- a/senf/Utils/Console/ScopedDirectory.hh +++ b/senf/Utils/Console/ScopedDirectory.hh @@ -1,24 +1,29 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief ScopedDirectory public header */ @@ -33,37 +38,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 +53,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 +64,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 +99,9 @@ namespace console { public: ScopedDirectory configDir; - MyClass() : configDir(this) + MyClass() : configDir(this) { - configDIr.add(...); + configDir.add(...); } }; \endcode @@ -136,35 +123,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 +162,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"