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 Tprop::notifyBeforeSetAllNodeValue();
74 nodeProperties.setAll(v);
75 Tprop::notifyAfterSetAllNodeValue();
78 template <
class Tnode,
class Tedge,
class Tprop>
80 Tprop::notifyBeforeSetAllEdgeValue();
82 edgeProperties.setAll(v);
83 Tprop::notifyAfterSetAllEdgeValue();
86 template <
class Tnode,
class Tedge,
class Tprop>
88 const typename Tnode::RealType& n1Value = getNodeValue(n1);
89 const typename Tnode::RealType& n2Value = getNodeValue(n2);
90 return (n1Value < n2Value) ? -1 : ((n1Value == n2Value) ? 0 : 1);
93 template <
class Tnode,
class Tedge,
class Tprop>
95 const typename Tedge::RealType& e1Value = getEdgeValue(e1);
96 const typename Tedge::RealType& e2Value = getEdgeValue(e2);
97 return (e1Value < e2Value) ? -1 : ((e1Value == e2Value) ? 0 : 1);
103 #ifndef DOXYGEN_NOTFOR_DEVEL
104 template <
typename ELT_TYPE>
105 class GraphEltIterator :
public tlp::Iterator<ELT_TYPE> {
108 ELT_TYPE tmp = curElt;
110 if ((_hasnext = it->hasNext())) {
113 while (!(_hasnext = (!graph || graph->isElement(curElt)))) {
114 if (!it->hasNext())
break;
122 GraphEltIterator(
const tlp::Graph* g, tlp::Iterator<ELT_TYPE>* itN)
123 :it(itN), graph(g), curElt(ELT_TYPE()), _hasnext(false) {
130 ~GraphEltIterator() {
135 tlp::Iterator<ELT_TYPE> *it;
140 #endif // DOXYGEN_NOTFOR_DEVEL
142 template <
class Tnode,
class Tedge,
class Tprop>
144 tlp::Iterator<tlp::node> *it =
145 new tlp::UINTIterator<tlp::node>(nodeProperties.findAll(nodeDefaultValue,
false));
147 if (Tprop::name.empty())
151 return new GraphEltIterator<tlp::node>(g != NULL ? g : Tprop::graph, it);
153 return ((g == NULL) || (g == Tprop::graph)) ? it :
new GraphEltIterator<tlp::node>(g, it);
156 template <
class Tnode,
class Tedge,
class Tprop>
159 return nodeProperties.numberOfNonDefaultValues();
162 unsigned int ret = 0;
164 forEach(n, getNonDefaultValuatedNodes(g)) {
171 template <
class Tnode,
class Tedge,
class Tprop>
173 return Tnode::valueSize();
176 template <
class Tnode,
class Tedge,
class Tprop>
178 Tnode::writeb(oss, nodeDefaultValue);
181 template <
class Tnode,
class Tedge,
class Tprop>
185 Tnode::writeb(oss, nodeProperties.get(n.id));
188 template <
class Tnode,
class Tedge,
class Tprop>
190 if (Tnode::readb(iss, nodeDefaultValue)) {
191 nodeProperties.setAll(nodeDefaultValue);
198 template <
class Tnode,
class Tedge,
class Tprop>
201 typename Tnode::RealType val;
203 if (Tnode::readb(iss, val)) {
204 nodeProperties.set(n.id, val);
211 template <
class Tnode,
class Tedge,
class Tprop>
213 tlp::Iterator<tlp::edge>* it =
214 new tlp::UINTIterator<tlp::edge>(edgeProperties.findAll(edgeDefaultValue,
false));
216 if (Tprop::name.empty())
220 return new GraphEltIterator<tlp::edge>(g != NULL ? g : Tprop::graph, it);
222 return ((g == NULL) || (g == Tprop::graph)) ? it :
new GraphEltIterator<tlp::edge>(g, it);
225 template <
class Tnode,
class Tedge,
class Tprop>
228 return edgeProperties.numberOfNonDefaultValues();
231 unsigned int ret = 0;
233 forEach(e, getNonDefaultValuatedEdges(g)) {
240 template <
class Tnode,
class Tedge,
class Tprop>
242 return Tedge::valueSize();
245 template <
class Tnode,
class Tedge,
class Tprop>
247 Tedge::writeb(oss, edgeDefaultValue);
250 template <
class Tnode,
class Tedge,
class Tprop>
254 Tedge::writeb(oss, edgeProperties.get(e.id));
257 template <
class Tnode,
class Tedge,
class Tprop>
259 if (Tedge::readb(iss, edgeDefaultValue)) {
260 edgeProperties.setAll(edgeDefaultValue);
267 template <
class Tnode,
class Tedge,
class Tprop>
270 typename Tedge::RealType val;
272 if (Tedge::readb(iss, val)) {
273 edgeProperties.set(e.id, val);
280 template <
typename vectType,
typename eltType,
typename propType>
281 tlp::AbstractVectorProperty<vectType, eltType, propType>::AbstractVectorProperty(
tlp::Graph* g,
const std::string& name) :AbstractProperty<vectType, vectType, propType>(g, name) {}
283 template <
typename vectType,
typename eltType,
typename propType>
284 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeStringValueAsVector(
const node n,
const std::string& s,
char openChar,
char sepChar,
char closeChar) {
285 typename vectType::RealType v;
286 std::istringstream iss(s);
288 if (!vectType::read(iss, v, openChar, sepChar, closeChar))
291 this->setNodeValue(n, v);
295 template <
typename vectType,
typename eltType,
typename propType>
296 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeStringValueAsVector(
const edge e,
const std::string& s,
char openChar,
char sepChar,
char closeChar) {
297 typename vectType::RealType v;
298 std::istringstream iss(s);
300 if (!vectType::read(iss, v, openChar, sepChar, closeChar))
303 this->setEdgeValue(e, v);
307 template <
typename vectType,
typename eltType,
typename propType>
308 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
311 typename vectType::RealType& vect =
312 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
313 assert(vect.size() > i);
314 this->propType::notifyBeforeSetNodeValue(n);
319 typename vectType::RealType tmp(vect);
321 AbstractProperty<vectType, vectType, propType>::nodeProperties.set(n.id, tmp);
324 this->propType::notifyAfterSetNodeValue(n);
327 template <
typename vectType,
typename eltType,
typename propType>
328 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
329 tlp::AbstractVectorProperty<vectType, eltType, propType>::getNodeEltValue(
const node n,
unsigned int i)
const {
331 const typename vectType::RealType& vect =
332 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n);
333 assert(vect.size() > i);
337 template <
typename vectType,
typename eltType,
typename propType>
338 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
341 typename vectType::RealType& vect =
342 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
343 this->propType::notifyBeforeSetNodeValue(n);
348 typename vectType::RealType tmp(vect);
350 AbstractProperty<vectType, vectType, propType>::nodeProperties.set(n, tmp);
353 this->propType::notifyAfterSetNodeValue(n);
356 template <
typename vectType,
typename eltType,
typename propType>
357 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackNodeEltValue(
const node n) {
360 typename vectType::RealType& vect =
361 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
362 this->propType::notifyBeforeSetNodeValue(n);
363 assert(isNotDefault);
365 this->propType::notifyAfterSetNodeValue(n);
368 template <
typename vectType,
typename eltType,
typename propType>
369 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt) {
372 typename vectType::RealType& vect =
373 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
374 assert(isNotDefault);
375 this->propType::notifyBeforeSetNodeValue(n);
376 vect.resize(size, elt);
377 this->propType::notifyAfterSetNodeValue(n);
380 template <
typename vectType,
typename eltType,
typename propType>
381 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
384 typename vectType::RealType& vect =
385 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
386 assert(vect.size() > i);
387 this->propType::notifyBeforeSetEdgeValue(e);
392 typename vectType::RealType tmp(vect);
394 AbstractProperty<vectType, vectType, propType>::edgeProperties.set(e, tmp);
397 this->propType::notifyAfterSetEdgeValue(e);
400 template <
typename vectType,
typename eltType,
typename propType>
401 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
402 tlp::AbstractVectorProperty<vectType, eltType, propType>::getEdgeEltValue(
const edge e,
unsigned int i)
const {
404 const typename vectType::RealType& vect =
405 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e);
406 assert(vect.size() > i);
409 template <
typename vectType,
typename eltType,
typename propType>
410 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
413 typename vectType::RealType& vect =
414 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
415 this->propType::notifyBeforeSetEdgeValue(e);
420 typename vectType::RealType tmp(vect);
422 AbstractProperty<vectType, vectType, propType>::edgeProperties.set(e, tmp);
425 this->propType::notifyAfterSetEdgeValue(e);
428 template <
typename vectType,
typename eltType,
typename propType>
429 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackEdgeEltValue(
const edge e) {
432 typename vectType::RealType& vect =
433 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
434 this->propType::notifyBeforeSetEdgeValue(e);
435 assert(isNotDefault);
437 this->propType::notifyAfterSetEdgeValue(e);
440 template <
typename vectType,
typename eltType,
typename propType>
441 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt) {
444 typename vectType::RealType& vect =
445 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
446 assert(isNotDefault);
447 this->propType::notifyBeforeSetEdgeValue(e);
448 vect.resize(size, elt);
449 this->propType::notifyAfterSetEdgeValue(e);
virtual void setAllEdgeValue(const typename Tedge::RealType &v)
Sets the value of all edges and notify the observers. All previous values are lost and the given valu...
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.
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 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)
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.