Utils/Console: Implement command node return value support
[senf.git] / Utils / Console / Node.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Node public header */
25
26 /** \defgroup node_tree The node tree
27
28     The console/config node tree is the central data-structure of the library. Into this tree, all
29     commands and parameters are entered. The tree is then exposed using a file-system like
30     interface.
31
32     \autotoc
33
34     \section console_tree The tree
35
36     We will start by giving a more complete example. This example contains most of the stuff needed
37     for using the console/config library.
38
39     \code
40     // Define callback function.
41     void mycommand(std::ostream & os, senf::console::ParseCommandInfo const & command)
42     {
43         // ...
44         os << "!! Important message ...\n";
45     }
46
47     class SomeClass
48     {
49     public:
50         // Declare a directory node (proxy) for use by this class. This must be public so we can add
51         // it to the node tree later.
52         senf::console::ScopedDirectory<SomeClass> dir;
53
54         SomeClass() : dir(this)
55         {
56             // You may document the directory here or later when adding it to the tree
57             dir.doc("Manager for something");
58
59             // Add a member function (the pointer-to-member is automatically bound to this instance)
60             dir.add("member", &SomeClass::member)
61                 .doc("Do the member operation");
62         }
63
64         void member(std::ostream & os, senf::console::ParseCommandInfo const & command)
65         {
66             // ...
67         }
68     };
69
70     int main(int, char**)
71     {
72         // Provide global documentation
73         senf::console::root()
74             .doc("This is someServer server");
75
76         // Add a new directory to the root and document it. All the mutators return the node object
77         // itself so operations can be chained.
78         senf::console::DirectoryNode & mydir (
79                 .mkdir("myserver")
80                 .doc("My server specific directory"));
81
82         // Add a command to that directory
83         mydir.add("mycommand", &mycommand)
84             .doc("mycommand <foo> [<bar>]\n\n"
85                  "If <bar> is given, flurgle the <foo>, otherwise burgle it");
86
87         // Create a SomeClass instance and add it's directory.
88         SomeClass someClass;
89         mydir.add("someClass", someClass.dir);
90
91         // Start the interactive console server
92         senf::console::Server::start(senf::INet4SocketAddress(senf::INet4Address::None, 23232u))
93             .name("someServer");
94     }
95     \endcode
96
97     \subsection console_nodes Node types
98
99     The console/config library tree consists of two basic node types:
100
101     \li senf::console::DirectoryNode provides internal nodes with an arbitrary number of children
102     \li senf::console::CommandNode describes a command entry in the tree
103     \li senf::console::LinkNode is a link to another node. It works much like a symlink on POSIX
104         systems.
105
106     senf::console::CommandNode is the base-class of all command nodes of which there are several,
107     depending on the type of command.
108
109     There is a single root node, the senf::console::DirectoryNode called senf::console::root(). From
110     this node, the tree is traversed.
111
112     All nodes are allocated on the heap and are managed using a smart pointer.
113
114     \subsection console_manipulate Manipulating the node tree
115
116     There are several ways to add nodes to the tree:
117
118     \li A senf::console::DirectoryNode can be added using senf::console::DirectoryNode::mkdir().
119     \li An arbitrary node can be created and then (possibly later) added to the tree using the
120         corresponding senf::console::DirectoryNode::add() overload.
121     \li A senf::console::CommandNode is normally added to the tree by directly adding a callback
122         using one of the overloaded senf::console::DirectoryNode::add() members. See \ref
123         console_commands.
124     \li A senf::console::LinkNode is created by senf::console::DirectoryNode::link()
125
126     When directly adding a node callback, the type of node added depends on the type of
127     callback. The callback types which can be added are listed at \ref console_callbacks.
128
129     \code
130     void callback(std::ostream & os, senf::console::ParseCommandInfo const & command) { ... }
131     // ...
132     myDirectory.add("foo",&callback);
133     \endcode
134
135     Every node is identified among it's siblings by it's name. The name of the node is set when
136     adding the node to the tree. If the name is empty or non-unique, a unique name will be
137     automatically provided.
138
139     To remove a node from the tree, just use the nodes senf::console::GenericNode::unlink() or the
140     parents senf::console::DirectoryNode::remove() member. This call removes the node from it's
141     parent and returns a (smart) node pointer.
142
143     \li If you ignore the return value, the node (and it's children) will be deleted.
144     \li Alternatively, you may store away the node and re-attach it later.
145     \li An node (or subtree) can be moved to a different place by unlinking the node at it's old
146         place and re-adding it at it's new location.
147     \li To rename a node, unlink and re-add it with a different name.
148
149     \code
150     myDirectory.add("bar", myDirectory.remove("foo"));
151     \endcode
152
153     \subsection console_node_param Assigning additional node parameters
154
155     Depending on the node type added, additional node parameters may be set. For example, every node
156     has a documentation parameter which is used by the online-help system. To assign these
157     parameters, the node exposes corresponding member functions. Since
158     senf::console::DirectoryNode::add() returns the newly added node by reference, additional
159     parameters may just be added to the end of the add command:
160     \code
161     myDirectory.add("foo",&fooCallback).doc("The foo method");
162     \endcode
163     Since the parameter setters all return the node reference, additional parameters may just be
164     added to the end of the command.
165
166     \subsection console_tree_traverse Traversing the tree
167
168     The simplest way to access tree elements is to save the return value of the
169     senf::console::DirectoryNode::add() members. However, saving the reference will not ensure, that
170     the node is not removed. If the node might be removed from the tree, you should use a smart
171     pointer (either <tt>ptr</tt> or <tt>weak_ptr</tt>) to hold the node.
172
173     Another possibility is to traverse the tree explicitly. For this purpose, the operators '[]' and
174     '()' have been overloaded in senf::console::DirectoryNode.
175     \code
176     senf::console::root().getDirectory("myDirectory").getCommand("foo")
177     \\ or more concise but otherwise completely identical
178     senf::console::root()["myDirectory"]("foo")
179     \endcode
180
181     getDirectory and the '[]' operator will return a senf::console::DirectoryNode whereas getCommand
182     and the '()' operator will return a senf::console::CommandNode. If the node is not found or is
183     not of the correct type, an exception will be raised.
184
185     \section console_object_dir Assigning a directory to an object instance
186
187     Most objects will register several commands. So it makes sense for these objects to manage their
188     own directory. Since directories are however allocated on the heap, they cannot be directly
189     added to a class. To facilitate this usage, the senf::console::ScopedDirectory is used. This
190     class provides a senf::console::DirectoryNode facade. Internally, it automatically creates a
191     senf::console::DirectoryNode to which all calls are forwarded.
192
193     The senf::console::ScopedDirectory member should be declared public. This allows the user of the
194     class to add the node to the tree.
195  */
196
197 #ifndef HH_SENF_Scheduler_Console_Node_
198 #define HH_SENF_Scheduler_Console_Node_ 1
199
200 // Custom includes
201 #include <map>
202 #include <boost/shared_ptr.hpp>
203 #include <boost/weak_ptr.hpp>
204 #include <boost/enable_shared_from_this.hpp>
205 #include <boost/utility.hpp>
206 #include <boost/range/iterator_range.hpp>
207 #include <boost/typeof/typeof.hpp>
208 #include <boost/type_traits/remove_reference.hpp>
209 #include <boost/any.hpp>
210 #include "../../Utils/Exception.hh"
211 #include "../../Utils/mpl.hh"
212 #include "../../Utils/Logger/SenfLog.hh"
213 #include "../../Utils/type_traits.hh"
214 #include "Parse.hh"
215
216 //#include "Node.mpp"
217 ///////////////////////////////hh.p////////////////////////////////////////
218
219 namespace senf {
220 namespace console {
221
222     class LinkNode;
223     class DirectoryNode;
224     class CommandNode;
225
226     DirectoryNode & root();
227
228     /** \brief Config/console node tree base-class
229
230         GenericNode is the base class of all node objects. There are two basic node types derived
231         from GenericNode:  DirectoryNode and CommandNode.
232
233         All nodes are dynamically allocated and automatically managed using reference counting.
234
235         All nodes are normally linked into a single tree which root node is
236         senf::console::root(). Nodes may however be orphaned (not linked to the tree) either
237         directly (the node has no parent) or indirectly (the node has a parent but is part of an
238         orphaned subtree which is not linked to the root node).
239
240         Every active (non-orphaned) node (except the root() node) has a non-empty node name. This
241         name is assigned to the node when adding the node to the tree.
242
243         \ingroup node_tree
244       */
245     class GenericNode
246         : public boost::enable_shared_from_this<GenericNode>
247     {
248         SENF_LOG_CLASS_AREA();
249     public:
250         ///////////////////////////////////////////////////////////////////////////
251         // Types
252
253         typedef boost::shared_ptr<GenericNode> ptr;
254         typedef boost::shared_ptr<GenericNode const> cptr;
255         typedef boost::weak_ptr<GenericNode> weak_ptr;
256
257         ///////////////////////////////////////////////////////////////////////////
258
259         virtual ~GenericNode();
260
261         std::string const & name() const; ///< Node name
262         boost::shared_ptr<DirectoryNode> parent() const; ///< Parent node
263                                         /**< May be null, if the node is the root node or if it is
264                                              not linked to the tree */
265
266         std::string path() const;       ///< Node path
267                                         /**< The node path is built by joining the names of all
268                                              parent nodes with '/' chars. */
269         std::string path(DirectoryNode const & root) const;
270                                         ///< Node path up to \a root
271                                         /**< The node path is built by joining the names of all
272                                              parent nodes up to \a root with '/' chars. */
273
274         ptr unlink();                   ///< Remove node from it's parent directory
275                                         /**< You may either discard the return value and thereby
276                                              dispose the node or may re-attach the node at some
277                                              other place using DirectoryNode::add(). */
278
279         bool active() const;            ///< \c true, if node is attached to the root() node
280
281         void help(std::ostream & output) const; /// Write help info to \a output
282
283         ptr thisptr();                  ///< Get smart pointer to node
284         cptr thisptr() const;           ///< Get smart pointer to node (const)
285
286         bool isChildOf(DirectoryNode & parent) const;
287                                         ///< \c true, if node is a child of \a parent
288                                         /**< Will also return \c true, if \a parent is the current
289                                              node. */
290
291         bool operator== (GenericNode & other) const;
292                                         ///< \c true, if this and \a other are the same node
293         bool operator!= (GenericNode & other) const;
294                                         ///< \c true, if this and \a other are different nodes
295
296         bool isDirectory() const;       ///< \c true, if this is a directory node
297         bool isLink() const;            ///< \c true, if this is a link node
298         bool isCommand() const;         ///< \c true, if this is a command node
299
300         GenericNode const & followLink() const; ///< Follow link if \c this node is a link node
301         GenericNode & followLink();     ///< Follow link if \c this node is a link node
302
303     protected:
304         GenericNode();
305
306         void name(std::string const & name);
307
308 #ifndef DOXYGEN
309     private:
310 #else
311     public:
312 #endif
313         virtual void v_help(std::ostream & output) const = 0;
314                                         ///< Provide help information
315                                         /**< This member must be implemented in derived classes
316                                              to provide node specific help information. */
317
318     private:
319         std::string name_;
320         DirectoryNode * parent_;
321
322         friend class DirectoryNode;
323     };
324
325     /** \brief Config/console tree link node
326
327         A LinkNode references another node and provides an additional alias name for that node. A
328         LinkNode works like a mixture of UNIX symlinks and hardlinks: It is an explicit link like a
329         UNIX symlink but references another node directly (not via it's path) like a UNIX
330         hardlink. Therefore, a LinkNode works across chroot().
331       */
332     class LinkNode
333         : public GenericNode
334     {
335     public:
336         ///////////////////////////////////////////////////////////////////////////
337         // Types
338
339         typedef boost::shared_ptr<LinkNode> ptr;
340         typedef boost::shared_ptr<LinkNode const> cptr;
341         typedef boost::weak_ptr<LinkNode> weak_ptr;
342
343         ///////////////////////////////////////////////////////////////////////////
344         ///\name Structors and default members
345         ///@{
346
347         static ptr create(GenericNode & node); ///< Create new link node.
348                                         /**< You should normally use DirectoryNode::link() to
349                                              create a link node. */
350
351         ///@}
352         ///////////////////////////////////////////////////////////////////////////
353
354         GenericNode & follow() const;   ///< Access the referenced node
355
356     protected:
357
358     private:
359         explicit LinkNode(GenericNode & node);
360
361         virtual void v_help(std::ostream &) const;
362
363         GenericNode::ptr node_;
364     };
365
366     class SimpleCommandNode;
367
368     /** \brief Internal: Node creation helper traits
369
370         This class is used internally to find out the type of node to create for a specific argument
371         type.
372      */
373     template <class Object>
374     struct NodeCreateTraits
375     {
376         typedef BOOST_TYPEOF_TPL( senf_console_add_node(
377                                       * static_cast<DirectoryNode *>(0),
378                                       * static_cast<std::string const *>(0),
379                                       * static_cast<Object *>(0),
380                                       0) ) base_type;
381         typedef typename senf::remove_cvref<base_type>::type value_type;
382
383         typedef typename value_type::node_type NodeType;
384         typedef typename value_type::return_type result_type;
385
386         /// Internal
387         struct Creator {
388             static result_type create(DirectoryNode & node, std::string const & name,
389                                       Object & ob);
390         };
391     };
392
393     /** \brief Config/console tree directory node
394
395         This node type provides the internal and root nodes of the tree. It allows to add arbitrary
396         children and supports directory traversal.
397
398         Nodes are normally not instantiated manually but are created by the DirectoryNode via
399         mkdir() or add(). Special add() members however allow externally allocated node objects.
400
401         Nodes may be added to the tree only once, otherwise chaos will ensue. Since nodes are always
402         managed dynamically, there is a special ScopedDirectory proxy template which provides a
403         DirectoryNode facade. ScopedDirectory is used if a class wants to manage it's own directory
404         as a data member.
405
406         Every node is assigned a (new) name when it is added to a directory. If the directory
407         already has an entry of that name, the name is made unique by appending a suffix of the form
408         '-n' where n is a number starting at 1. If the name is empty, int is set to 'unnamed' and
409         then uniquified as above. Automatically providing unique names simplifies adding
410         configuration/console support to generic components.
411
412         \ingroup node_tree
413       */
414     class DirectoryNode : public GenericNode
415     {
416         SENF_LOG_CLASS_AREA();
417         typedef std::map<std::string, GenericNode::ptr> ChildMap;
418     public:
419         ///////////////////////////////////////////////////////////////////////////
420         // Types
421
422         typedef boost::shared_ptr<DirectoryNode> ptr;
423         typedef boost::shared_ptr<DirectoryNode const> cptr;
424         typedef boost::weak_ptr<DirectoryNode> weak_ptr;
425
426         typedef boost::iterator_range<ChildMap::const_iterator> ChildrenRange;
427         typedef ChildMap::const_iterator child_iterator;
428
429         typedef DirectoryNode node_type;
430         typedef DirectoryNode & return_type;
431
432         ///////////////////////////////////////////////////////////////////////////
433         ///\name Structors and default members
434         ///\{
435
436         static ptr create();            ///< Create node object.
437                                         /**< You should normally use either mkdir() or
438                                              ScopedDirectory instead of create() */
439
440         ///\}
441         ///////////////////////////////////////////////////////////////////////////
442         ///\name Children
443         ///\{
444
445         template <class NodeType>
446         NodeType & add(std::string const & name, boost::shared_ptr<NodeType> node);
447                                         ///< Add node to tree
448                                         /**< Adds the \a node to the tree as a child of \a this
449                                              node. The node is given the name \a name. If a node of
450                                              that name already exists, a numeric suffix of the form
451                                              '-n' is added to the name until the name is unique. If
452                                              \a name is empty, it is set to 'unnamed'. */
453
454         template <class Object>
455         typename NodeCreateTraits<Object>::result_type add(std::string const & name,
456                                                            Object const & ob);
457                                         ///< Generic child node factory
458                                         /**< This member is used to create a new child node of the
459                                              current directory. The type of node created depends on
460                                              the type of argument passed.
461
462                                              The node type is selected by the NodeCreateTraits
463                                              class. To allow adding a specific node type, you need
464                                              to provide an overload for
465                                              <tt>senf_console_add_node</tt> which must be visible at
466                                              when you register the new node.
467                                              \code
468                                              MyNodeType & senf_console_add_node(
469                                                  DirectoryNode & dir,
470                                                  std::string const & name,
471                                                  MySpecialObject const & ob,
472                                                  int)
473                                              {
474                                                  return dir.add(name, MyNodeType::create(ob));
475                                              }
476                                              \endcode
477                                              (Do not forget the last unnamed 'int' parameter which
478                                              is not used but serves to disambiguate the
479                                              overloads). */
480
481         template <class Object>
482         typename NodeCreateTraits<Object>::result_type add(std::string const & name,
483                                                            Object & ob);
484                                         ///< Generic child node factory
485                                         /**< \see add() */
486
487         GenericNode::ptr remove(std::string const & name);
488                                         ///< Remove node \a name from the tree
489                                         /**< The returned pointer may either be discarded, which
490                                              will automatically dispose the removed node, or it may
491                                              be saved and/or re-attached at some other place in the
492                                              tree. */
493
494         bool hasChild(std::string const & name) const;
495                                         ///< \c true, if there is a child with name \a name
496
497         GenericNode & get(std::string const & name) const;
498                                         ///< Get child node automatically dereferencing links
499                                         /**< \throws UnknownNodeNameException if a child \a name
500                                                  does not exist */
501         GenericNode & getLink(std::string const & name) const;
502                                         ///< Get child node without dereferencing links
503                                         /**< \throws UnknownNodeNameException if a child \a name
504                                                  does not exist */
505
506         DirectoryNode & getDirectory(std::string const & name) const;
507                                         ///< Get directory child node (dereferencing links)
508                                         /**< Same as operator[]
509                                              \throws UnknownNodeNameException if a child \a name
510                                                  does not exist.
511                                              \throws std::bad_cast if the child \a name is not a
512                                                  directory node. */
513
514         DirectoryNode & operator[](std::string const & name) const;
515                                         ///< Get directory child node (dereferencing links)
516                                         /**< Same as getDirectory
517                                              \throws UnknownNodeNameException if a child \a name
518                                                  does not exist.
519                                              \throws std::bad_cast if the child \a name is not a
520                                                  directory node. */
521
522         CommandNode & getCommand(std::string const & name) const;
523                                         ///< Get command child node (dereferencing links)
524                                         /**< Same as operator()
525                                              \throws UnknownNodeNameException if a child \a name
526                                                  does not exist
527                                              \throws std::bad_cast if the child \a name is not a
528                                                  command node. */
529
530         CommandNode & operator()(std::string const & name) const;
531                                         ///< Get command child node (dereferencing links)
532                                         /**< Same as getCommand()
533                                              \throws UnknownNodeNameException if a child \a name
534                                                  does not exist
535                                              \throws std::bad_cast if the child \a name is not a
536                                                  command node. */
537
538         DirectoryNode & mkdir(std::string const & name);
539                                         ///< Create sub-directory node
540
541         ChildrenRange children() const; ///< Return iterator range over all children.
542                                         /**< The returned range is sorted by child name. */
543
544         ChildrenRange completions(std::string const & s) const;
545                                         ///< Return iterator range of completions for \a s
546                                         /**< The returned range is sorted by child name. */
547
548         void link(std::string const & name, GenericNode & target);
549                                         ///< Create a child node which is a link to target. \a s
550                                         /**< The new link node will be a child of the node for which this member function is called. */
551
552         ///\}
553         ///////////////////////////////////////////////////////////////////////////
554
555         DirectoryNode & doc(std::string const & doc); ///< Set node documentation
556
557         ptr thisptr();
558         cptr thisptr() const;
559
560     protected:
561         DirectoryNode();
562
563     private:
564         void add(GenericNode::ptr node);
565         virtual void v_help(std::ostream & output) const;
566
567         ChildMap children_;
568         std::string doc_;
569
570         friend DirectoryNode & root();
571     };
572
573     /// Exception: Unknown node name
574     struct UnknownNodeNameException : public senf::Exception
575     { UnknownNodeNameException() : senf::Exception("Unknown node name") {}};
576
577 #ifndef DOXYGEN
578     template <class Type>
579     struct NodeCreateTraits< boost::shared_ptr<Type> >
580     {};
581 #endif
582
583     /** \brief Config/console tree command node
584
585         The CommandNode is the base-class for the tree leaf nodes. Concrete command node
586         implementations are derived from this class.
587
588         To execute a command, CommandNode::operator()() or CommandNode::execute() is called.
589
590         Subclass instances of this node type are automatically created when adding commands to the
591         tree. See \ref console_commands.
592
593         \ingroup node_tree
594       */
595     class CommandNode : public GenericNode
596     {
597         SENF_LOG_CLASS_AREA();
598     public:
599         ///////////////////////////////////////////////////////////////////////////
600         // Types
601
602         typedef boost::shared_ptr<CommandNode> ptr;
603         typedef boost::shared_ptr<CommandNode const> cptr;
604         typedef boost::weak_ptr<CommandNode> weak_ptr;
605
606         ///////////////////////////////////////////////////////////////////////////
607
608         void execute(std::ostream & output, ParseCommandInfo const & command) const;
609                                         ///< Execute the command
610                                         /**< \param[in] output stream where result messages may be
611                                                  written to
612                                              \param[in] arguments command arguments. This is a
613                                                  range of ranges of Token instances. */
614
615         void execute(boost::any & rv, std::ostream & output, ParseCommandInfo const & command) 
616             const;
617                                         ///< Execute the command
618                                         /**< \param[out] rv command return value
619                                              \param[in] output stream where result messages may be
620                                                  written to
621                                              \param[in] arguments command arguments. This is a
622                                                  range of ranges of Token instances. */
623
624         void operator()(std::ostream & output, ParseCommandInfo const & command) const;
625                                         ///< Execute the command
626                                         /**< Same as execute()
627                                              \param[in] output stream where result messages may be
628                                                  written to
629                                              \param[in] arguments command arguments. This is a
630                                                  range of ranges of Token instances. */
631         void operator()(boost::any & rv, std::ostream & output, ParseCommandInfo const & command)
632             const;
633
634         ptr thisptr();
635         cptr thisptr() const;
636
637     protected:
638         CommandNode();
639
640 #ifndef DOXYGEN
641     private:
642 #endif
643         virtual void v_execute(boost::any & rv, std::ostream & os, ParseCommandInfo const & command)
644             const = 0;
645                                         ///< Called to execute the command
646                                         /**< \param[out] rv return value holder
647                                              \param[in] arguments command arguments. This is a
648                                                  range of ranges of Token instances. */
649
650     private:
651     };
652
653     /** \brief Most simple CommandNode implementation
654
655         This CommandNode implementation simply forwards the \a output and \a arguments arguments to
656         an arbitrary callback. Thus, it allows to add callbacks with the signature
657         \code
658         void callback(std::ostream & os, senf::console::ParseCommandInfo const & command)
659         { ... }
660         \endcode
661         to the tree.
662
663         \ingroup console_commands
664      */
665     class SimpleCommandNode : public CommandNode
666     {
667         SENF_LOG_CLASS_AREA();
668     public:
669         ///////////////////////////////////////////////////////////////////////////
670         // Types
671
672         typedef boost::shared_ptr<SimpleCommandNode> ptr;
673         typedef boost::shared_ptr<SimpleCommandNode const> cptr;
674         typedef boost::weak_ptr<SimpleCommandNode> weak_ptr;
675
676         typedef boost::function<void (std::ostream &, ParseCommandInfo const &)> Function;
677
678         typedef SimpleCommandNode node_type;
679         typedef SimpleCommandNode & return_type;
680
681         ///////////////////////////////////////////////////////////////////////////
682         ///\name Structors and default members
683         ///\{
684
685         static ptr create(Function const & fn);
686
687         ///\}
688         ///////////////////////////////////////////////////////////////////////////
689
690         ptr thisptr();
691         cptr thisptr() const;
692
693         SimpleCommandNode & doc(std::string const & doc);
694
695     protected:
696         SimpleCommandNode(Function const & fn);
697
698     private:
699         virtual void v_help(std::ostream & output) const;
700         virtual void v_execute(boost::any & rv, std::ostream & os, ParseCommandInfo const & command)
701             const;
702
703
704         Function fn_;
705         std::string doc_;
706     };
707
708 #ifndef DOXYGEN
709
710     SimpleCommandNode & senf_console_add_node(DirectoryNode & node, std::string const & name,
711                                               SimpleCommandNode::Function fn, int);
712
713 #endif
714
715 }}
716
717 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
718
719 BOOST_TYPEOF_REGISTER_TYPE(senf::console::DirectoryNode)
720 BOOST_TYPEOF_REGISTER_TYPE(senf::console::SimpleCommandNode)
721
722
723 ///////////////////////////////hh.e////////////////////////////////////////
724 #include "Node.cci"
725 //#include "Node.ct"
726 #include "Node.cti"
727 #endif
728
729
730 // Local Variables:
731 // mode: c++
732 // fill-column: 100
733 // comment-column: 40
734 // c-file-style: "senf"
735 // indent-tabs-mode: nil
736 // ispell-local-dictionary: "american"
737 // compile-command: "scons -u test"
738 // End: