22 #ifndef _TULIPWITHPARAMETER 23 #define _TULIPWITHPARAMETER 29 #include <tulip/tulipconf.h> 35 template <
class itType>
48 enum ParameterDirection { IN_PARAM = 0, OUT_PARAM = 1, INOUT_PARAM = 2 };
70 class TLP_SCOPE ParameterDescription {
75 std::string defaultValue;
77 ParameterDirection direction;
80 ParameterDescription() {}
81 ParameterDescription(
const std::string &name,
const std::string &type,
const std::string &help,
82 const std::string &defaultValue,
bool mandatory,
83 ParameterDirection direction)
84 : name(name), type(type), help(help), defaultValue(defaultValue), mandatory(mandatory),
85 direction(direction) {}
90 const std::string &getName()
const {
96 const std::string &getTypeName()
const {
102 const std::string &getHelp()
const {
108 const std::string &getDefaultValue()
const {
114 void setDefaultValue(
const std::string &defVal) {
115 defaultValue = defVal;
120 bool isMandatory()
const {
126 ParameterDirection getDirection()
const {
132 void setDirection(ParameterDirection dir) {
138 bool isEditable()
const {
140 return (direction != OUT_PARAM) ||
142 (type.find(
"Property") != std::string::npos);
154 struct TLP_SCOPE ParameterDescriptionList {
156 ParameterDescriptionList() {}
168 template <
typename T>
169 void add(
const std::string ¶meterName,
const std::string &help,
170 const std::string &defaultValue,
bool isMandatory =
true,
171 ParameterDirection direction = IN_PARAM,
172 const std::string &valuesDescription = std::string()) {
173 for (
unsigned int i = 0; i < parameters.size(); ++i) {
174 if (parameters[i].getName() == parameterName) {
176 tlp::warning() <<
"ParameterDescriptionList::add " << parameterName <<
" already exists" 183 ParameterDescription newParameter(
184 parameterName,
typeid(T).name(),
185 generateParameterHTMLDocumentation(parameterName, help,
typeid(T).name(), defaultValue,
186 valuesDescription, direction),
187 defaultValue, isMandatory, direction);
188 parameters.push_back(newParameter);
204 const std::string &getDefaultValue(
const std::string ¶meterName)
const;
213 void setDefaultValue(
const std::string ¶meterName,
const std::string &value);
222 void setDirection(
const std::string ¶meterName, ParameterDirection direction);
231 bool isMandatory(
const std::string ¶meterName)
const;
243 void buildDefaultDataSet(DataSet &ioDataSet, Graph *inG =
nullptr)
const;
250 inline unsigned int size()
const {
251 return parameters.size();
259 inline bool empty()
const {
260 return parameters.empty();
264 ParameterDescription *getParameter(
const std::string ¶meterName);
265 std::string generateParameterHTMLDocumentation(
const std::string &name,
const std::string &help,
266 const std::string &type,
267 const std::string &defaultValue,
268 const std::string &valuesDescription,
269 const ParameterDirection &direction);
270 std::vector<ParameterDescription> parameters;
273 #define HTML_HELP_OPEN() \ 274 "<!DOCTYPE html><html><head>\ 275 <style type=\"text/css\">.body { font-family: \"Segoe UI\", Candara, \"Bitstream Vera Sans\", \"DejaVu Sans\", \"Bitstream Vera Sans\", \"Trebuchet MS\", Verdana, \"Verdana Ref\", sans-serif; }\ 276 .paramtable { width: 100%; border: 0px; border-bottom: 1px solid #C9C9C9; padding: 5px; }\ 277 .help { font-style: italic; font-size: 90%; }\ 278 .b { padding-left: 5px; }</style>\ 279 </head><body><table border=\"0\" class=\"paramtable\">" 281 #define HTML_HELP_DEF(A, B) "<tr><td><b>" A "</b><td class=\"b\">" B "</td></tr>" 283 #define HTML_HELP_BODY() "</table><p class=\"help\">" 285 #define HTML_HELP_CLOSE() "</p></body></html>" 296 struct TLP_SCOPE WithParameter {
303 const tlp::ParameterDescriptionList &getParameters()
const;
317 template <
typename T>
318 void addInParameter(
const std::string &name,
const std::string &help,
319 const std::string &defaultValue,
bool isMandatory =
true,
320 const std::string &valuesDescription = std::string()) {
321 parameters.template add<T>(name, help, defaultValue, isMandatory, IN_PARAM, valuesDescription);
336 template <
typename T>
337 void addOutParameter(
const std::string &name,
const std::string &help = std::string(),
338 const std::string &defaultValue = std::string(),
bool isMandatory =
true,
339 const std::string &valuesDescription = std::string()) {
340 parameters.template add<T>(name, help, defaultValue, isMandatory, OUT_PARAM, valuesDescription);
355 template <
typename T>
356 void addInOutParameter(
const std::string &name,
const std::string &help = std::string(),
357 const std::string &defaultValue = std::string(),
bool isMandatory =
true,
358 const std::string &valuesDescription = std::string()) {
359 parameters.template add<T>(name, help, defaultValue, isMandatory, INOUT_PARAM,
368 bool inputRequired()
const;
374 ParameterDescriptionList parameters;
Interface for Tulip iterators. Allows basic iteration operations only.