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>
158 return nodeProperties.numberOfNonDefaultValues();
161 template <
class Tnode,
class Tedge,
class Tprop>
163 return Tnode::valueSize();
166 template <
class Tnode,
class Tedge,
class Tprop>
168 Tnode::writeb(oss, nodeDefaultValue);
171 template <
class Tnode,
class Tedge,
class Tprop>
175 Tnode::writeb(oss, nodeProperties.get(n.id));
178 template <
class Tnode,
class Tedge,
class Tprop>
180 if (Tnode::readb(iss, nodeDefaultValue)) {
181 nodeProperties.setAll(nodeDefaultValue);
188 template <
class Tnode,
class Tedge,
class Tprop>
191 typename Tnode::RealType val;
193 if (Tnode::readb(iss, val)) {
194 nodeProperties.set(n.id, val);
201 template <
class Tnode,
class Tedge,
class Tprop>
203 tlp::Iterator<tlp::edge>* it =
204 new tlp::UINTIterator<tlp::edge>(edgeProperties.findAll(edgeDefaultValue,
false));
206 if (Tprop::name.empty())
210 return new GraphEltIterator<tlp::edge>(g != NULL ? g : Tprop::graph, it);
212 return ((g == NULL) || (g == Tprop::graph)) ? it :
new GraphEltIterator<tlp::edge>(g, it);
215 template <
class Tnode,
class Tedge,
class Tprop>
217 return edgeProperties.numberOfNonDefaultValues();
220 template <
class Tnode,
class Tedge,
class Tprop>
222 return Tedge::valueSize();
225 template <
class Tnode,
class Tedge,
class Tprop>
227 Tedge::writeb(oss, edgeDefaultValue);
230 template <
class Tnode,
class Tedge,
class Tprop>
234 Tedge::writeb(oss, edgeProperties.get(e.id));
237 template <
class Tnode,
class Tedge,
class Tprop>
239 if (Tedge::readb(iss, edgeDefaultValue)) {
240 edgeProperties.setAll(edgeDefaultValue);
247 template <
class Tnode,
class Tedge,
class Tprop>
250 typename Tedge::RealType val;
252 if (Tedge::readb(iss, val)) {
253 edgeProperties.set(e.id, val);
260 template <
typename vectType,
typename eltType,
typename propType>
261 tlp::AbstractVectorProperty<vectType, eltType, propType>::AbstractVectorProperty(
tlp::Graph* g,
const std::string& name) :AbstractProperty<vectType, vectType, propType>(g, name) {}
263 template <
typename vectType,
typename eltType,
typename propType>
264 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeStringValueAsVector(
const node n,
const std::string& s,
char openChar,
char sepChar,
char closeChar) {
265 typename vectType::RealType v;
266 std::istringstream iss(s);
268 if (!vectType::read(iss, v, openChar, sepChar, closeChar))
271 this->setNodeValue(n, v);
275 template <
typename vectType,
typename eltType,
typename propType>
276 bool tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeStringValueAsVector(
const edge e,
const std::string& s,
char openChar,
char sepChar,
char closeChar) {
277 typename vectType::RealType v;
278 std::istringstream iss(s);
280 if (!vectType::read(iss, v, openChar, sepChar, closeChar))
283 this->setEdgeValue(e, v);
287 template <
typename vectType,
typename eltType,
typename propType>
288 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
291 typename vectType::RealType& vect =
292 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
293 assert(vect.size() > i);
294 this->propType::notifyBeforeSetNodeValue(n);
299 typename vectType::RealType tmp(vect);
301 AbstractProperty<vectType, vectType, propType>::nodeProperties.set(n.id, tmp);
304 this->propType::notifyAfterSetNodeValue(n);
307 template <
typename vectType,
typename eltType,
typename propType>
308 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
309 tlp::AbstractVectorProperty<vectType, eltType, propType>::getNodeEltValue(
const node n,
unsigned int i)
const {
311 const typename vectType::RealType& vect =
312 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n);
313 assert(vect.size() > i);
317 template <
typename vectType,
typename eltType,
typename propType>
318 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
321 typename vectType::RealType& vect =
322 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
323 this->propType::notifyBeforeSetNodeValue(n);
328 typename vectType::RealType tmp(vect);
330 AbstractProperty<vectType, vectType, propType>::nodeProperties.set(n, tmp);
333 this->propType::notifyAfterSetNodeValue(n);
336 template <
typename vectType,
typename eltType,
typename propType>
337 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackNodeEltValue(
const node n) {
340 typename vectType::RealType& vect =
341 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
342 this->propType::notifyBeforeSetNodeValue(n);
343 assert(isNotDefault);
345 this->propType::notifyAfterSetNodeValue(n);
348 template <
typename vectType,
typename eltType,
typename propType>
349 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt) {
352 typename vectType::RealType& vect =
353 AbstractProperty<vectType, vectType, propType>::nodeProperties.get(n, isNotDefault);
354 assert(isNotDefault);
355 this->propType::notifyBeforeSetNodeValue(n);
356 vect.resize(size, elt);
357 this->propType::notifyAfterSetNodeValue(n);
360 template <
typename vectType,
typename eltType,
typename propType>
361 void tlp::AbstractVectorProperty<vectType, eltType, propType>::setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
364 typename vectType::RealType& vect =
365 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
366 assert(vect.size() > i);
367 this->propType::notifyBeforeSetEdgeValue(e);
372 typename vectType::RealType tmp(vect);
374 AbstractProperty<vectType, vectType, propType>::edgeProperties.set(e, tmp);
377 this->propType::notifyAfterSetEdgeValue(e);
380 template <
typename vectType,
typename eltType,
typename propType>
381 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue
382 tlp::AbstractVectorProperty<vectType, eltType, propType>::getEdgeEltValue(
const edge e,
unsigned int i)
const {
384 const typename vectType::RealType& vect =
385 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e);
386 assert(vect.size() > i);
389 template <
typename vectType,
typename eltType,
typename propType>
390 void tlp::AbstractVectorProperty<vectType, eltType, propType>::pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v) {
393 typename vectType::RealType& vect =
394 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
395 this->propType::notifyBeforeSetEdgeValue(e);
400 typename vectType::RealType tmp(vect);
402 AbstractProperty<vectType, vectType, propType>::edgeProperties.set(e, tmp);
405 this->propType::notifyAfterSetEdgeValue(e);
408 template <
typename vectType,
typename eltType,
typename propType>
409 void tlp::AbstractVectorProperty<vectType, eltType, propType>::popBackEdgeEltValue(
const edge e) {
412 typename vectType::RealType& vect =
413 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
414 this->propType::notifyBeforeSetEdgeValue(e);
415 assert(isNotDefault);
417 this->propType::notifyAfterSetEdgeValue(e);
420 template <
typename vectType,
typename eltType,
typename propType>
421 void tlp::AbstractVectorProperty<vectType, eltType, propType>::resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt) {
424 typename vectType::RealType& vect =
425 AbstractProperty<vectType, vectType, propType>::edgeProperties.get(e, isNotDefault);
426 assert(isNotDefault);
427 this->propType::notifyBeforeSetEdgeValue(e);
428 vect.resize(size, elt);
429 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.