OverloadedCommand.cci
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 
14 /** \file
15  \brief OverloadedCommand inline non-template implementation */
16 
17 //#include "OverloadedCommand.ih"
18 
19 // Custom includes
20 #include <iostream>
21 
22 #define prefix_ inline
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 // senf::console::OverloadedCommandNode
27 
28 prefix_ senf::console::OverloadedCommandNode::ptr senf::console::OverloadedCommandNode::create()
29 {
30  return ptr(new OverloadedCommandNode());
31 }
32 
33 prefix_ senf::console::OverloadedCommandNode::ptr senf::console::OverloadedCommandNode::thisptr()
34 {
35  return boost::static_pointer_cast<OverloadedCommandNode>(shared_from_this());
36 }
37 
38 prefix_ senf::console::OverloadedCommandNode::cptr senf::console::OverloadedCommandNode::thisptr()
39  const
40 {
41  return boost::static_pointer_cast<OverloadedCommandNode const>(shared_from_this());
42 }
43 
44 prefix_ senf::console::OverloadedCommandNode &
45 senf::console::OverloadedCommandNode::doc(std::string const & doc)
46 {
47  doc_ = doc;
48  return *this;
49 }
50 
51 prefix_ senf::console::OverloadedCommandNode &
52 senf::console::OverloadedCommandNode::shortdoc(std::string const & doc)
53 {
54  shortdoc_ = doc;
55  return *this;
56 }
57 
58 prefix_ unsigned
59 senf::console::OverloadedCommandNode::overloadIndex(CommandOverload const & overload)
60 {
61  return find(overloads_.begin(), overloads_.end(), CommandOverload::cptr(&overload))
62  - overloads_.begin() + 1;
63 }
64 
65 prefix_ senf::console::OverloadedCommandNode::OverloadsRange
66 senf::console::OverloadedCommandNode::overloads()
67  const
68 {
69  return boost::make_iterator_range(overloads_.begin(), overloads_.end());
70 }
71 
72 prefix_ senf::console::OverloadedCommandNode::OverloadedCommandNode()
73 {}
74 
75 //-/////////////////////////////////////////////////////////////////////////////////////////////////
76 // senf::console::SimpleCommandOverload
77 
78 prefix_ senf::console::SimpleCommandOverload::ptr
79 senf::console::SimpleCommandOverload::create(Function fn)
80 {
81  return ptr(new SimpleCommandOverload(fn));
82 }
83 
84 prefix_ senf::console::SimpleCommandOverload &
85 senf::console::SimpleCommandOverload::doc(std::string const & doc)
86 {
87  doc_ = doc;
88  return *this;
89 }
90 
91 prefix_ senf::console::SimpleCommandOverload::SimpleCommandOverload(Function fn)
92  : fn_ (fn)
93 {}
94 
95 //-/////////////////////////////////////////////////////////////////////////////////////////////////
96 // senf::console::SimpleOverloadAttributor
97 
98 prefix_ senf::console::SimpleOverloadAttributor::
99 SimpleOverloadAttributor(SimpleCommandOverload::Function fn)
100  : overload_ (SimpleCommandOverload::create(fn))
101 {}
102 
103 prefix_ senf::console::SimpleOverloadAttributor const &
104 senf::console::SimpleOverloadAttributor::doc(std::string const & doc)
105  const
106 {
107  doc_ = doc;
108  return *this;
109 }
110 
111 prefix_ senf::console::SimpleOverloadAttributor const &
112 senf::console::SimpleOverloadAttributor::shortdoc(std::string const & doc)
113  const
114 {
115  shortdoc_ = doc;
116  return *this;
117 }
118 
119 prefix_ senf::console::SimpleOverloadAttributor const &
120 senf::console::SimpleOverloadAttributor::overloadDoc(std::string const & doc)
121  const
122 {
123  overload_->doc(doc);
124  return *this;
125 }
126 
127 prefix_ senf::console::OverloadedCommandNode &
128 senf::console::SimpleOverloadAttributor::create(DirectoryNode & dir, std::string const & name)
129  const
130 {
131  OverloadedCommandNode & node (OverloadedCommandNode::insertOverload(dir, name, overload_));
132  if (doc_) node.doc(*doc_);
133  if (shortdoc_) node.shortdoc(*shortdoc_);
134  return node;
135 }
136 
137 //-/////////////////////////////////////////////////////////////////////////////////////////////////
138 #undef prefix_
139 
140 
141 // Local Variables:
142 // mode: c++
143 // fill-column: 100
144 // comment-column: 40
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // End: