21 template <
class Tnode,
class Tedge,
class Tprop>
25 nodeDefaultValue = Tnode::defaultValue();
26 edgeDefaultValue = Tedge::defaultValue();
27 nodeProperties.setAll(Tnode::defaultValue());
28 edgeProperties.setAll(Tedge::defaultValue());
29 Tprop::metaValueCalculator = NULL;
32 template <
class Tnode,
class Tedge,
class Tprop>
34 return nodeDefaultValue;
37 template <
class Tnode,
class Tedge,
class Tprop>
39 return edgeDefaultValue;
42 template <
class Tnode,
class Tedge,
class Tprop>
45 return nodeProperties.get(n.
id);
48 template <
class Tnode,
class Tedge,
class Tprop>
51 return edgeProperties.get(e.
id);
54 template <
class Tnode,
class Tedge,
class Tprop>
57 Tprop::notifyBeforeSetNodeValue(n);
58 nodeProperties.set(n.
id,v);
59 Tprop::notifyAfterSetNodeValue(n);
62 template <
class Tnode,
class Tedge,
class Tprop>
65 Tprop::notifyBeforeSetEdgeValue(e);
66 edgeProperties.set(e.
id,v);
67 Tprop::notifyAfterSetEdgeValue(e);
70 template <
class Tnode,
class Tedge,
class Tprop>
72 if (graph && this->getGraph()->isDescendantGraph(graph)) {
78 else if (!graph || this->getGraph() == graph) {
79 Tprop::notifyBeforeSetAllNodeValue();
81 nodeProperties.setAll(v);
82 Tprop::notifyAfterSetAllNodeValue();
86 template <
class Tnode,
class Tedge,
class Tprop>
88 if (graph && this->getGraph()->isDescendantGraph(graph)) {
94 else if (!graph || this->getGraph() == graph) {
95 Tprop::notifyBeforeSetAllEdgeValue();
97 edgeProperties.setAll(v);
98 Tprop::notifyAfterSetAllEdgeValue();
102 template <
class Tnode,
class Tedge,
class Tprop>
104 const typename Tnode::RealType& n1Value = getNodeValue(n1);
105 const typename Tnode::RealType& n2Value = getNodeValue(n2);
106 return (n1Value < n2Value) ? -1 : ((n1Value == n2Value) ? 0 : 1);
109 template <
class Tnode,
class Tedge,
class Tprop>
111 const typename Tedge::RealType& e1Value = getEdgeValue(e1);
112 const typename Tedge::RealType& e2Value = getEdgeValue(e2);
113 return (e1Value < e2Value) ? -1 : ((e1Value == e2Value) ? 0 : 1);
120 template <
typename ELT_TYPE>
121 class GraphEltIterator :
public tlp::Iterator<ELT_TYPE> {
124 ELT_TYPE tmp = curElt;
126 if ((_hasnext = it->hasNext())) {
129 while (!(_hasnext = (!graph || graph->isElement(curElt)))) {
130 if (!it->hasNext())
break;
138 GraphEltIterator(
const tlp::Graph* g, tlp::Iterator<ELT_TYPE>* itN)
139 :it(itN), graph(g), curElt(ELT_TYPE()), _hasnext(
false) {
146 ~GraphEltIterator() {
151 tlp::Iterator<ELT_TYPE> *it;
159 template <
class Tnode,
class Tedge,
class Tprop>
161 tlp::Iterator<tlp::node> *it =
162 new tlp::UINTIterator<tlp::node>(nodeProperties.findAll(nodeDefaultValue,
false));
164 if (Tprop::name.empty())
168 return new GraphEltIterator<tlp::node>(g != NULL ? g : Tprop::graph, it);
170 return ((g == NULL) || (g == Tprop::graph)) ? it :
new GraphEltIterator<tlp::node>(g, it);
173 template <
class Tnode,
class Tedge,
class Tprop>
176 return nodeProperties.numberOfNonDefaultValues();
179 unsigned int ret = 0;
181 forEach(n, getNonDefaultValuatedNodes(g)) {
188 template <
class Tnode,
class Tedge,
class Tprop>
190 return Tnode::valueSize();
193 template <
class Tnode,
class Tedge,
class Tprop>
195 Tnode::writeb(oss, nodeDefaultValue);
198 template <
class Tnode,
class Tedge,
class Tprop>
202 Tnode::writeb(oss, nodeProperties.get(n.
id));
205 template <
class Tnode,
class Tedge,
class Tprop>
207 if (Tnode::readb(iss, nodeDefaultValue)) {
208 nodeProperties.setAll(nodeDefaultValue);
215 template <
class Tnode,
class Tedge,
class Tprop>
218 typename Tnode::RealType val;
220 if (Tnode::readb(iss, val)) {
221 nodeProperties.set(n.
id, val);
228 template <
class Tnode,
class Tedge,
class Tprop>
230 tlp::Iterator<tlp::edge>* it =
231 new tlp::UINTIterator<tlp::edge>(edgeProperties.findAll(edgeDefaultValue,
false));
233 if (Tprop::name.empty())
237 return new GraphEltIterator<tlp::edge>(g != NULL ? g : Tprop::graph, it);
239 return ((g == NULL) || (g == Tprop::graph)) ? it :
new GraphEltIterator<tlp::edge>(g, it);
242 template <
class Tnode,
class Tedge,
class Tprop>
245 return edgeProperties.numberOfNonDefaultValues();
248 unsigned int ret = 0;
250 forEach(e, getNonDefaultValuatedEdges(g)) {
257 template <
class Tnode,
class Tedge,
class Tprop>
259 return Tedge::valueSize();
262 template <
class Tnode,
class Tedge,
class Tprop>
264 Tedge::writeb(oss, edgeDefaultValue);
267 template <
class Tnode,
class Tedge,
class Tprop>
271 Tedge::writeb(oss, edgeProperties.get(e.
id));
274 template <
class Tnode,
class Tedge,
class Tprop>
276 if (Tedge::readb(iss, edgeDefaultValue)) {
277 edgeProperties.setAll(edgeDefaultValue);
284 template <
class Tnode,
class Tedge,
class Tprop>
287 typename Tedge::RealType val;
289 if (Tedge::readb(iss, val)) {
290 edgeProperties.set(e.
id, val);
297 template <
typename vectType,
typename eltType,
typename propType>
300 template <
typename vectType,
typename eltType,
typename propType>
301 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeStringValueAsVector(
const node n,
const std::string& s,
char openChar,
char sepChar,
char closeChar) {
302 typename vectType::RealType v;
303 std::istringstream iss(s);
305 if (!vectType::read(iss, v, openChar, sepChar, closeChar))
308 this->setNodeValue(n, v);
312 template <
typename vectType,
typename eltType,
typename propType>
313 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeStringValueAsVector(
const edge e,
const std::string& s,
char openChar,
char sepChar,
char closeChar) {
314 typename vectType::RealType v;
315 std::istringstream iss(s);
317 if (!vectType::read(iss, v, openChar, sepChar, closeChar))
320 this->setEdgeValue(e, v);
324 template <
typename vectType,
typename eltType,
typename propType>
325 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
328 typename vectType::RealType& vect =
330 assert(vect.size() > i);
331 this->propType::notifyBeforeSetNodeValue(n);
336 typename vectType::RealType tmp(vect);
341 this->propType::notifyAfterSetNodeValue(n);
344 template <
typename vectType,
typename eltType,
typename propType>
345 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
346 tlp::AbstractVectorProperty<vectType, eltType, propType>::getNodeEltValue(
const node n,
unsigned int i)
const {
348 const typename vectType::RealType& vect =
350 assert(vect.size() > i);
354 template <
typename vectType,
typename eltType,
typename propType>
355 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
358 typename vectType::RealType& vect =
360 this->propType::notifyBeforeSetNodeValue(n);
365 typename vectType::RealType tmp(vect);
370 this->propType::notifyAfterSetNodeValue(n);
373 template <
typename vectType,
typename eltType,
typename propType>
374 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackNodeEltValue(
const node n) {
377 typename vectType::RealType& vect =
379 this->propType::notifyBeforeSetNodeValue(n);
380 assert(isNotDefault);
382 this->propType::notifyAfterSetNodeValue(n);
385 template <
typename vectType,
typename eltType,
typename propType>
386 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt) {
389 typename vectType::RealType& vect =
391 assert(isNotDefault);
392 this->propType::notifyBeforeSetNodeValue(n);
393 vect.resize(size, elt);
394 this->propType::notifyAfterSetNodeValue(n);
397 template <
typename vectType,
typename eltType,
typename propType>
398 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
401 typename vectType::RealType& vect =
403 assert(vect.size() > i);
404 this->propType::notifyBeforeSetEdgeValue(e);
409 typename vectType::RealType tmp(vect);
414 this->propType::notifyAfterSetEdgeValue(e);
417 template <
typename vectType,
typename eltType,
typename propType>
418 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
419 tlp::AbstractVectorProperty<vectType, eltType, propType>::getEdgeEltValue(
const edge e,
unsigned int i)
const {
421 const typename vectType::RealType& vect =
423 assert(vect.size() > i);
426 template <
typename vectType,
typename eltType,
typename propType>
427 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
430 typename vectType::RealType& vect =
432 this->propType::notifyBeforeSetEdgeValue(e);
437 typename vectType::RealType tmp(vect);
442 this->propType::notifyAfterSetEdgeValue(e);
445 template <
typename vectType,
typename eltType,
typename propType>
446 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackEdgeEltValue(
const edge e) {
449 typename vectType::RealType& vect =
451 this->propType::notifyBeforeSetEdgeValue(e);
452 assert(isNotDefault);
454 this->propType::notifyAfterSetEdgeValue(e);
457 template <
typename vectType,
typename eltType,
typename propType>
458 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt) {
461 typename vectType::RealType& vect =
463 assert(isNotDefault);
464 this->propType::notifyBeforeSetEdgeValue(e);
465 vect.resize(size, elt);
466 this->propType::notifyAfterSetEdgeValue(e);
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
virtual 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.
virtual Iterator< edge > * getEdges() const =0
Get an iterator over all the graph's edges.
bool isValid() const
isValid checks if the node is valid. An invalid node is a node whose id is UINT_MAX.
virtual void setEdgeValue(const edge e, const typename Tedge::RealType &v)
Set the value of an edge and notify the observers of a modification.
virtual Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
virtual void setNodeValue(const node n, const typename Tnode::RealType &v)
Sets the value of a node and notify the observers of a modification.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
bool isValid() const
isValid checks if the edge is valid. An invalid edge is an edge whose id is UINT_MAX.
virtual Iterator< node > * getNodes() const =0
Gets an iterator over this graph's nodes.
virtual void setAllEdgeValue(const typename Tedge::RealType &v, const Graph *graph=NULL)
Sets the value of all edges and notify the observers. All previous values are lost and the given valu...
virtual 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.
virtual Tedge::RealType getEdgeDefaultValue() const
Gets the default edge value of the property.
unsigned int id
id The identifier of the node.
virtual void setAllNodeValue(const typename Tnode::RealType &v, const Graph *graph=NULL)
Sets the value of all nodes and notify the observers. All previous values are lost and the given valu...
unsigned int id
id The identifier of the edge.