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 typename Tnode::RealType getNodeDefaultValue()
const;
71 typename Tedge::RealType getEdgeDefaultValue()
const;
80 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue getNodeValue(
const node n )
const;
89 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue getEdgeValue(
const edge e)
const;
96 virtual tlp::Iterator<node> *getNodesEqualTo(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
const Graph *g = NULL)
const;
103 virtual tlp::Iterator<edge> *getEdgesEqualTo(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
const Graph *g = NULL)
const;
111 virtual void setNodeValue(
const node n,
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
119 virtual void setEdgeValue(
const edge e,
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
128 virtual void setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
139 virtual void setNodeDefaultValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
158 _DEPRECATED
virtual void setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
const Graph *graph);
175 virtual void setValueToGraphNodes(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
const Graph *graph);
186 virtual void setEdgeDefaultValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
195 virtual void setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
214 _DEPRECATED
virtual void setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
const Graph *graph);
231 virtual void setValueToGraphEdges(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
const Graph *graph);
241 setNodeValue(n, nodeDefaultValue);
252 setEdgeValue(e, edgeDefaultValue);
268 if (Tprop::graph == NULL) Tprop::graph = prop.Tprop::graph;
270 if (Tprop::graph == prop.Tprop::graph) {
273 Iterator<node> *itN = prop.getNonDefaultValuatedNodes();
275 while (itN->hasNext()) {
276 node itn = itN->next();
281 Iterator<edge> *itE = prop.getNonDefaultValuatedEdges();
283 while (itE->hasNext()) {
284 edge ite = itE->next();
292 const std::vector<node>& nodes = Tprop::graph->nodes();
293 unsigned int nbElts = nodes.size();
295 for(
unsigned int i = 0; i < nbElts; ++i) {
298 if (prop.Tprop::graph->isElement(n))
302 const std::vector<edge>& edges = Tprop::graph->edges();
303 nbElts = edges.size();
305 for(
unsigned int i = 0; i < nbElts; ++i) {
308 if (prop.Tprop::graph->isElement(e))
320 virtual std::string getNodeDefaultStringValue()
const {
321 typename Tnode::RealType v = getNodeDefaultValue();
322 return Tnode::toString( v );
324 virtual std::string getEdgeDefaultStringValue()
const {
325 typename Tedge::RealType v = getEdgeDefaultValue();
326 return Tedge::toString( v );
328 virtual std::string getNodeStringValue(
const node n )
const {
329 typename Tnode::RealType v = getNodeValue( n );
330 return Tnode::toString( v );
332 virtual std::string getEdgeStringValue(
const edge e )
const {
333 typename Tedge::RealType v = getEdgeValue( e );
334 return Tedge::toString( v );
336 virtual bool setNodeStringValue(
const node inN,
const std::string & inV ) {
337 typename Tnode::RealType v;
339 if( !Tnode::fromString( v, inV ) )
342 setNodeValue( inN, v );
345 virtual bool setEdgeStringValue(
const edge inE,
const std::string & inV ) {
346 typename Tedge::RealType v;
348 if( !Tedge::fromString( v, inV ) )
351 setEdgeValue( inE, v );
354 virtual bool setNodeDefaultStringValue(
const std::string & inV ) {
355 typename Tnode::RealType v;
357 if( !Tnode::fromString( v, inV ) )
360 setNodeDefaultValue( v );
363 virtual bool setAllNodeStringValue(
const std::string & inV ) {
364 typename Tnode::RealType v;
366 if( !Tnode::fromString( v, inV ) )
369 setAllNodeValue( v );
372 _DEPRECATED
virtual bool setAllNodeStringValue(
const std::string & inV ,
const Graph *graph ) {
373 return setStringValueToGraphNodes(inV, graph);
375 virtual bool setStringValueToGraphNodes(
const std::string & inV ,
const Graph *graph ) {
376 typename Tnode::RealType v;
378 if( !Tnode::fromString( v, inV ) )
381 setValueToGraphNodes( v , graph );
384 virtual bool setEdgeDefaultStringValue(
const std::string & inV ) {
385 typename Tedge::RealType v;
387 if( !Tedge::fromString(v ,inV ) )
390 setEdgeDefaultValue( v );
393 virtual bool setAllEdgeStringValue(
const std::string & inV ) {
394 typename Tedge::RealType v;
396 if( !Tedge::fromString(v ,inV ) )
399 setAllEdgeValue( v );
402 _DEPRECATED
virtual bool setAllEdgeStringValue(
const std::string & inV ,
const Graph *graph ) {
403 return setStringValueToGraphEdges(inV, graph);
405 virtual bool setStringValueToGraphEdges(
const std::string & inV ,
const Graph *graph ) {
406 typename Tedge::RealType v;
408 if( !Tedge::fromString(v,inV) )
411 setValueToGraphEdges( v , graph );
414 virtual tlp::Iterator<node>* getNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
415 virtual unsigned int numberOfNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
416 virtual unsigned int nodeValueSize()
const;
417 virtual void writeNodeDefaultValue(std::ostream&)
const;
418 virtual void writeNodeValue(std::ostream&,
node)
const;
419 virtual bool readNodeDefaultValue(std::istream&);
420 virtual bool readNodeValue(std::istream&,
node);
421 virtual tlp::Iterator<edge>* getNonDefaultValuatedEdges(
const Graph* g = NULL)
const;
422 virtual unsigned int numberOfNonDefaultValuatedEdges(
const Graph* = NULL)
const;
423 virtual unsigned int edgeValueSize()
const;
424 virtual void writeEdgeDefaultValue(std::ostream&)
const;
425 virtual void writeEdgeValue(std::ostream&,
edge)
const;
426 virtual bool readEdgeDefaultValue(std::istream&);
427 virtual bool readEdgeValue(std::istream&,
edge);
429 bool ifNotDefault =
false) {
430 if (property == NULL)
437 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
438 tp->nodeProperties.get(source.
id, notDefault);
440 if (ifNotDefault && !notDefault)
443 setNodeValue(destination, value);
447 bool ifNotDefault =
false) {
448 if (property == NULL)
455 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
456 tp->edgeProperties.get(source.
id, notDefault);
458 if (ifNotDefault && !notDefault)
461 setEdgeValue(destination, value);
467 assert(prop != NULL);
471 virtual DataMem* getNodeDefaultDataMemValue()
const {
472 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
474 virtual DataMem* getEdgeDefaultDataMemValue()
const {
475 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
477 virtual DataMem* getNodeDataMemValue(
const node n)
const {
478 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
480 virtual DataMem* getEdgeDataMemValue(
const edge e)
const {
481 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
483 virtual DataMem* getNonDefaultDataMemValue(
const node n )
const {
485 typename StoredType<typename Tnode::RealType>::ReturnedValue value = nodeProperties.get(n.
id, notDefault);
488 return new TypedValueContainer<typename Tnode::RealType>(value);
492 virtual DataMem* getNonDefaultDataMemValue(
const edge e )
const {
494 typename StoredType<typename Tedge::RealType>::ReturnedValue value = edgeProperties.get(e.
id, notDefault);
497 return new TypedValueContainer<typename Tedge::RealType>(value);
501 virtual void setNodeDataMemValue(
const node n,
const DataMem* v) {
502 setNodeValue(n, ((TypedValueContainer<typename Tnode::RealType> *) v)->value);
504 virtual void setEdgeDataMemValue(
const edge e,
const DataMem* v) {
505 setEdgeValue(e, ((TypedValueContainer<typename Tedge::RealType> *) v)->value);
507 virtual void setAllNodeDataMemValue(
const DataMem* v) {
508 setAllNodeValue(((TypedValueContainer<typename Tnode::RealType> *) v)->value);
510 virtual void setAllEdgeDataMemValue(
const DataMem* v) {
511 setAllEdgeValue(((TypedValueContainer<typename Tedge::RealType> *) v)->value);
518 if (Tprop::metaValueCalculator)
520 Tprop::metaValueCalculator)->computeMetaValue(
this, n, sg, mg);
524 virtual void computeMetaValue(
edge e, tlp::Iterator<edge>* itE,
Graph* mg) {
525 if (Tprop::metaValueCalculator)
534 Tprop::metaValueCalculator = mvCalc;
537 int compare(
const node n1,
const node n2)
const;
538 int compare(
const edge e1,
const edge e2)
const;
564 MutableContainer<typename Tnode::RealType> nodeProperties;
565 MutableContainer<typename Tedge::RealType> edgeProperties;
566 typename Tnode::RealType nodeDefaultValue;
567 typename Tedge::RealType edgeDefaultValue;
570 template <
typename vectType,
typename eltType,
typename propType=VectorPropertyInterface>
571 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
573 AbstractVectorProperty(
Graph *,
const std::string& name =
"");
576 bool setNodeStringValueAsVector(
const node,
const std::string&,
579 bool setEdgeStringValueAsVector(
const edge,
const std::string&,
590 void setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
598 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getNodeEltValue(
const node n,
unsigned int i)
const;
606 void pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
613 void popBackNodeEltValue(
const node n);
622 void resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
631 void setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
639 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getEdgeEltValue(
const edge n,
unsigned int i)
const;
647 void pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
654 void popBackEdgeEltValue(
const edge e);
663 void resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
668 #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 669 # include "cxx/AbstractProperty.cxx" This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
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.
Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
void erase(const edge e)
Resets the value of an edge to the default value.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
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.
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.
virtual AbstractProperty< Tnode, Tedge, Tprop > & operator=(AbstractProperty< Tnode, Tedge, Tprop > &prop)
This operator overload allows to copy a property using the following syntax :
void erase(const node n)
Resets the value of a node to the default value.
unsigned int id
id The identifier of the edge.