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);
175 setValueToGraphNodes(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
189 setEdgeDefaultValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
200 setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
219 setValueToGraphEdges(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
230 setNodeValue(n, nodeDefaultValue);
241 setEdgeValue(e, edgeDefaultValue);
258 if (Tprop::graph ==
nullptr)
259 Tprop::graph = prop.Tprop::graph;
261 if (Tprop::graph == prop.Tprop::graph) {
265 for (
auto itn : prop.getNonDefaultValuatedNodes()) {
269 for (
auto ite : prop.getNonDefaultValuatedEdges()) {
275 for (
auto n : Tprop::graph->nodes()) {
276 if (prop.Tprop::graph->isElement(n))
280 for (
auto e : Tprop::graph->edges()) {
281 if (prop.Tprop::graph->isElement(e))
293 std::string getNodeDefaultStringValue()
const override {
294 typename Tnode::RealType v = getNodeDefaultValue();
295 return Tnode::toString(v);
297 std::string getEdgeDefaultStringValue()
const override {
298 typename Tedge::RealType v = getEdgeDefaultValue();
299 return Tedge::toString(v);
301 std::string getNodeStringValue(
const node n)
const override {
302 typename Tnode::RealType v = getNodeValue(n);
303 return Tnode::toString(v);
305 std::string getEdgeStringValue(
const edge e)
const override {
306 typename Tedge::RealType v = getEdgeValue(e);
307 return Tedge::toString(v);
309 bool setNodeStringValue(
const node inN,
const std::string &inV)
override {
310 typename Tnode::RealType v;
312 if (!Tnode::fromString(v, inV))
315 setNodeValue(inN, v);
318 bool setEdgeStringValue(
const edge inE,
const std::string &inV)
override {
319 typename Tedge::RealType v;
321 if (!Tedge::fromString(v, inV))
324 setEdgeValue(inE, v);
327 bool setNodeDefaultStringValue(
const std::string &inV)
override {
328 typename Tnode::RealType v;
330 if (!Tnode::fromString(v, inV))
333 setNodeDefaultValue(v);
336 bool setAllNodeStringValue(
const std::string &inV)
override {
337 typename Tnode::RealType v;
339 if (!Tnode::fromString(v, inV))
345 bool setStringValueToGraphNodes(
const std::string &inV,
const Graph *graph)
override {
346 typename Tnode::RealType v;
348 if (!Tnode::fromString(v, inV))
351 setValueToGraphNodes(v, graph);
354 bool setEdgeDefaultStringValue(
const std::string &inV)
override {
355 typename Tedge::RealType v;
357 if (!Tedge::fromString(v, inV))
360 setEdgeDefaultValue(v);
363 bool setAllEdgeStringValue(
const std::string &inV)
override {
364 typename Tedge::RealType v;
366 if (!Tedge::fromString(v, inV))
372 bool setStringValueToGraphEdges(
const std::string &inV,
const Graph *graph)
override {
373 typename Tedge::RealType v;
375 if (!Tedge::fromString(v, inV))
378 setValueToGraphEdges(v, graph);
382 bool hasNonDefaultValuatedNodes(
const Graph *g =
nullptr)
const override;
383 unsigned int numberOfNonDefaultValuatedNodes(
const Graph *g =
nullptr)
const override;
384 unsigned int nodeValueSize()
const override;
385 void writeNodeDefaultValue(std::ostream &)
const override;
386 void writeNodeValue(std::ostream &,
node)
const override;
387 bool readNodeDefaultValue(std::istream &)
override;
388 bool readNodeValue(std::istream &,
node)
override;
390 bool hasNonDefaultValuatedEdges(
const Graph *g =
nullptr)
const override;
391 unsigned int numberOfNonDefaultValuatedEdges(
const Graph * =
nullptr)
const override;
392 unsigned int edgeValueSize()
const override;
393 void writeEdgeDefaultValue(std::ostream &)
const override;
394 void writeEdgeValue(std::ostream &,
edge)
const override;
395 bool readEdgeDefaultValue(std::istream &)
override;
396 bool readEdgeValue(std::istream &,
edge)
override;
398 bool ifNotDefault =
false)
override {
399 if (property ==
nullptr)
406 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
407 tp->nodeProperties.get(source.
id, notDefault);
409 if (ifNotDefault && !notDefault)
412 setNodeValue(destination, value);
416 bool ifNotDefault =
false)
override {
417 if (property ==
nullptr)
424 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
425 tp->edgeProperties.get(source.
id, notDefault);
427 if (ifNotDefault && !notDefault)
430 setEdgeValue(destination, value);
436 assert(prop !=
nullptr);
440 DataMem *getNodeDefaultDataMemValue()
const override {
441 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
443 DataMem *getEdgeDefaultDataMemValue()
const override {
444 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
446 DataMem *getNodeDataMemValue(
const node n)
const override {
447 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
449 DataMem *getEdgeDataMemValue(
const edge e)
const override {
450 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
452 DataMem *getNonDefaultDataMemValue(
const node n)
const override {
454 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
455 nodeProperties.get(n.
id, notDefault);
458 return new TypedValueContainer<typename Tnode::RealType>(value);
462 DataMem *getNonDefaultDataMemValue(
const edge e)
const override {
464 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
465 edgeProperties.get(e.
id, notDefault);
468 return new TypedValueContainer<typename Tedge::RealType>(value);
472 void setNodeDataMemValue(
const node n,
const DataMem *v)
override {
473 setNodeValue(n,
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
475 void setEdgeDataMemValue(
const edge e,
const DataMem *v)
override {
476 setEdgeValue(e,
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
478 void setAllNodeDataMemValue(
const DataMem *v)
override {
479 setAllNodeValue(
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
481 void setAllEdgeDataMemValue(
const DataMem *v)
override {
482 setAllEdgeValue(
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
489 if (Tprop::metaValueCalculator)
491 Tprop::metaValueCalculator)
492 ->computeMetaValue(
this, n, sg, mg);
497 if (Tprop::metaValueCalculator)
499 Tprop::metaValueCalculator)
500 ->computeMetaValue(
this, e, itE, mg);
507 <<
"Warning : " << __PRETTY_FUNCTION__ <<
" ... invalid conversion of " 508 <<
typeid(mvCalc).name() <<
"into " 515 Tprop::metaValueCalculator = mvCalc;
518 int compare(
const node n1,
const node n2)
const override;
519 int compare(
const edge e1,
const edge e2)
const override;
545 MutableContainer<typename Tnode::RealType> nodeProperties;
546 MutableContainer<typename Tedge::RealType> edgeProperties;
547 typename Tnode::RealType nodeDefaultValue;
548 typename Tedge::RealType edgeDefaultValue;
551 template <
typename vectType,
typename eltType,
typename propType = VectorPropertyInterface>
552 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
554 AbstractVectorProperty(
Graph *,
const std::string &name =
"");
557 bool tokenize(
const std::string &str, std::vector<std::string> &vect,
char openChar =
'(',
558 char sepChar =
',',
char closeChar =
')')
override;
560 bool setNodeStringValueAsVector(
const node n,
const std::vector<std::string> &values)
override;
562 bool setNodeStringValueAsVector(
const node,
const std::string &,
char,
char,
char)
override;
564 bool setEdgeStringValueAsVector(
const edge e,
const std::vector<std::string> &values)
override;
566 bool setEdgeStringValueAsVector(
const edge,
const std::string &,
char,
char,
char)
override;
576 void setNodeEltValue(
const node n,
unsigned int i,
577 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
585 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
586 getNodeEltValue(
const node n,
unsigned int i)
const;
596 pushBackNodeEltValue(
const node n,
597 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
605 void popBackNodeEltValue(
const node n);
615 void resizeNodeValue(
const node n,
size_t size,
616 typename eltType::RealType elt = eltType::defaultValue());
625 void setEdgeEltValue(
const edge e,
unsigned int i,
626 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
634 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
635 getEdgeEltValue(
const edge n,
unsigned int i)
const;
645 pushBackEdgeEltValue(
const edge e,
646 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
654 void popBackEdgeEltValue(
const edge e);
664 void resizeEdgeValue(
const edge e,
size_t size,
665 typename eltType::RealType elt = eltType::defaultValue());
668 #if !defined(_MSC_VER) || defined(DLL_TULIP) // When using VC++, we only want to include this when 671 #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.