Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
TemplateAlgorithm.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 TULIP_PROPERTY_H
21 #define TULIP_PROPERTY_H
22 
23 #include <tulip/Algorithm.h>
24 #include <tulip/Graph.h>
25 
26 #include <sstream>
27 
28 namespace tlp {
29 class PluginContext;
30 static const std::string PROPERTY_ALGORITHM_CATEGORY = "Property";
31 
32 /**
33  * @ingroup Plugins
34  * @brief A non-template interface for tlp::TemplateAlgorithm
35  * @see tlp::TemplateAlgorithm
36  **/
37 class TLP_SCOPE PropertyAlgorithm: public tlp::Algorithm {
38 public :
39  PropertyAlgorithm(const tlp::PluginContext* context):Algorithm(context) {}
40  virtual std::string category() const {
41  return PROPERTY_ALGORITHM_CATEGORY;
42  }
43 };
44 
45 /**
46  * @ingroup Plugins
47  * @brief The TemplateAlgorithm class describes a plugin that can operate on a single graph's property.
48  * @param Property The property template arguments gives the type of the property the algorithm operates on.
49  *
50  * A TemplateAlgorithm takes a graph as input (plus additional parameters defined via tlp::WithParameter) and outputs its results in a tlp::PropertyInterface subclass.
51  * The output property is defined as an output parameter named "result" and as a class member called result.
52  *
53  * @warning Subclassing TemplateAlgorithm is not recommended since template specifications are available for every Tulip property types.
54  *
55  * @see tlp::BooleanAlgorithm
56  * @see tlp::StringAlgorithm
57  * @see tlp::DoubleAlgorithm
58  * @see tlp::IntegerAlgorithm
59  * @see tlp::LayoutAlgorithm
60  * @see tlp::SizeAlgorithm
61  */
62 template<class Property>
63 class TLP_SCOPE TemplateAlgorithm : public PropertyAlgorithm {
64 public:
65  Property* result;
66  TemplateAlgorithm (const tlp::PluginContext* context) : tlp::PropertyAlgorithm(context), result(NULL) {
67  if (dataSet != NULL) {
68  if(!dataSet->exist("result")) {
69  std::stringstream propname;
70  propname << "result";
71  unsigned number = 0;
72 
73  while(graph->existProperty(propname.str())) {
74  propname.clear();
75  propname << "result" << number;
76  ++number;
77  }
78 
79  result = graph->getProperty<Property>(propname.str());
80  }
81  else {
82  dataSet->get("result", result);
83  }
84  }
85  }
86 };
87 
88 
89 }
90 #endif