CLI  2.9
param.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
31 
32 #ifndef _CLI_PARAM_H_
33 #define _CLI_PARAM_H_
34 
35 #include "cli/namespace.h"
36 #include "cli/syntax_node.h"
37 #include "cli/tk.h"
38 
39 
41 
42  // Forward declarations.
43  class Help;
44 
45 
50  class Param : public SyntaxNode
51  {
52  protected:
54  explicit Param(
55  const char* const STR_Keyword,
56  const Help& CLI_Help
59  );
60 
61  public:
63  virtual ~Param(void);
64 
65  private:
67  explicit Param(void);
69  Param(const Param&);
71  Param& operator=(const Param&);
72 
73  public:
74  // Inherit doxygen comments from cli::Element documentation.
75  virtual const tk::String GetKeyword(void) const;
76 
77  // Inherit doxygen comments from cli::Element documentation.
78  virtual const bool FindElements(Element::List& CLI_ExactList, Element::List& CLI_NearList, const char* const STR_Keyword) const;
79 
80  // Note: use of @param doxygen tag in order to avoid doxygen warnings for reimplementations in sub-classes.
86  virtual const bool SetstrValue(const char* const STR_Value) const = 0;
87 
90  const tk::String GetstrValue(void) const;
91 
96  virtual const Param* const Clone(void) const = 0;
97 
100  const Param* const GetCloned(void) const;
101 
102  // Note: use of @param doxygen tag in order to avoid doxygen warnings for reimplementations in sub-classes.
106  virtual const Param& CopyValue(const Param& CLI_Param) const = 0;
107 
108  protected:
111  const bool SetValue(
112  const char* const STR_Value
113  ) const;
114 
117  const Param* const InitClone(
118  Param& CLI_CloneParam
119  ) const;
120 
123  const bool SetCloned(
124  const Param& CLI_Cloned
125  );
126 
127  private:
129  mutable tk::String m_strValue;
130 
132  const Param* m_pcliCloned;
133  };
134 
135 
137  template <class T> class ParamT : public Param
138  {
139  public:
141  explicit ParamT<T>(
142  const char* const STR_Keyword,
143  const T& T_Default,
144  const Help& CLI_Help
145  )
146  : Param(STR_Keyword, CLI_Help),
147  m_tValue(T_Default)
148  {
149  }
150 
152  virtual ~ParamT<T>(void)
153  {
154  }
155 
156  private:
158  explicit ParamT<T>(void);
160  ParamT<T>(const ParamT<T>&);
162  ParamT<T>& operator=(const ParamT<T>&);
163 
164  public:
166  operator const T(void) const
167  {
168  return m_tValue;
169  }
170 
171  // Inherit doxygen comments from cli::Param documentation.
172  virtual const Param& CopyValue(const Param& CLI_Param) const
173  {
174  if (const ParamT<T>* const pcli_Param = dynamic_cast<const ParamT<T>*>(& CLI_Param))
175  {
176  SetValue(CLI_Param.GetKeyword(), *pcli_Param);
177  }
178  return *this;
179  }
180 
181  protected:
183  void SetValue(
184  const char* const STR_Value,
185  const T& T_Value
186  ) const
187  {
188  Param::SetValue(STR_Value);
189  m_tValue = T_Value;
190  }
191 
192  private:
194  mutable T m_tValue;
195  };
196 
198 
199 #endif // _CLI_PARAM_H_
200 
virtual const Param *const Clone(void) const =0
Parameter cloning handler.
const bool SetCloned(const Param &CLI_Cloned)
Cloned parameter reference setting.
Main namespace of the CLI library.
Template parameter class.
Definition: param.h:137
SyntaxNode class definition.
Help container class.
Definition: help.h:46
virtual ~Param(void)
Destructor.
Syntax node elements.
Definition: syntax_node.h:51
const bool SetValue(const char *const STR_Value) const
Value setting from derived class.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
virtual const bool SetstrValue(const char *const STR_Value) const =0
Value setting.
Namespace management.
virtual const Param & CopyValue(const Param &CLI_Param) const =0
Value copy handler.
Base parameter class.
Definition: param.h:50
virtual const bool FindElements(Element::List &CLI_ExactList, Element::List &CLI_NearList, const char *const STR_Keyword) const
Sub-elements search.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
const Param *const InitClone(Param &CLI_CloneParam) const
Clone initialization.
void SetValue(const char *const STR_Value, const T &T_Value) const
Value setting for derived class.
Definition: param.h:183
CLI toolkit definition.
const Param *const GetCloned(void) const
Cloned parameter access.
virtual const tk::String GetKeyword(void) const
String identifier accessor.
const tk::String GetstrValue(void) const
Value access in its string form.
tk::Queue< const Element * > List
CLI element list type.
Definition: element.h:61
virtual const Param & CopyValue(const Param &CLI_Param) const
Value copy handler.
Definition: param.h:172