Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ScopedDirectory.hh

Go to the documentation of this file.
00001 // $Id: ScopedDirectory.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Scheduler_Console_ScopedDirectory_
00027 #define HH_SENF_Scheduler_Console_ScopedDirectory_ 1
00028 
00029 // Custom includes
00030 #include <boost/utility.hpp>
00031 #include <boost/type_traits/is_convertible.hpp>
00032 #include "Node.hh"
00033 #include "LazyDirectory.hh" // For ScopedDirectory template default arg
00034 
00035 //#include "ScopedDirectory.mpp"
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 namespace senf {
00039 namespace console {
00040 
00041     namespace detail { struct OwnedNodeFactory {}; }
00042 
00045     class ScopedDirectoryBase
00046     {
00047     public:
00048         DirectoryNode & node() const;   
00049         operator DirectoryNode & () const; 
00050 
00051         //-////////////////////////////////////////////////////////////////////////
00053         //\{
00054 
00055         GenericNode::ptr remove(std::string const & name);
00056         bool hasChild(std::string const & name) const;
00057         DirectoryNode & getDirectory(std::string const & name) const;
00058         DirectoryNode & operator[](std::string const & name) const;
00059         CommandNode & getCommand(std::string const & name) const;
00060         CommandNode & operator()(std::string const & name) const;
00061         GenericNode & get(std::string const & name) const;
00062         DirectoryNode::ChildrenRange children() const;
00063         DirectoryNode & doc(std::string const & doc);
00064         std::string const & name() const;
00065         bool active() const;
00066         std::string path() const;
00067         std::string path(DirectoryNode const & root) const;
00068         boost::shared_ptr<DirectoryNode> parent() const;
00069         GenericNode::ptr unlink();
00070         void help(std::ostream & output) const;
00071         std::string shorthelp() const;
00072 
00073         //\}
00074 
00075     protected:
00076         ScopedDirectoryBase();
00077         ~ScopedDirectoryBase();
00078 
00079     private:
00080         DirectoryNode::ptr node_;
00081     };
00082 
00117     template <class Owner>
00118     class ScopedDirectory : public ScopedDirectoryBase
00119     {
00120     public:
00121         //-////////////////////////////////////////////////////////////////////////
00122         // Types
00123 
00124         typedef Owner owner;
00125 
00126         //-////////////////////////////////////////////////////////////////////////
00128         //\{
00129 
00130         explicit ScopedDirectory(Owner * owner);
00131 
00132         //\}
00133         //-////////////////////////////////////////////////////////////////////////
00134 
00135         template <class NodeType>
00136         NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
00137         template <class NodeType>
00138         NodeType & add(std::string const & name, NodeType & node,
00139                        typename boost::enable_if< boost::is_convertible<NodeType &, GenericNode &> >::type * = 0);
00140         template <class Factory>
00141         typename Factory::result_type add(std::string const & name, Factory const & factory,
00142                                           typename boost::enable_if< boost::is_convertible<Factory*, detail::OwnedNodeFactory*> >::type * = 0);
00143         template <class Factory>
00144         typename Factory::result_type add(std::string const & name, Factory const & factory,
00145                                           typename boost::enable_if< boost::is_convertible<Factory*, detail::NodeFactory*> >::type * = 0,
00146                                           typename boost::disable_if< boost::is_convertible<Factory*, detail::OwnedNodeFactory*> >::type * = 0);
00147 
00148     protected:
00149 
00150     private:
00151         Owner * owner_;
00152     };
00153 
00154 #ifndef DOXYGEN
00155 
00156     template <>
00157     class ScopedDirectory<void> : public ScopedDirectoryBase
00158     {
00159     public:
00160         template <class NodeType>
00161         NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
00162         template <class NodeType>
00163         NodeType & add(std::string const & name, NodeType & node,
00164                        typename boost::enable_if< boost::is_convertible<NodeType &, GenericNode &> >::type * = 0);
00165         template <class Factory>
00166         typename Factory::result_type add(std::string const & name, Factory const & factory,
00167                                           typename boost::enable_if< boost::is_convertible<Factory*, detail::NodeFactory*> >::type * = 0);
00168     };
00169 
00170 #endif
00171 
00172 }}
00173 
00174 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00175 #include "ScopedDirectory.cci"
00176 //#include "ScopedDirectory.ct"
00177 #include "ScopedDirectory.cti"
00178 #endif
00179 
00180 
00181 // Local Variables:
00182 // mode: c++
00183 // fill-column: 100
00184 // comment-column: 40
00185 // c-file-style: "senf"
00186 // indent-tabs-mode: nil
00187 // ispell-local-dictionary: "american"
00188 // compile-command: "scons -u test"
00189 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research