Tulip  5.1.0
Large graphs analysis and drawing
Graph.cxx
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 #include <tulip/PluginProgress.h>
20 #include <tulip/PropertyInterface.h>
21 
22 //================================================================================
23 template<typename ATTRIBUTETYPE>
24 bool tlp::Graph::getAttribute(const std::string &name, ATTRIBUTETYPE& value) const {
25  return getAttributes().get(name, value);
26 }
27 //================================================================================
28 template<typename ATTRIBUTETYPE>
29 void tlp::Graph::setAttribute(const std::string &name,const ATTRIBUTETYPE&value) {
30  tlp::DataSet &data=getNonConstAttributes();
31  notifyBeforeSetAttribute(name);
32  data.set(name,value);
33  notifyAfterSetAttribute(name);
34 }
35 //================================================================================
36 template<typename PropertyType>
37 PropertyType* tlp::Graph::getLocalProperty(const std::string &name) {
38  if (existLocalProperty(name)) {
39  PropertyInterface* prop = getProperty(name);
40  assert (dynamic_cast<PropertyType *>(prop)!=NULL);
41  return dynamic_cast<PropertyType *>(prop);
42  }
43  else {
44  PropertyType* prop = new PropertyType(this, name);
45  this->addLocalProperty(name, prop);
46  return prop;
47  }
48 }
49 //====================================================================================
50 template<typename PropertyType>
51 PropertyType* tlp::Graph::getProperty(const std::string &name) {
52  if (existProperty(name)) {
53  tlp::PropertyInterface* prop = getProperty(name);
54  assert (dynamic_cast<PropertyType *>(prop)!=NULL);
55  return dynamic_cast<PropertyType *>(prop);
56  }
57  else {
58  return getLocalProperty<PropertyType>(name);
59  }
60 }
PropertyType * getLocalProperty(const std::string &name)
Gets a property on this graph. The name of a property identifies it uniquely. Either there already ex...
Definition: Graph.cxx:37
PropertyInterface describes the interface of a graph property.
void set(const std::string &key, const T &value)
Stores a copy of the given param, associated with the key. The value must have a well-formed copy con...
Definition: DataSet.cxx:52
A container that can store data from any type.
Definition: DataSet.h:190
virtual PropertyInterface * getProperty(const std::string &name) const =0
Gets an existing property. In DEBUG mode an assertion checks the existence of the property...
virtual bool existProperty(const std::string &name) const =0
Checks if a property exists in this graph or one of its ancestors.
virtual bool existLocalProperty(const std::string &name) const =0
Checks if a property exists in this graph.
const DataSet & getAttributes() const
Gets the attributes of the graph.
Definition: Graph.h:1165
void setAttribute(const std::string &name, const ATTRIBUTETYPE &value)
Sets an attribute on the graph.
Definition: Graph.cxx:29
bool get(const std::string &key, T &value) const
Returns the stored value associated with the given key. The stored value is a copy of the original va...
Definition: DataSet.cxx:22
bool getAttribute(const std::string &name, ATTRIBUTETYPE &value) const
Gets an attribute on the graph.
Definition: Graph.cxx:24
virtual void addLocalProperty(const std::string &name, PropertyInterface *prop)=0
Adds a property to the graph. The graph takes ownership of the property. If you want to delete it...