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>
54template <
class Tnode,
class Tedge,
class Tprop = PropertyInterface>
55class TLP_SCOPE AbstractProperty :
public Tprop {
57 friend class GraphView;
60 AbstractProperty(Graph *,
const std::string &n =
"");
82 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
88 const typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue
101 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue
107 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue
operator[](
edge e)
const {
117 getNodesEqualTo(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v,
118 const Graph *g =
nullptr)
const;
126 getEdgesEqualTo(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v,
127 const Graph *g =
nullptr)
const;
137 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
144 AbstractProperty *_prop;
148 constexpr nodeValueRef(AbstractProperty *prop,
node n) : _prop(prop), _n(n) {}
150 typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue getValue()
const {
151 return _prop->getNodeValue(_n);
159 operator=(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue val)
noexcept {
160 _prop->setNodeValue(_n, val);
168 nodeValueRef &
operator=(
const nodeValueRef &ref)
noexcept {
169 _prop->setNodeValue(_n, ref.getValue());
177 operator typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue() {
186 return nodeValueRef(
this, n);
197 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
204 AbstractProperty *_prop;
208 constexpr edgeValueRef(AbstractProperty *prop,
edge e) : _prop(prop), _e(e) {}
210 typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue getValue()
const {
211 return _prop->getEdgeValue(_e);
219 operator=(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue val)
noexcept {
220 _prop->setEdgeValue(_e, val);
228 edgeValueRef &
operator=(
const edgeValueRef &ref)
noexcept {
229 _prop->setEdgeValue(_e, ref.getValue());
237 operator typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue() {
246 return edgeValueRef(
this, e);
258 setAllNodeValue(
typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue v);
315 setAllEdgeValue(
typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue v);
371 operator=(AbstractProperty<Tnode, Tedge, Tprop> &prop) {
373 if (Tprop::graph ==
nullptr)
374 Tprop::graph = prop.Tprop::graph;
376 if (Tprop::graph == prop.Tprop::graph) {
390 for (
auto n : Tprop::graph->nodes()) {
391 if (prop.Tprop::graph->isElement(n))
395 for (
auto e : Tprop::graph->edges()) {
396 if (prop.Tprop::graph->isElement(e))
410 return Tnode::toString(v);
414 return Tedge::toString(v);
418 return Tnode::toString(v);
422 return Tedge::toString(v);
425 typename Tnode::RealType v;
427 if (!Tnode::fromString(v, inV))
434 typename Tedge::RealType v;
436 if (!Tedge::fromString(v, inV))
443 typename Tnode::RealType v;
445 if (!Tnode::fromString(v, inV))
452 typename Tnode::RealType v;
454 if (!Tnode::fromString(v, inV))
461 typename Tnode::RealType v;
463 if (!Tnode::fromString(v, inV))
470 typename Tedge::RealType v;
472 if (!Tedge::fromString(v, inV))
479 typename Tedge::RealType v;
481 if (!Tedge::fromString(v, inV))
488 typename Tedge::RealType v;
490 if (!Tedge::fromString(v, inV))
512 bool copy(
const node destination,
const node source, PropertyInterface *property,
513 bool ifNotDefault =
false)
override {
514 if (property ==
nullptr)
521 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
522 tp->nodeProperties.get(source.
id, notDefault);
524 if (ifNotDefault && !notDefault)
530 bool copy(
const edge destination,
const edge source, PropertyInterface *property,
531 bool ifNotDefault =
false)
override {
532 if (property ==
nullptr)
539 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
540 tp->edgeProperties.get(source.
id, notDefault);
542 if (ifNotDefault && !notDefault)
548 void copy(PropertyInterface *property)
override {
551 assert(prop !=
nullptr);
562 return new TypedValueContainer<typename Tnode::RealType>(
getNodeValue(n));
565 return new TypedValueContainer<typename Tedge::RealType>(
getEdgeValue(e));
569 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
570 nodeProperties.get(n.
id, notDefault);
573 return new TypedValueContainer<typename Tnode::RealType>(value);
579 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
580 edgeProperties.get(e.
id, notDefault);
583 return new TypedValueContainer<typename Tedge::RealType>(value);
588 setNodeValue(n,
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
591 setEdgeValue(e,
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
594 setAllNodeValue(
static_cast<const TypedValueContainer<typename Tnode::RealType> *
>(v)->value);
597 setAllEdgeValue(
static_cast<const TypedValueContainer<typename Tedge::RealType> *
>(v)->value);
604 if (Tprop::metaValueCalculator)
606 Tprop::metaValueCalculator)
612 if (Tprop::metaValueCalculator)
614 Tprop::metaValueCalculator)
622 <<
"Warning : " << __PRETTY_FUNCTION__ <<
" ... invalid conversion of "
623 <<
typeid(mvCalc).name() <<
"into "
630 Tprop::metaValueCalculator = mvCalc;
645 virtual void computeMetaValue(AbstractProperty<Tnode, Tedge, Tprop> *,
node, Graph *, Graph *) {
651 virtual void computeMetaValue(AbstractProperty<Tnode, Tedge, Tprop> *,
edge,
660 MutableContainer<typename Tnode::RealType> nodeProperties;
661 MutableContainer<typename Tedge::RealType> edgeProperties;
662 typename Tnode::RealType nodeDefaultValue;
663 typename Tedge::RealType edgeDefaultValue;
666template <
typename vectType,
typename eltType,
typename propType = VectorPropertyInterface>
667class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
669 AbstractVectorProperty(Graph *,
const std::string &name =
"");
670 using AbstractProperty<vectType, vectType, propType>::operator=;
673 bool tokenize(
const std::string &str, std::vector<std::string> &vect,
char openChar =
'(',
674 char sepChar =
',',
char closeChar =
')')
override;
676 bool setNodeStringValueAsVector(
const node n,
const std::vector<std::string> &values)
override;
678 bool setNodeStringValueAsVector(
const node,
const std::string &,
char,
char,
char)
override;
680 bool setEdgeStringValueAsVector(
const edge e,
const std::vector<std::string> &values)
override;
682 bool setEdgeStringValueAsVector(
const edge,
const std::string &,
char,
char,
char)
override;
692 void setNodeEltValue(
const node n,
unsigned int i,
693 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
701 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
702 getNodeEltValue(
const node n,
unsigned int i)
const;
712 pushBackNodeEltValue(
const node n,
713 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
721 void popBackNodeEltValue(
const node n);
731 void resizeNodeValue(
const node n,
size_t size,
732 typename eltType::RealType elt = eltType::defaultValue());
741 void setEdgeEltValue(
const edge e,
unsigned int i,
742 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
750 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
751 getEdgeEltValue(
const edge n,
unsigned int i)
const;
761 pushBackEdgeEltValue(
const edge e,
762 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
770 void popBackEdgeEltValue(
const edge e);
780 void resizeEdgeValue(
const edge e,
size_t size,
781 typename eltType::RealType elt = eltType::defaultValue());
785#include "cxx/AbstractProperty.cxx"
edgeValueRef & operator=(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue val) noexcept
overloading of operator= to assign an edge value which allow to write: prop[n] = val
edgeValueRef & operator=(const edgeValueRef &ref) noexcept
overloading of operator= to assign an edge value which allow to write: prop1[e1] = prop2[e2]
nodeValueRef & operator=(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue val) noexcept
overloading of operator= to assign a node value which allow to write: prop[n] = val
nodeValueRef & operator=(const nodeValueRef &ref) noexcept
overloading of operator= to assign a node value which allow to write: prop1[n] = prop2[m]
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
void writeEdgeValue(std::ostream &, edge) const override
Writes the value of an edge.
void erase(const edge e) override
Resets the value of an edge to the default value.
virtual void setAllEdgeValue(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v)
Sets the value of all edges and notify the observers. All previous values are lost and the given valu...
void writeNodeValue(std::ostream &, node) const override
Writes the value of a node.
virtual void clone_handler(AbstractProperty< tlp::ColorType, tlp::ColorType, PropertyInterface > &)
bool setNodeStringValue(const node inN, const std::string &inV) override
Sets a new value on the node, represented by the string parameter.
bool readEdgeValue(std::istream &, edge) override
Reads the value of an edge.
void setNodeDataMemValue(const node n, const DataMem *v) override
Sets the node value.
virtual void setEdgeValue(const edge e, typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v)
Set the value of an edge and notify the observers of a modification.
bool setStringValueToGraphNodes(const std::string &inV, const Graph *graph) override
Sets all the nodes value to the value represented by the string for a graph. For some types,...
tlp::Iterator< node > * getNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Gets an Iterator on all non-default valuated nodes. When given a Graph as parameter,...
tlp::StoredType< typenameTedge::RealType >::ReturnedConstValue getEdgeValue(const edge e) const
Returns the value associated to the edge e in this property. If there is no value,...
void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *mvCalc) override
Sets the Calculator for meta nodes and edges.
constexpr nodeValueRef operator[](node n)
overloading of operator[] to set a node value
virtual void setAllNodeValue(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value of all nodes and notify the observers. All previous values are lost and the given valu...
bool setAllNodeStringValue(const std::string &inV) override
Sets all the nodes value to the value represented by the string. For some types, some parsing will be...
void setEdgeDataMemValue(const edge e, const DataMem *v) override
Sets the edge value.
bool setStringValueToGraphEdges(const std::string &inV, const Graph *graph) override
Sets all the edges value to the value represented by the string for a graph. For some types,...
unsigned int edgeValueSize() const override
Returns the size in bytes of an edge's value.
DataMem * getNonDefaultDataMemValue(const edge e) const override
Returns the value in a DataMem if it is not default, otherwise returns nullptr.
bool hasNonDefaultValuatedEdges(const Graph *g=nullptr) const override
Returns whether the property has edges with a non default value. When given a Graph as parameter,...
DataMem * getNodeDefaultDataMemValue() const override
Gets a pointer to the tlp::DataMem structure that contains the node default value.
bool readEdgeDefaultValue(std::istream &) override
Reads the edges default value.
const tlp::StoredType< typenameTnode::RealType >::ReturnedConstValue operator[](node n) const
overloading of operator[] to get a node value
virtual tlp::Iterator< node > * getNodesEqualTo(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v, const Graph *g=nullptr) const
virtual void setEdgeDefaultValue(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v)
Sets the value assigned as the default one to the future added edges.
virtual void setValueToGraphNodes(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v, const Graph *graph)
Sets the value of all nodes in a graph and notify the observers. Only the nodes from that graph will ...
DataMem * getNodeDataMemValue(const node n) const override
Gets the node value, contained in a tlp::DataMem structure.
bool setEdgeStringValue(const edge inE, const std::string &inV) override
Sets a new value on the edge, represented by the string parameter.
void setAllNodeDataMemValue(const DataMem *v) override
Sets all the nodes value to the value contained in the given DataMem structure. All previous values a...
void computeMetaValue(node n, Graph *sg, Graph *mg) override
Sets the value of the metanode to a computed value.
bool setAllEdgeStringValue(const std::string &inV) override
Sets all the edges value to the value represented by the string. For some types, some parsing will be...
bool setNodeDefaultStringValue(const std::string &inV) override
Sets the value assigned as the default one to the future added nodes from a string representation.
DataMem * getNonDefaultDataMemValue(const node n) const override
Returns the value in a DataMem if it is not default, otherwise returns nullptr.
std::string getNodeDefaultStringValue() const override
Gets a string representation of the node default value.
void writeEdgeDefaultValue(std::ostream &) const override
Writes the edges default value.
void setAllEdgeDataMemValue(const DataMem *v) override
Sets all the edges value to the value contained in the given DataMem structure. All previous values a...
bool setEdgeDefaultStringValue(const std::string &inV) override
Sets the value assigned as the default one to the future added edges from a string representation.
std::string getNodeStringValue(const node n) const override
Gets a string representation of the node value.
Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
void erase(const node n) override
Resets the value of a node to the default value.
bool hasNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Returns whether the property has nodes with a non default value. When given a Graph as parameter,...
virtual void setNodeValue(const node n, typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value of a node and notify the observers of a modification.
unsigned int numberOfNonDefaultValuatedEdges(const Graph *=nullptr) const override
Returns the number of edges with a non default value.
unsigned int nodeValueSize() const override
Returns the size in bytes of a node's value.
bool copy(const edge destination, const edge source, PropertyInterface *property, bool ifNotDefault=false) override
Copies the value of an edge in another property to an edge in this property.
void computeMetaValue(edge e, tlp::Iterator< edge > *itE, Graph *mg) override
Sets the value of the metaedge to a computed value.
tlp::StoredType< typenameTnode::RealType >::ReturnedConstValue getNodeValue(const node n) const
Returns the value associated with the node n in this property. If there is no value,...
virtual void setNodeDefaultValue(typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value assigned as the default one to the future added nodes.
std::string getEdgeStringValue(const edge e) const override
Gets a string representation of the edge value.
bool copy(const node destination, const node source, PropertyInterface *property, bool ifNotDefault=false) override
Copies the value of a node in another property to a node in this property.
unsigned int numberOfNonDefaultValuatedNodes(const Graph *g=nullptr) const override
Returns the number of nodes with a non default value. When given a Graph as parameter,...
virtual void setValueToGraphEdges(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v, const Graph *graph)
Sets the value of all edges in a graph and notify the observers. Only the edges from that graph will ...
Tedge::RealType getEdgeDefaultValue() const
Gets the default edge value of the property.
bool readNodeDefaultValue(std::istream &) override
Reads the nodes default value.
void copy(PropertyInterface *property) override
Copies the values of the source property to this property.
tlp::StoredType< typenameTedge::RealType >::ReturnedConstValue operator[](edge e) const
overloading of operator[] to get an edge value
constexpr edgeValueRef operator[](edge e)
overloading of operator[] to set an edge value
virtual AbstractProperty< Tnode, Tedge, Tprop > & operator=(AbstractProperty< Tnode, Tedge, Tprop > &prop)
This operator overload allows to copy a property using the following syntax :
int compare(const node n1, const node n2) const override
Compares the value this property holds for the two given nodes.
tlp::Iterator< edge > * getNonDefaultValuatedEdges(const Graph *g=nullptr) const override
Gets an Iterator on all non-default valuated edges. When given a Graph as parameter,...
virtual tlp::Iterator< edge > * getEdgesEqualTo(typename tlp::StoredType< typename Tedge::RealType >::ReturnedConstValue v, const Graph *g=nullptr) const
std::string getEdgeDefaultStringValue() const override
Gets a string representation of the edge default value.
void writeNodeDefaultValue(std::ostream &) const override
Writes the nodes default value.
bool readNodeValue(std::istream &, node) override
Reads the value of a node.
DataMem * getEdgeDataMemValue(const edge e) const override
Gets the edge value, contained in a tlp::DataMem structure.
DataMem * getEdgeDefaultDataMemValue() const override
Gets a pointer to the tlp::DataMem structure that contains the edge default value.
int compare(const edge e1, const edge e2) const override
Compares the value this property holds for the two given edges.
Interface for Tulip iterators. Allows basic iteration operations only.
The edge struct represents an edge in a Graph object.
unsigned int id
id The identifier of the edge.
The node struct represents a node in a Graph object.
unsigned int id
id The identifier of the node.