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> 55 template <
class Tnode,
class Tedge,
class Tprop = PropertyInterface>
58 friend class GraphView;
67 typename Tnode::RealType getNodeDefaultValue()
const;
73 typename Tedge::RealType getEdgeDefaultValue()
const;
83 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
84 getNodeValue(
const node n)
const;
94 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue
95 getEdgeValue(
const edge e)
const;
103 getNodesEqualTo(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
104 const Graph *g =
nullptr)
const;
112 getEdgesEqualTo(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
113 const Graph *g =
nullptr)
const;
122 setNodeValue(
const node n,
123 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
132 setEdgeValue(
const edge e,
133 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
144 setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
157 setNodeDefaultValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
178 _DEPRECATED
virtual void 179 setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
199 setValueToGraphNodes(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
213 setEdgeDefaultValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
224 setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
245 _DEPRECATED
virtual void 246 setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
266 setValueToGraphEdges(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
277 setNodeValue(n, nodeDefaultValue);
288 setEdgeValue(e, edgeDefaultValue);
305 if (Tprop::graph ==
nullptr)
306 Tprop::graph = prop.Tprop::graph;
308 if (Tprop::graph == prop.Tprop::graph) {
312 for (
auto itn : prop.getNonDefaultValuatedNodes()) {
316 for (
auto ite : prop.getNonDefaultValuatedEdges()) {
322 for (
auto n : Tprop::graph->nodes()) {
323 if (prop.Tprop::graph->isElement(n))
327 for (
auto e : Tprop::graph->edges()) {
328 if (prop.Tprop::graph->isElement(e))
340 std::string getNodeDefaultStringValue()
const override {
341 typename Tnode::RealType v = getNodeDefaultValue();
342 return Tnode::toString(v);
344 std::string getEdgeDefaultStringValue()
const override {
345 typename Tedge::RealType v = getEdgeDefaultValue();
346 return Tedge::toString(v);
348 std::string getNodeStringValue(
const node n)
const override {
349 typename Tnode::RealType v = getNodeValue(n);
350 return Tnode::toString(v);
352 std::string getEdgeStringValue(
const edge e)
const override {
353 typename Tedge::RealType v = getEdgeValue(e);
354 return Tedge::toString(v);
356 bool setNodeStringValue(
const node inN,
const std::string &inV)
override {
357 typename Tnode::RealType v;
359 if (!Tnode::fromString(v, inV))
362 setNodeValue(inN, v);
365 bool setEdgeStringValue(
const edge inE,
const std::string &inV)
override {
366 typename Tedge::RealType v;
368 if (!Tedge::fromString(v, inV))
371 setEdgeValue(inE, v);
374 bool setNodeDefaultStringValue(
const std::string &inV)
override {
375 typename Tnode::RealType v;
377 if (!Tnode::fromString(v, inV))
380 setNodeDefaultValue(v);
383 bool setAllNodeStringValue(
const std::string &inV)
override {
384 typename Tnode::RealType v;
386 if (!Tnode::fromString(v, inV))
392 _DEPRECATED
bool setAllNodeStringValue(
const std::string &inV,
const Graph *graph)
override {
393 return setStringValueToGraphNodes(inV, graph);
395 bool setStringValueToGraphNodes(
const std::string &inV,
const Graph *graph)
override {
396 typename Tnode::RealType v;
398 if (!Tnode::fromString(v, inV))
401 setValueToGraphNodes(v, graph);
404 bool setEdgeDefaultStringValue(
const std::string &inV)
override {
405 typename Tedge::RealType v;
407 if (!Tedge::fromString(v, inV))
410 setEdgeDefaultValue(v);
413 bool setAllEdgeStringValue(
const std::string &inV)
override {
414 typename Tedge::RealType v;
416 if (!Tedge::fromString(v, inV))
422 _DEPRECATED
bool setAllEdgeStringValue(
const std::string &inV,
const Graph *graph)
override {
423 return setStringValueToGraphEdges(inV, graph);
425 bool setStringValueToGraphEdges(
const std::string &inV,
const Graph *graph)
override {
426 typename Tedge::RealType v;
428 if (!Tedge::fromString(v, inV))
431 setValueToGraphEdges(v, graph);
435 bool hasNonDefaultValuatedNodes(
const Graph *g =
nullptr)
const override;
436 unsigned int numberOfNonDefaultValuatedNodes(
const Graph *g =
nullptr)
const override;
437 unsigned int nodeValueSize()
const override;
438 void writeNodeDefaultValue(std::ostream &)
const override;
439 void writeNodeValue(std::ostream &,
node)
const override;
440 bool readNodeDefaultValue(std::istream &)
override;
441 bool readNodeValue(std::istream &,
node)
override;
443 bool hasNonDefaultValuatedEdges(
const Graph *g =
nullptr)
const override;
444 unsigned int numberOfNonDefaultValuatedEdges(
const Graph * =
nullptr)
const override;
445 unsigned int edgeValueSize()
const override;
446 void writeEdgeDefaultValue(std::ostream &)
const override;
447 void writeEdgeValue(std::ostream &,
edge)
const override;
448 bool readEdgeDefaultValue(std::istream &)
override;
449 bool readEdgeValue(std::istream &,
edge)
override;
451 bool ifNotDefault =
false)
override {
452 if (property ==
nullptr)
459 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
460 tp->nodeProperties.get(source.
id, notDefault);
462 if (ifNotDefault && !notDefault)
465 setNodeValue(destination, value);
469 bool ifNotDefault =
false)
override {
470 if (property ==
nullptr)
477 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
478 tp->edgeProperties.get(source.
id, notDefault);
480 if (ifNotDefault && !notDefault)
483 setEdgeValue(destination, value);
489 assert(prop !=
nullptr);
493 DataMem *getNodeDefaultDataMemValue()
const override {
494 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
496 DataMem *getEdgeDefaultDataMemValue()
const override {
497 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
499 DataMem *getNodeDataMemValue(
const node n)
const override {
500 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
502 DataMem *getEdgeDataMemValue(
const edge e)
const override {
503 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
505 DataMem *getNonDefaultDataMemValue(
const node n)
const override {
507 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
508 nodeProperties.get(n.
id, notDefault);
511 return new TypedValueContainer<typename Tnode::RealType>(value);
515 DataMem *getNonDefaultDataMemValue(
const edge e)
const override {
517 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
518 edgeProperties.get(e.
id, notDefault);
521 return new TypedValueContainer<typename Tedge::RealType>(value);
525 void setNodeDataMemValue(
const node n,
const DataMem *v)
override {
526 setNodeValue(n,
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
528 void setEdgeDataMemValue(
const edge e,
const DataMem *v)
override {
529 setEdgeValue(e,
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
531 void setAllNodeDataMemValue(
const DataMem *v)
override {
532 setAllNodeValue(
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
534 void setAllEdgeDataMemValue(
const DataMem *v)
override {
535 setAllEdgeValue(
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
542 if (Tprop::metaValueCalculator)
544 Tprop::metaValueCalculator)
545 ->computeMetaValue(
this, n, sg, mg);
550 if (Tprop::metaValueCalculator)
552 Tprop::metaValueCalculator)
553 ->computeMetaValue(
this, e, itE, mg);
560 <<
"Warning : " << __PRETTY_FUNCTION__ <<
" ... invalid conversion of " 561 <<
typeid(mvCalc).name() <<
"into " 568 Tprop::metaValueCalculator = mvCalc;
571 int compare(
const node n1,
const node n2)
const override;
572 int compare(
const edge e1,
const edge e2)
const override;
598 MutableContainer<typename Tnode::RealType> nodeProperties;
599 MutableContainer<typename Tedge::RealType> edgeProperties;
600 typename Tnode::RealType nodeDefaultValue;
601 typename Tedge::RealType edgeDefaultValue;
604 template <
typename vectType,
typename eltType,
typename propType = VectorPropertyInterface>
605 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
607 AbstractVectorProperty(
Graph *,
const std::string &name =
"");
610 bool tokenize(
const std::string &str, std::vector<std::string> &vect,
char openChar =
'(',
611 char sepChar =
',',
char closeChar =
')')
override;
613 bool setNodeStringValueAsVector(
const node n,
const std::vector<std::string> &values)
override;
615 bool setNodeStringValueAsVector(
const node,
const std::string &,
char,
char,
char)
override;
617 bool setEdgeStringValueAsVector(
const edge e,
const std::vector<std::string> &values)
override;
619 bool setEdgeStringValueAsVector(
const edge,
const std::string &,
char,
char,
char)
override;
629 void setNodeEltValue(
const node n,
unsigned int i,
630 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
638 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
639 getNodeEltValue(
const node n,
unsigned int i)
const;
649 pushBackNodeEltValue(
const node n,
650 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
658 void popBackNodeEltValue(
const node n);
668 void resizeNodeValue(
const node n,
size_t size,
669 typename eltType::RealType elt = eltType::defaultValue());
678 void setEdgeEltValue(
const edge e,
unsigned int i,
679 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
687 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
688 getEdgeEltValue(
const edge n,
unsigned int i)
const;
698 pushBackEdgeEltValue(
const edge e,
699 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
707 void popBackEdgeEltValue(
const edge e);
717 void resizeEdgeValue(
const edge e,
size_t size,
718 typename eltType::RealType elt = eltType::defaultValue());
721 #if !defined(_MSC_VER) || defined(DLL_TULIP) // When using VC++, we only want to include this when 724 #include "cxx/AbstractProperty.cxx" void erase(const edge e) override
Resets the value of an edge to the default value.
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
Tedge::RealType getEdgeDefaultValue() const
Gets the default edge value of the property.
Interface for Tulip iterators. Allows basic iteration operations only.
PropertyInterface describes the interface of a graph property.
virtual AbstractProperty< Tnode, Tedge, Tprop > & operator=(AbstractProperty< Tnode, Tedge, Tprop > &prop)
This operator overload allows to copy a property using the following syntax :
Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
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.
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.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
void erase(const node n) override
Resets the value of a node to the default value.
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.