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/DataSet.h> 32 #include <tulip/Graph.h> 54 template <
class Tnode,
class Tedge,
class Tprop = PropertyInterface>
57 friend class GraphView;
66 typename Tnode::RealType getNodeDefaultValue()
const;
72 typename Tedge::RealType getEdgeDefaultValue()
const;
82 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
83 getNodeValue(
const node n)
const;
93 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue
94 getEdgeValue(
const edge e)
const;
102 getNodesEqualTo(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
103 const Graph *g =
nullptr)
const;
111 getEdgesEqualTo(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
112 const Graph *g =
nullptr)
const;
121 setNodeValue(
const node n,
122 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
131 setEdgeValue(
const edge e,
132 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
143 setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
156 setNodeDefaultValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
177 _DEPRECATED
virtual void 178 setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
198 setValueToGraphNodes(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
212 setEdgeDefaultValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
223 setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
244 _DEPRECATED
virtual void 245 setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
265 setValueToGraphEdges(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
276 setNodeValue(n, nodeDefaultValue);
287 setEdgeValue(e, edgeDefaultValue);
304 if (Tprop::graph ==
nullptr)
305 Tprop::graph = prop.Tprop::graph;
307 if (Tprop::graph == prop.Tprop::graph) {
311 for (
auto itn : prop.getNonDefaultValuatedNodes()) {
315 for (
auto ite : prop.getNonDefaultValuatedEdges()) {
321 for (
auto n : Tprop::graph->nodes()) {
322 if (prop.Tprop::graph->isElement(n))
326 for (
auto e : Tprop::graph->edges()) {
327 if (prop.Tprop::graph->isElement(e))
339 std::string getNodeDefaultStringValue()
const override {
340 typename Tnode::RealType v = getNodeDefaultValue();
341 return Tnode::toString(v);
343 std::string getEdgeDefaultStringValue()
const override {
344 typename Tedge::RealType v = getEdgeDefaultValue();
345 return Tedge::toString(v);
347 std::string getNodeStringValue(
const node n)
const override {
348 typename Tnode::RealType v = getNodeValue(n);
349 return Tnode::toString(v);
351 std::string getEdgeStringValue(
const edge e)
const override {
352 typename Tedge::RealType v = getEdgeValue(e);
353 return Tedge::toString(v);
355 bool setNodeStringValue(
const node inN,
const std::string &inV)
override {
356 typename Tnode::RealType v;
358 if (!Tnode::fromString(v, inV))
361 setNodeValue(inN, v);
364 bool setEdgeStringValue(
const edge inE,
const std::string &inV)
override {
365 typename Tedge::RealType v;
367 if (!Tedge::fromString(v, inV))
370 setEdgeValue(inE, v);
373 bool setNodeDefaultStringValue(
const std::string &inV)
override {
374 typename Tnode::RealType v;
376 if (!Tnode::fromString(v, inV))
379 setNodeDefaultValue(v);
382 bool setAllNodeStringValue(
const std::string &inV)
override {
383 typename Tnode::RealType v;
385 if (!Tnode::fromString(v, inV))
391 _DEPRECATED
bool setAllNodeStringValue(
const std::string &inV,
const Graph *graph)
override {
392 return setStringValueToGraphNodes(inV, graph);
394 bool setStringValueToGraphNodes(
const std::string &inV,
const Graph *graph)
override {
395 typename Tnode::RealType v;
397 if (!Tnode::fromString(v, inV))
400 setValueToGraphNodes(v, graph);
403 bool setEdgeDefaultStringValue(
const std::string &inV)
override {
404 typename Tedge::RealType v;
406 if (!Tedge::fromString(v, inV))
409 setEdgeDefaultValue(v);
412 bool setAllEdgeStringValue(
const std::string &inV)
override {
413 typename Tedge::RealType v;
415 if (!Tedge::fromString(v, inV))
421 _DEPRECATED
bool setAllEdgeStringValue(
const std::string &inV,
const Graph *graph)
override {
422 return setStringValueToGraphEdges(inV, graph);
424 bool setStringValueToGraphEdges(
const std::string &inV,
const Graph *graph)
override {
425 typename Tedge::RealType v;
427 if (!Tedge::fromString(v, inV))
430 setValueToGraphEdges(v, graph);
434 bool hasNonDefaultValuatedNodes(
const Graph *g =
nullptr)
const override;
435 unsigned int numberOfNonDefaultValuatedNodes(
const Graph *g =
nullptr)
const override;
436 unsigned int nodeValueSize()
const override;
437 void writeNodeDefaultValue(std::ostream &)
const override;
438 void writeNodeValue(std::ostream &,
node)
const override;
439 bool readNodeDefaultValue(std::istream &)
override;
440 bool readNodeValue(std::istream &,
node)
override;
442 bool hasNonDefaultValuatedEdges(
const Graph *g =
nullptr)
const override;
443 unsigned int numberOfNonDefaultValuatedEdges(
const Graph * =
nullptr)
const override;
444 unsigned int edgeValueSize()
const override;
445 void writeEdgeDefaultValue(std::ostream &)
const override;
446 void writeEdgeValue(std::ostream &,
edge)
const override;
447 bool readEdgeDefaultValue(std::istream &)
override;
448 bool readEdgeValue(std::istream &,
edge)
override;
450 bool ifNotDefault =
false)
override {
451 if (property ==
nullptr)
458 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
459 tp->nodeProperties.get(source.
id, notDefault);
461 if (ifNotDefault && !notDefault)
464 setNodeValue(destination, value);
468 bool ifNotDefault =
false)
override {
469 if (property ==
nullptr)
476 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
477 tp->edgeProperties.get(source.
id, notDefault);
479 if (ifNotDefault && !notDefault)
482 setEdgeValue(destination, value);
488 assert(prop !=
nullptr);
492 DataMem *getNodeDefaultDataMemValue()
const override {
493 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
495 DataMem *getEdgeDefaultDataMemValue()
const override {
496 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
498 DataMem *getNodeDataMemValue(
const node n)
const override {
499 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
501 DataMem *getEdgeDataMemValue(
const edge e)
const override {
502 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
504 DataMem *getNonDefaultDataMemValue(
const node n)
const override {
506 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
507 nodeProperties.get(n.
id, notDefault);
510 return new TypedValueContainer<typename Tnode::RealType>(value);
514 DataMem *getNonDefaultDataMemValue(
const edge e)
const override {
516 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
517 edgeProperties.get(e.
id, notDefault);
520 return new TypedValueContainer<typename Tedge::RealType>(value);
524 void setNodeDataMemValue(
const node n,
const DataMem *v)
override {
525 setNodeValue(n,
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
527 void setEdgeDataMemValue(
const edge e,
const DataMem *v)
override {
528 setEdgeValue(e,
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
530 void setAllNodeDataMemValue(
const DataMem *v)
override {
531 setAllNodeValue(
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
533 void setAllEdgeDataMemValue(
const DataMem *v)
override {
534 setAllEdgeValue(
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
541 if (Tprop::metaValueCalculator)
543 Tprop::metaValueCalculator)
544 ->computeMetaValue(
this, n, sg, mg);
549 if (Tprop::metaValueCalculator)
551 Tprop::metaValueCalculator)
552 ->computeMetaValue(
this, e, itE, mg);
559 <<
"Warning : " << __PRETTY_FUNCTION__ <<
" ... invalid conversion of " 560 <<
typeid(mvCalc).name() <<
"into " 567 Tprop::metaValueCalculator = mvCalc;
570 int compare(
const node n1,
const node n2)
const override;
571 int compare(
const edge e1,
const edge e2)
const override;
597 MutableContainer<typename Tnode::RealType> nodeProperties;
598 MutableContainer<typename Tedge::RealType> edgeProperties;
599 typename Tnode::RealType nodeDefaultValue;
600 typename Tedge::RealType edgeDefaultValue;
603 template <
typename vectType,
typename eltType,
typename propType = VectorPropertyInterface>
604 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
606 AbstractVectorProperty(
Graph *,
const std::string &name =
"");
609 bool tokenize(
const std::string &str, std::vector<std::string> &vect,
char openChar =
'(',
610 char sepChar =
',',
char closeChar =
')')
override;
612 bool setNodeStringValueAsVector(
const node n,
const std::vector<std::string> &values)
override;
614 bool setNodeStringValueAsVector(
const node,
const std::string &,
char,
char,
char)
override;
616 bool setEdgeStringValueAsVector(
const edge e,
const std::vector<std::string> &values)
override;
618 bool setEdgeStringValueAsVector(
const edge,
const std::string &,
char,
char,
char)
override;
628 void setNodeEltValue(
const node n,
unsigned int i,
629 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
637 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
638 getNodeEltValue(
const node n,
unsigned int i)
const;
648 pushBackNodeEltValue(
const node n,
649 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
657 void popBackNodeEltValue(
const node n);
667 void resizeNodeValue(
const node n,
size_t size,
668 typename eltType::RealType elt = eltType::defaultValue());
677 void setEdgeEltValue(
const edge e,
unsigned int i,
678 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
686 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
687 getEdgeEltValue(
const edge n,
unsigned int i)
const;
697 pushBackEdgeEltValue(
const edge e,
698 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
706 void popBackEdgeEltValue(
const edge e);
716 void resizeEdgeValue(
const edge e,
size_t size,
717 typename eltType::RealType elt = eltType::defaultValue());
720 #if !defined(_MSC_VER) || defined(DLL_TULIP) // When using VC++, we only want to include this when 723 #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.