ScopedDirectory.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_Console_ScopedDirectory_
18 #define HH_SENF_Utils_Console_ScopedDirectory_ 1
19 
20 // Custom includes
21 #include <boost/utility/enable_if.hpp>
22 #include <boost/type_traits/is_convertible.hpp>
23 #include "Node.hh"
24 #include "LazyDirectory.hh" // For ScopedDirectory template default arg
25 
26 //#include "ScopedDirectory.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 namespace console {
31 
32  namespace detail { struct OwnedNodeFactory {}; }
33 
37  {
38  public:
39  DirectoryNode & node() const;
40  operator DirectoryNode & () const;
41 
42  //-////////////////////////////////////////////////////////////////////////
44  //\{
45 
46  GenericNode::ptr remove(std::string const & name);
47  bool hasChild(std::string const & name) const;
48  DirectoryNode & getDirectory(std::string const & name) const;
49  DirectoryNode & operator[](std::string const & name) const;
50  CommandNode & getCommand(std::string const & name) const;
51  CommandNode & operator()(std::string const & name) const;
52  GenericNode & get(std::string const & name) const;
53  DirectoryNode::ChildrenRange children() const;
54  DirectoryNode & doc(std::string const & doc);
55  std::string const & name() const;
56  bool active() const;
57  std::string path() const;
58  std::string path(DirectoryNode const & root) const;
59  boost::shared_ptr<DirectoryNode> parent() const;
60  GenericNode::ptr unlink();
61  void help(std::ostream & output) const;
62  std::string shorthelp() const;
63 
64  //\}
65 
66  protected:
69 
70  private:
71  DirectoryNode::ptr node_;
72  };
73 
108  template <class Owner>
109  class ScopedDirectory : public ScopedDirectoryBase
110  {
111  public:
112  //-////////////////////////////////////////////////////////////////////////
113  // Types
114 
115  typedef Owner owner;
116 
117  //-////////////////////////////////////////////////////////////////////////
119  //\{
120 
121  explicit ScopedDirectory(Owner * owner);
122 
123  //\}
124  //-////////////////////////////////////////////////////////////////////////
125 
126  template <class NodeType>
127  NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
128  template <class NodeType>
129  NodeType & add(std::string const & name, NodeType & node,
130  typename boost::enable_if< boost::is_convertible<NodeType &, GenericNode &> >::type * = 0);
131  template <class Factory>
132  typename Factory::result_type add(std::string const & name, Factory const & factory,
133  typename boost::enable_if< boost::is_convertible<Factory*, detail::OwnedNodeFactory*> >::type * = 0);
134  template <class Factory>
135  typename Factory::result_type add(std::string const & name, Factory const & factory,
136  typename boost::enable_if< boost::is_convertible<Factory*, detail::NodeFactory*> >::type * = 0,
137  typename boost::disable_if< boost::is_convertible<Factory*, detail::OwnedNodeFactory*> >::type * = 0);
138 
139  protected:
140 
141  private:
142  Owner * owner_;
143  };
144 
145 #ifndef DOXYGEN
146 
147  template <>
148  class ScopedDirectory<void> : public ScopedDirectoryBase
149  {
150  public:
151  template <class NodeType>
152  NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
153  template <class NodeType>
154  NodeType & add(std::string const & name, NodeType & node,
155  typename boost::enable_if< boost::is_convertible<NodeType &, GenericNode &> >::type * = 0);
156  template <class Factory>
157  typename Factory::result_type add(std::string const & name, Factory const & factory,
158  typename boost::enable_if< boost::is_convertible<Factory*, detail::NodeFactory*> >::type * = 0);
159  };
160 
161 #endif
162 
163 }}
164 
165 //-/////////////////////////////////////////////////////////////////////////////////////////////////
166 #include "ScopedDirectory.cci"
167 //#include "ScopedDirectory.ct"
168 #include "ScopedDirectory.cti"
169 #endif
170 
171 
172 // Local Variables:
173 // mode: c++
174 // fill-column: 100
175 // comment-column: 40
176 // c-file-style: "senf"
177 // indent-tabs-mode: nil
178 // ispell-local-dictionary: "american"
179 // compile-command: "scons -u test"
180 // End:
Internal: Marker base class for all ScopedDirectory proxies.
boost::shared_ptr< DirectoryNode > ptr
Definition: Node.hh:414
Config/console tree directory node.
Definition: Node.hh:406
Node public header.
boost::iterator_range< ChildMap::const_iterator > ChildrenRange
Definition: Node.hh:418
DirectoryNode member proxy.
LazyDirectory public header.
Definition: Config.hh:28
DirectoryNode & root()
Get console root node.
Definition: Node.cc:26
Config/console tree command node.
Definition: Node.hh:563
unspecified_keyword_type name
Argument name.
Config/console node tree base-class.
Definition: Node.hh:250
boost::shared_ptr< GenericNode > ptr
Definition: Node.hh:253