Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 00020 #ifndef TULIP_PROPERTY_H 00021 #define TULIP_PROPERTY_H 00022 00023 #include <tulip/Algorithm.h> 00024 #include <tulip/Graph.h> 00025 00026 #include <sstream> 00027 00028 namespace tlp { 00029 class PluginContext; 00030 static const std::string PROPERTY_ALGORITHM_CATEGORY = "Property"; 00031 00032 /** 00033 * @ingroup Plugins 00034 * @brief A non-template interface for tlp::TemplateAlgorithm 00035 * @see tlp::TemplateAlgorithm 00036 **/ 00037 class TLP_SCOPE PropertyAlgorithm: public tlp::Algorithm { 00038 public : 00039 PropertyAlgorithm(const tlp::PluginContext* context):Algorithm(context) {} 00040 virtual std::string category() const { 00041 return PROPERTY_ALGORITHM_CATEGORY; 00042 } 00043 }; 00044 00045 /** 00046 * @ingroup Plugins 00047 * @brief The TemplateAlgorithm class describes a plugin that can operate on a single graph's property. 00048 * @param Property The property template arguments gives the type of the property the algorithm operates on. 00049 * 00050 * A TemplateAlgorithm takes a graph as input (plus additional parameters defined via tlp::WithParameter) and outputs its results in a tlp::PropertyInterface subclass. 00051 * The output property is defined as an output parameter named "result" and as a class member called result. 00052 * 00053 * @warning Subclassing TemplateAlgorithm is not recommended since template specifications are available for every Tulip property types. 00054 * 00055 * @see tlp::BooleanAlgorithm 00056 * @see tlp::StringAlgorithm 00057 * @see tlp::DoubleAlgorithm 00058 * @see tlp::IntegerAlgorithm 00059 * @see tlp::LayoutAlgorithm 00060 * @see tlp::SizeAlgorithm 00061 */ 00062 template<class Property> 00063 class TLP_SCOPE TemplateAlgorithm : public PropertyAlgorithm { 00064 public: 00065 Property* result; 00066 TemplateAlgorithm (const tlp::PluginContext* context) : tlp::PropertyAlgorithm(context), result(NULL) { 00067 if (dataSet != NULL) { 00068 if(!dataSet->exist("result")) { 00069 std::stringstream propname; 00070 propname << "result"; 00071 unsigned number = 0; 00072 00073 while(graph->existProperty(propname.str())) { 00074 propname.clear(); 00075 propname << "result" << number; 00076 ++number; 00077 } 00078 00079 result = graph->getProperty<Property>(propname.str()); 00080 } 00081 else { 00082 dataSet->get("result", result); 00083 } 00084 } 00085 } 00086 }; 00087 00088 00089 } 00090 #endif