00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Scheduler_Console_ScopedDirectory_
00027 #define HH_SENF_Scheduler_Console_ScopedDirectory_ 1
00028
00029
00030 #include <boost/utility.hpp>
00031 #include <boost/type_traits/is_convertible.hpp>
00032 #include "Node.hh"
00033 #include "LazyDirectory.hh"
00034
00035
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
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
00177 #include "ScopedDirectory.cti"
00178 #endif
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189