20 #ifndef ABSTRACT_PROPERTY_H 21 #define ABSTRACT_PROPERTY_H 26 #include <tulip/tulipconf.h> 27 #include <tulip/StoredType.h> 28 #include <tulip/MutableContainer.h> 29 #include <tulip/PropertyInterface.h> 30 #include <tulip/Iterator.h> 31 #include <tulip/PropertyAlgorithm.h> 32 #include <tulip/DataSet.h> 33 #include <tulip/Graph.h> 53 template <
class Tnode,
class Tedge,
class Tprop=PropertyInterface>
56 friend class GraphView;
65 virtual typename Tnode::RealType getNodeDefaultValue()
const;
71 virtual typename Tedge::RealType getEdgeDefaultValue()
const;
80 virtual typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue getNodeValue(
const node n )
const;
89 virtual typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue getEdgeValue(
const edge e)
const;
97 virtual void setNodeValue(
const node n,
const typename Tnode::RealType &v);
105 virtual void setEdgeValue(
const edge e,
const typename Tedge::RealType &v);
118 virtual void setAllNodeValue(
const typename Tnode::RealType &v,
const Graph *graph = NULL);
131 virtual void setAllEdgeValue(
const typename Tedge::RealType &v,
const Graph *graph = NULL);
141 setNodeValue(n, nodeDefaultValue);
152 setEdgeValue(e, edgeDefaultValue);
168 if (Tprop::graph == NULL) Tprop::graph = prop.Tprop::graph;
170 if (Tprop::graph == prop.Tprop::graph) {
173 Iterator<node> *itN = prop.getNonDefaultValuatedNodes();
175 while (itN->hasNext()) {
176 node itn = itN->next();
181 Iterator<edge> *itE = prop.getNonDefaultValuatedEdges();
183 while (itE->hasNext()) {
184 edge ite = itE->next();
192 Iterator<node>* itN = Tprop::graph->getNodes();
194 while (itN->hasNext()) {
195 node itn=itN->next();
197 if (prop.Tprop::graph->isElement(itn))
202 Iterator<edge>*itE = Tprop::graph->getEdges();
204 while (itE->hasNext()) {
205 edge ite=itE->next();
207 if (prop.Tprop::graph->isElement(ite))
221 virtual std::string getNodeDefaultStringValue()
const {
222 typename Tnode::RealType v = getNodeDefaultValue();
223 return Tnode::toString( v );
225 virtual std::string getEdgeDefaultStringValue()
const {
226 typename Tedge::RealType v = getEdgeDefaultValue();
227 return Tedge::toString( v );
229 virtual std::string getNodeStringValue(
const node n )
const {
230 typename Tnode::RealType v = getNodeValue( n );
231 return Tnode::toString( v );
233 virtual std::string getEdgeStringValue(
const edge e )
const {
234 typename Tedge::RealType v = getEdgeValue( e );
235 return Tedge::toString( v );
237 virtual bool setNodeStringValue(
const node inN,
const std::string & inV ) {
238 typename Tnode::RealType v;
240 if( !Tnode::fromString(v,inV) )
243 setNodeValue( inN, v );
246 virtual bool setEdgeStringValue(
const edge inE,
const std::string & inV ) {
247 typename Tedge::RealType v;
249 if( !Tedge::fromString(v,inV) )
252 setEdgeValue( inE, v );
255 virtual bool setAllNodeStringValue(
const std::string & inV ,
const Graph *graph = NULL ) {
256 typename Tnode::RealType v;
258 if( !Tnode::fromString(v,inV) )
261 setAllNodeValue( v , graph );
264 virtual bool setAllEdgeStringValue(
const std::string & inV ,
const Graph *graph = NULL ) {
265 typename Tedge::RealType v;
267 if( !Tedge::fromString(v,inV) )
270 setAllEdgeValue( v , graph );
273 virtual tlp::Iterator<node>* getNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
274 virtual unsigned int numberOfNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
275 virtual unsigned int nodeValueSize()
const;
276 virtual void writeNodeDefaultValue(std::ostream&)
const;
277 virtual void writeNodeValue(std::ostream&,
node)
const;
278 virtual bool readNodeDefaultValue(std::istream&);
279 virtual bool readNodeValue(std::istream&,
node);
280 virtual tlp::Iterator<edge>* getNonDefaultValuatedEdges(
const Graph* g = NULL)
const;
281 virtual unsigned int numberOfNonDefaultValuatedEdges(
const Graph* = NULL)
const;
282 virtual unsigned int edgeValueSize()
const;
283 virtual void writeEdgeDefaultValue(std::ostream&)
const;
284 virtual void writeEdgeValue(std::ostream&,
edge)
const;
285 virtual bool readEdgeDefaultValue(std::istream&);
286 virtual bool readEdgeValue(std::istream&,
edge);
288 bool ifNotDefault =
false) {
289 if (property == NULL)
296 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
297 tp->nodeProperties.get(source.
id, notDefault);
299 if (ifNotDefault && !notDefault)
302 setNodeValue(destination, value);
306 bool ifNotDefault =
false) {
307 if (property == NULL)
314 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
315 tp->edgeProperties.get(source.
id, notDefault);
317 if (ifNotDefault && !notDefault)
320 setEdgeValue(destination, value);
326 assert(prop != NULL);
330 virtual DataMem* getNodeDefaultDataMemValue()
const {
331 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
333 virtual DataMem* getEdgeDefaultDataMemValue()
const {
334 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
336 virtual DataMem* getNodeDataMemValue(
const node n)
const {
337 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
339 virtual DataMem* getEdgeDataMemValue(
const edge e)
const {
340 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
342 virtual DataMem* getNonDefaultDataMemValue(
const node n )
const {
344 typename StoredType<typename Tnode::RealType>::ReturnedValue value = nodeProperties.get(n.
id, notDefault);
347 return new TypedValueContainer<typename Tnode::RealType>(value);
351 virtual DataMem* getNonDefaultDataMemValue(
const edge e )
const {
353 typename StoredType<typename Tedge::RealType>::ReturnedValue value = edgeProperties.get(e.
id, notDefault);
356 return new TypedValueContainer<typename Tedge::RealType>(value);
360 virtual void setNodeDataMemValue(
const node n,
const DataMem* v) {
361 setNodeValue(n, ((TypedValueContainer<typename Tnode::RealType> *) v)->value);
363 virtual void setEdgeDataMemValue(
const edge e,
const DataMem* v) {
364 setEdgeValue(e, ((TypedValueContainer<typename Tedge::RealType> *) v)->value);
366 virtual void setAllNodeDataMemValue(
const DataMem* v) {
367 setAllNodeValue(((TypedValueContainer<typename Tnode::RealType> *) v)->value);
369 virtual void setAllEdgeDataMemValue(
const DataMem* v) {
370 setAllEdgeValue(((TypedValueContainer<typename Tedge::RealType> *) v)->value);
376 virtual void computeMetaValue(
node n,
const Graph* sg,
const Graph* mg) {
377 if (Tprop::metaValueCalculator)
379 Tprop::metaValueCalculator)->computeMetaValue(
this, n, sg, mg);
383 virtual void computeMetaValue(
edge e, tlp::Iterator<edge>* itE,
const Graph* mg) {
384 if (Tprop::metaValueCalculator)
393 Tprop::metaValueCalculator = mvCalc;
396 int compare(
const node n1,
const node n2)
const;
397 int compare(
const edge e1,
const edge e2)
const;
416 edge, tlp::Iterator<edge>*,
425 MutableContainer<typename Tnode::RealType> nodeProperties;
426 MutableContainer<typename Tedge::RealType> edgeProperties;
427 typename Tnode::RealType nodeDefaultValue;
428 typename Tedge::RealType edgeDefaultValue;
431 template <
typename vectType,
typename eltType,
typename propType=VectorPropertyInterface>
432 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
434 AbstractVectorProperty(
Graph *,
const std::string& name =
"");
437 bool setNodeStringValueAsVector(
const node,
const std::string&,
440 bool setEdgeStringValueAsVector(
const edge,
const std::string&,
451 void setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
459 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getNodeEltValue(
const node n,
unsigned int i)
const;
467 void pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
474 void popBackNodeEltValue(
const node n);
483 void resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
492 void setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
500 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getEdgeEltValue(
const edge n,
unsigned int i)
const;
508 void pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
515 void popBackEdgeEltValue(
const edge e);
524 void resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
529 #if !defined(_MSC_VER) || defined(DLL_TULIP) //When using VC++, we only want to include this when we are in the TULIP dll. With any other compiler, include it all the time 530 # include "cxx/AbstractProperty.cxx" This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
virtual tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue getNodeValue(const node n) const
Returns the value associated with the node n in this property. If there is no value, it returns the default node value.
PropertyInterface describes the interface of a graph property.
virtual void erase(const edge e)
Resets the value of an edge to the default value.
virtual Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
virtual void erase(const node n)
Resets the value of a node to the default value.
virtual tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue getEdgeValue(const edge e) const
Returns the value associated to the edge e in this property. If there is no value, it returns the default edge value.
virtual Tedge::RealType getEdgeDefaultValue() const
Gets the default edge value of the property.
virtual void clone_handler(AbstractProperty< Tnode, Tedge, Tprop > &)
Enable to clone part of sub_class.
unsigned int id
id The identifier of the node.
unsigned int id
id The identifier of the edge.