Tulip  5.1.0
Large graphs analysis and drawing
WithParameter.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip 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.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef _TULIPWITHPARAMETER
21 #define _TULIPWITHPARAMETER
22 
23 #include <string>
24 #include <typeinfo>
25 #include <vector>
26 
27 #include <tulip/tulipconf.h>
28 
29 namespace tlp {
30 
31 class Graph;
32 class DataSet;
33 template<class itType >
34 struct Iterator;
35 
36 /**
37  * @ingroup Plugins
38  * @brief The ParameterDirection enum describes how a parameter is passed to a plugin
39  * The parameter can be seen as passing parameters to a C++ functions and works as follow:
40  * @list
41  * @li IN_PARAM: The parameter is passes by value
42  * @li OUT_PARAM: The parameter is a return value
43  * @li INOUT_PARAM: The parameter is passed by reference.
44  * @endlist
45  */
46 enum ParameterDirection { IN_PARAM=0, OUT_PARAM = 1, INOUT_PARAM = 2 };
47 
48 /**
49  * @ingroup Plugins
50  * @brief Describes a plugin's parameter.
51  *
52  * A plugin parameter consists of the following information:
53  * @list
54  * @li A name (std::string) which can be used to retrieve the value of the parameter when running the plugin.
55  * @li A type (std::string) which is the C++ typename of the parameter.
56  * @li A help string (std::string) which gives additional information about the parameter and its possible values.
57  * @li A default value which is mapped on the parameter if no value has been entered by the user.
58  * @li The mandatory flag (bool) which tells if the parameter is optional or not.
59  * @li A ParameterDirection (enum).
60  * @endlist
61  *
62  * @see tlp::ParameterDirection
63  * @see tlp::ParameterDescriptionList
64  * @see tlp::WithParameter
65  **/
66 class TLP_SCOPE ParameterDescription {
67 private:
68  std::string name;
69  std::string type;
70  std::string help;
71  std::string defaultValue;
72  bool mandatory;
73  ParameterDirection direction;
74 public:
76  ParameterDescription(const std::string& name, const std::string& type,
77  const std::string& help, const std::string& defaultValue,
78  bool mandatory, ParameterDirection direction)
79  : name(name), type(type), help(help),
80  defaultValue(defaultValue), mandatory(mandatory),
81  direction(direction) {}
82 
83  /**
84  * @return The parameter's name
85  */
86  const std::string& getName() const {
87  return name;
88  }
89  /**
90  * @return The parameter's C++ type name
91  */
92  const std::string& getTypeName() const {
93  return type;
94  }
95  /**
96  * @return The parameter's help string
97  */
98  const std::string& getHelp() const {
99  return help;
100  }
101  /**
102  * @return The parameter's default value.
103  */
104  const std::string& getDefaultValue() const {
105  return defaultValue;
106  }
107  /**
108  * @brief Set the parameter's default value.
109  */
110  void setDefaultValue(const std::string& defVal) {
111  defaultValue = defVal;
112  }
113  /**
114  * @return Whether the parameter is mandatory or not.
115  */
116  bool isMandatory() const {
117  return mandatory;
118  }
119  /**
120  * @return The parameter's direction
121  */
123  return direction;
124  }
125  /**
126  * @return Set the parameter's direction
127  */
129  direction = dir;
130  }
131  /**
132  * @return Whether the parameter is editable or not.
133  */
134  bool isEditable() const {
135  // input parameters are editable
136  return (direction != OUT_PARAM) ||
137  // only property output parameters are editable
138  (type.find("Property") != std::string::npos);
139  }
140 };
141 
142 /**
143  * @ingroup Plugins
144  * @brief This class describes parameters taken by a plugin.
145  *
146  * It is used by WithParameter to store parameters.
147  * Each parameter is identified by a name, has a default value, a value, a help string, and a boolean indicating whether it is mandatory or optional.
148  **/
149 struct TLP_SCOPE ParameterDescriptionList {
150 
152 
153  /**
154  * @brief Adds a new parameter of type T to the list.
155  *
156  * @param parameterName The name of the parameter.
157  * @param help The help string of this parameter. Defaults to std::string().
158  * @param defaultValue The default value of this parameter. Defaults to std::string().
159  * @param isMandatory Whether this parameter is mandatory or optional. Defaults to true.
160  * @param direction The parameter's direction (see tlp::ParameterDirection for details)
161  * @return void
162  **/
163  template<typename T> void add(const std::string& parameterName,
164  const std::string& help,
165  const std::string& defaultValue,
166  bool isMandatory = true,
167  ParameterDirection direction = IN_PARAM,
168  const std::string &valuesDescription = std::string()) {
169  for (unsigned int i = 0; i < parameters.size(); ++i) {
170  if (parameters[i].getName() == parameterName) {
171 #ifndef NDEBUG
172  tlp::warning() << "ParameterDescriptionList::add " << parameterName << " already exists" << std::endl;
173 #endif
174  return;
175  }
176  }
177 
178  ParameterDescription newParameter(parameterName,
179  typeid(T).name(),
180  generateParameterHTMLDocumentation(parameterName, help, typeid(T).name(), defaultValue, valuesDescription, direction),
181  defaultValue,
182  isMandatory, direction);
183  parameters.push_back(newParameter);
184  }
185 
186  /**
187  * @brief Retrieves an Iterator on the parameters.
188  *
189  * @return An iterator over the parameters :Iterator<ParameterDescription>*
190  **/
191  tlp::Iterator<ParameterDescription>* getParameters() const;
192 
193  /**
194  * @brief retrieves the default value of a parameter.
195  *
196  * @param parameterName The name of the parameter to retrieve the default value of.
197  * @return The default value of the parameter:string
198  **/
199  const std::string& getDefaultValue(const std::string& parameterName) const;
200 
201  /**
202  * @brief Sets the default value of a parameter.
203  *
204  * @param parameterName The name of the parameter to set the value of.
205  * @param value The new value for this parameter.
206  * @return void
207  **/
208  void setDefaultValue(const std::string& parameterName,
209  const std::string& value);
210 
211  /**
212  * @brief Sets the direction of a parameter.
213  *
214  * @param parameterName The name of the parameter to set the value of.
215  * @param dir The new direction for this parameter.
216  * @return void
217  **/
218  void setDirection(const std::string& parameterName,
219  ParameterDirection direction);
220 
221  /**
222  * @brief Retrieves whether a parameter is mandatory or optional.
223  *
224  * @param parameterName The name of the parameter for which to checkparait is mandatory or optional.
<8i! 216  203  *&#">  }breturn void
<> 218 
22__plugins.html#gtrue,
200 22a name="l00199"> 120  *2span>
  }
2a name="l00132"> ,60; 155  2@return Whether the parameter i2 editable or not.
  2@span>
lts to tro 33  2@param parameterName The name of3the parameter for which to checkparait is mandatinG A grapha 2@  2o"> 217  **w">return (direction != 23irection
<> 218  // only property output p2rameters are editonst std::string& parameterbuil class= 33ParameterDirectio">Parparamete="la_ cls="line 33//line">ro 33ParameterDirectio">Parparametegraphs="lineGraph">//*tinG = NULL00"> 200 "Pr23a name="l00199"> 120  *2a name="l00141">
ass= 155  2span>
<> 218  163  add(const 135  2span>
pan>  2s">return (direction != 24ame="l00107">  2sent">// only property output p2 name, has a default value, a value, 218  "Pr2a name="l00149"> 120  *2aa name="l00140">#160;conn>  *2name="l00151"> 151 ass= 155  2ucttlp_1_1_parameter_descriptio25 name="l00132"> 203 conn> 160  2n>
pa><> 218 
163  typename T> std::string&ama47a6a9558b5ded805a3b581fb560bc1d"83eb4"> 163  135  2 @brief Adds a new parameter of25lass="line"> pan>  2
25iv>
2 @param parameterName The name 2f the parameter.an>  2 ent">// only property output p2this parameter. Defaults to class="lineno"> 68  std::string name;
<2 @param defaultValue The defaul25lass="keyword">cocription newParameter(parameterName,
2 a name="l00140"> rd">typeid(T).name(), defaullass="keyword">const;
,6lass="keyword">const;
  2 @param direction The parameter26Name() == parameterName) {
;
 
;
182  2*/
;
220 cons2 std::stridiv cv 2t;
 
2 std::st/span> 26 the parameter.an>  2 178  cons26 name="l00149">  for (if (parameters[i].g27neno"> 151 5px;2}\ 218 
-left 5px;2}/spa/style"lin\ 218 
<\q/a>  cons2class="line"> 
27ne"><\q/a>  27 the parameter.an>  2name="l00178"> 178<\q/a>  cons2n.html">Parametpan>  for (  221  /** defaultValue,
<28 name="l00132"> 120  *2 isMandatory, directi28="l00153"> pn class="lineno"> 144  * 2wParameter);
145  *<2  *2 /span>
2e="l00186"> pivThes="line">
163
  2@return An iterator over the pa2ameters :Iterator<ParameterDescrip 218 
120  *2rDescription>* getParameters29 name="l00132"> 188  *2n>
ass= 155  2
2a name="l00194"> 2:n>;
<29iv>
ParameterDirectio>() {}
="l00161"> 1parameter name="l00192"> 192  
120  *2r cons2 145  *<2@return An iterator over the pa29meters :Iterator<ParameterDescription 145  *<3n>
it is mandatnional.
  *<3
3a name="l00202">
*<3<>
3 name="l00204"> lts to true.
requir0018"lineno"eno"> n class="lineno"> 160  3@param parameterName The name o3 the parameter to set the value of.
<9">
*<3
<3his parameter.
2o"> 217  *3@return void
218  std::strss="keywordtype">void
163 163const;
,pan>  const;
  3n>
;
182  3
31v class="line">onst std::string&ama47a6a9558b5 name="l00167"> 167  3@brief Sets the direction of a 31);
169  <31e"> ,6escripe="l00181">  std::stri>  3@param dir The new direction fo3 this parameter.
  120  *3/
145  *<3>void setDirection( 189  *3s="code" href="group___plugins.31meters :Iterator<ParameterDescription&gmandatnional.
  *<3n>
no).
A=ss="keywords
*<3
3a name="l00222">
  *<3@brief Retrieves whether a para3eter is mandatory or optional.
s to true.
requir0018"lineno"eno"> n class="lineno"> 160  3/span>
<3 name="l00224"> >
<9">
*<3@param parameterName The name o3 the parameter for which to checkparait is no"> 2o"> 217  *36 
std::strss="keywordtype">void
163 163const;
,pan>  32/span> std::string &valuesDescriplass="keyword">const;
169,pan>  182 169,pan>  std::string&ama47a6a9558b5 name="l00167"> 167  3
33v class="line">
;
169  ,6escripe="l00181"> 
<="line"> 145  *<3ment">// only property output p33a name="l00218">  *<3mescription.html#a2de6acab57c">33a name="l00199">  *<3
*<3a name="l00141">
ass=v>s to true.
requir0018"lineno"eno"> n class="lineno"> 160  3span>
<9">
*<3sspan>
<3 class="line"> 2o"> 217  *3brief This class describes pa><3 e of a parameter.
218 
,pan>  // only property output p34__plugins.html#ga228aba44e44a0b8f8a8eeflass="keyword">const;
169,pan>  "Pr34/span> std::string &valuesDescriptis="line"> 182 169,pan>  (T).name(),
std::string&ama47a6a9558b5 name="l00167"> 167  3name="l00151"> 169  ,6escripe="l00181"> 
  3
  120  *3
35is parameter.
(deprecated) 120  *3<">return (direction != 3f the parameter.>  *<3 ent">// only property output p3this parameter. Defaults to div class="lineserliddIn47"><() 120  *3"Pr35a name="l00199"><() 120  *3  *<3 @param direction The parameter36="l00201"> it is mandatnional.
  *<3 @return void
3*/
  3*/span>
lts to true.
requir0018"lineno"eno"> n class="lineno"> 160  3 cons36the parameter for which to checkparait is no"> 2o"> 217  *3 /span>
,pan>  cons36/span> std::string &valuesDescriptif8a8eeflass="keyword">const;
169,pan>  for ( 182 169,pan>  if (parameters[i].g37ocumentation(parameterName, help, std::string&ama47a6a9558b5 name="l00167"> 167  ,6escripe="l00181">
3#endif
  cons3class="line">
120  *3#/span>
37ne">indicatene">  *3# 37 the parameter.r<ParameterDescription 145  *<3name="l00178"> 178 2pan>an/6">orss="me="l001out>0173" 144  * 3# cons3n.html">Parametp0203">for (consing&ama47a6a9558b5 "> 192  221  /*3 defaultValue,
<38 name="l00132">  /*3 /
221  std::string name;
<3wParameter);
  /*3 cons38the parameter for which to checkparaia"> 120  *3 /span>
3e="l00186"> pion&gclass="v> 188  *3
3a name="l00187"> 218  ParameterDirectio>() {}
161"> 1nn class="lsp name="l00144">  /*3 cons38.html">Parametp0203">  /*3 ">for (
 <39 name="l00132">an> 
>  3
3a name="l00194">160;="lref="cn> ()act_"me="l00_8h_source 0@()actPme="l00.h:3ne"f="cn>cn>&# 160;0@c94097478c6058dea2">160;0@c94097478c6058dea2">="l00161"> n class="lin"l0016 getNf="192neno"> n> 0<.h:86e"f="cn>cn>&# 160;160;="l00Graph">// n>  @retGraph00:lass=f="cn>cn>&# 160; 163   2neno"> n> "eo">#160;conn> n> "<.h:2ekeywordn>cn>&# 160;160;It>typor 1l0"cn> Inne"ftypors. Allows basic it>typords

typordpaonly.> n> typori8h_source 0@9">It>typor.h:39e"f="cn>cn>&# 160;160;="l00161">< 1l0"cn> ) n> 1descl00147"><.h:128s=f="cn>cn>&# 160; 163<::iddOut47"> <(eno">n class="lin"l0016o"> ,6eno">n class="lin"l001665 169,6eno">n class="lin"l0016e="l00181"><=lineno"> 169,603n class="lin"l00169"> 169) n>  > n> 3<.h:327ref="cn>cn>&# 160;  n> 11/spl00147"><.h:116e"f="cn>cn>&# 160;160;// n> Dnoori"linspab7c14crectio_="la_ cli8h_source 1/1/ddd7cd910a4f279e19f">160;1/ddd7cd910a4f279e19f">="l00161">< 1l0"cn>  n> 1@bril00147"><.h:122s=f="cn>cn>&# 160; 163   2neno"> n> Ro"> 213"> > n> "briel00147"><.h:2 class=n>cn>&# 160;60;< 1l0"cn> <(eno">n class="lin"l0016e="81") n> Set ns="line">Dnoori"linspab7c14crectio_"itaerName,1n><.h:11a nf="cn>cn>&# 160;60;<,

< 1l0"cn> "s="> 04/spl00147"><.h:4ss=f="cn>cn>&# 160; 163<::idd47"> <(eno">n class="lin"l0016o"> ,6eno">n class="lin"l001665 169,6eno">n class="lin"l0016e="l00181"><=lineno"> 169,603 (deprecated)> n> 36/spl00147"><.h:367ref="cn>cn>&# 160; 163   n class="lin"l0016a>N"> ,6eno">n class="lin"l001665n class="lin"l0016e="l00181"><,603lass="=> 168n class="lin"l00169"> 169) n> of1:str Tspaniv>< clas> n> 16/spl00147"><.h:16keywordn>cn>&# 160; 163<::iddInOut47"> <(eno">n class="lin"l0016o"> ,6eno">n class="lin"l001665 169,6eno">n class="lin"l0016e="l00181"><=lineno"> 169,603n class="lin"l00169"> 169) n>  > n> 34/spl00147"><.h:34ss=f="cn>cn>&# 160;60; n class="lin"l0016 getHe"l192neno"> n> 09escl00147"><.h:98s=f="cn>cn>&# 160;60; n class="lin"l0016 getTstrNf="192neno"> n> 09bril00147"><.h:92s=f="cn>cn>&# 160; 163<::iddIn47"> <(eno">n class="lin"l0016o"> ,6eno">n class="lin"l001665n class="lin"l0016e="l00181"><,603
n class="lin"l00169"> 169) n>  > n> 30escl00147"><.h:30href="cn>cn>&# 160;60;  n> 13riel00147"><.h:13 class=n>cn>&# 160;160;="l00161">< 1l0"cn> n class="lin"l0016 gete="l00181"><(92neno"> n> 10riel00147"><.h:10 class=n>cn>&# 160; 163  ="l00161"> 1 n> "sine">Dnoori"linspab7c14crectio_"itaerName,1aa nl00147"><.h:149e"f="cn>cn>&# 160;160;="l00161"> 1 n> Dme="l0014ainenoi n> 06/spl00147"><.h:6ss=f="cn>cn>&# 160; 163<> 1 n> "sine"> > n> "8escl00147"><.h:28href="cn>cn>&# 1cn>!-- fragescr -->1cn>!-- nentof.s --> 1cn>!-- eoc-nentof. --> 1!-- start fooa> 160; 1cn>&# 1cbody# 1c