// $Id$
//
-// Copyright (C) 2008
+// Copyright (C) 2008
// Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-// Stefan Bund <g0dil@berlios.de>
//
-// 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 <g0dil@berlios.de>
/** \file
\brief ScopedDirectory public header */
#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 <class Owner, class Object>
- struct OwnerNodeCreateTraits
- {
- typedef BOOST_TYPEOF_TPL( senf_console_add_node(
- * static_cast<DirectoryNode *>(0),
- * static_cast<Owner *>(0),
- * static_cast<std::string const *>(0),
- * static_cast<Object *>(0),
- * static_cast<int *>(0)) ) base_type;
- typedef typename senf::remove_cvref<base_type>::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
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;
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<DirectoryNode> parent() const;
+ GenericNode::ptr unlink();
+ void help(std::ostream & output) const;
+ std::string shorthelp() const;
- ///\}
+ //\}
protected:
ScopedDirectoryBase();
public:
ScopedDirectory<MyClass> configDir;
- MyClass() : configDir(this)
+ MyClass() : configDir(this)
{
- configDIr.add(...);
+ configDir.add(...);
}
};
\endcode
class ScopedDirectory : public ScopedDirectoryBase
{
public:
- ///////////////////////////////////////////////////////////////////////////
+ //-////////////////////////////////////////////////////////////////////////
// Types
-
+
typedef Owner owner;
- ///////////////////////////////////////////////////////////////////////////
+ //-////////////////////////////////////////////////////////////////////////
///\name Structors and default members
- ///@{
+ //\{
explicit ScopedDirectory(Owner * owner);
- ///@}
- ///////////////////////////////////////////////////////////////////////////
-
- template <class Object>
- typename OwnerNodeCreateTraits<Owner, Object>::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 <class Object>
- typename OwnerNodeCreateTraits<Owner, Object>::result_type add(std::string const & name,
- Object & ob);
- ///< Create new child node
- /**< \see add() */
+ //\}
+ //-////////////////////////////////////////////////////////////////////////
+
+ template <class NodeType>
+ NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
+ template <class NodeType>
+ NodeType & add(std::string const & name, NodeType & node,
+ typename boost::enable_if< boost::is_convertible<NodeType &, GenericNode &> >::type * = 0);
+ template <class Factory>
+ typename Factory::result_type add(std::string const & name, Factory const & factory,
+ typename boost::enable_if< boost::is_convertible<Factory*, detail::OwnedNodeFactory*> >::type * = 0);
+ template <class Factory>
+ typename Factory::result_type add(std::string const & name, Factory const & factory,
+ typename boost::enable_if< boost::is_convertible<Factory*, detail::NodeFactory*> >::type * = 0,
+ typename boost::disable_if< boost::is_convertible<Factory*, detail::OwnedNodeFactory*> >::type * = 0);
protected:
class ScopedDirectory<void> : public ScopedDirectoryBase
{
public:
- template <class Object>
- typename NodeCreateTraits<Object>::result_type add(std::string const & name,
- Object const & ob);
-
- template <class Object>
- typename NodeCreateTraits<Object>::result_type add(std::string const & name,
- Object & ob);
+ template <class NodeType>
+ NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
+ template <class NodeType>
+ NodeType & add(std::string const & name, NodeType & node,
+ typename boost::enable_if< boost::is_convertible<NodeType &, GenericNode &> >::type * = 0);
+ template <class Factory>
+ typename Factory::result_type add(std::string const & name, Factory const & factory,
+ typename boost::enable_if< boost::is_convertible<Factory*, detail::NodeFactory*> >::type * = 0);
};
- template <class Owner, class Function>
- SimpleCommandNode & senf_console_add_node(
- DirectoryNode & node, Owner & owner, std::string const & name,
- SimpleCommandNode::Function fn, int);
-
- template <class Owner>
- SimpleCommandNode & senf_console_add_node(
- DirectoryNode & node, Owner & owner, std::string const & name,
- void (Owner::*fn)(std::ostream &, ParseCommandInfo const &), int);
-
- template <class Owner>
- DirectoryNode & senf_console_add_node(DirectoryNode & node, Owner & owner,
- std::string const & name, DirectoryNode & dir, int);
-
- template <class Node>
- DirectoryNode & senf_console_add_node(
- DirectoryNode & dir, std::string const & name, Node const & node, int,
- typename boost::enable_if< boost::is_convertible<Node*, ScopedDirectoryBase*> >::type * = 0);
#endif
}}
-///////////////////////////////hh.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
#include "ScopedDirectory.cci"
//#include "ScopedDirectory.ct"
#include "ScopedDirectory.cti"