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/PropertyAlgorithm.h>
32 #include <tulip/DataSet.h>
33 #include <tulip/Graph.h>
53 template <
class Tnode,
class Tedge,
class Tprop=PropertyInterface>
56 friend class GraphView;
65 virtual typename Tnode::RealType getNodeDefaultValue()
const;
71 virtual typename Tedge::RealType getEdgeDefaultValue()
const;
80 virtual typename tlp::StoredType<typename Tnode::RealType>::ReturnedConstValue getNodeValue(
const node n )
const;
89 virtual typename tlp::StoredType<typename Tedge::RealType>::ReturnedConstValue getEdgeValue(
const edge e)
const;
97 virtual void setNodeValue(
const node n,
const typename Tnode::RealType &v);
105 virtual void setEdgeValue(
const edge e,
const typename Tedge::RealType &v);
113 virtual void setAllNodeValue(
const typename Tnode::RealType &v);
121 virtual void setAllEdgeValue(
const typename Tedge::RealType &v);
131 setNodeValue(n, nodeDefaultValue);
142 setEdgeValue(e, edgeDefaultValue);
158 if (Tprop::graph == NULL) Tprop::graph = prop.Tprop::graph;
160 if (Tprop::graph == prop.Tprop::graph) {
163 Iterator<node> *itN = prop.getNonDefaultValuatedNodes();
165 while (itN->hasNext()) {
166 node itn = itN->next();
171 Iterator<edge> *itE = prop.getNonDefaultValuatedEdges();
173 while (itE->hasNext()) {
174 edge ite = itE->next();
182 Iterator<node>* itN = Tprop::graph->getNodes();
184 while (itN->hasNext()) {
185 node itn=itN->next();
187 if (prop.Tprop::graph->isElement(itn))
192 Iterator<edge>*itE = Tprop::graph->getEdges();
194 while (itE->hasNext()) {
195 edge ite=itE->next();
197 if (prop.Tprop::graph->isElement(ite))
211 virtual std::string getNodeDefaultStringValue()
const {
212 typename Tnode::RealType v = getNodeDefaultValue();
213 return Tnode::toString( v );
215 virtual std::string getEdgeDefaultStringValue()
const {
216 typename Tedge::RealType v = getEdgeDefaultValue();
217 return Tedge::toString( v );
219 virtual std::string getNodeStringValue(
const node n )
const {
220 typename Tnode::RealType v = getNodeValue( n );
221 return Tnode::toString( v );
223 virtual std::string getEdgeStringValue(
const edge e )
const {
224 typename Tedge::RealType v = getEdgeValue( e );
225 return Tedge::toString( v );
227 virtual bool setNodeStringValue(
const node inN,
const std::string & inV ) {
228 typename Tnode::RealType v;
230 if( !Tnode::fromString(v,inV) )
233 setNodeValue( inN, v );
236 virtual bool setEdgeStringValue(
const edge inE,
const std::string & inV ) {
237 typename Tedge::RealType v;
239 if( !Tedge::fromString(v,inV) )
242 setEdgeValue( inE, v );
245 virtual bool setAllNodeStringValue(
const std::string & inV ) {
246 typename Tnode::RealType v;
248 if( !Tnode::fromString(v,inV) )
251 setAllNodeValue( v );
254 virtual bool setAllEdgeStringValue(
const std::string & inV ) {
255 typename Tedge::RealType v;
257 if( !Tedge::fromString(v,inV) )
260 setAllEdgeValue( v );
263 virtual tlp::Iterator<node>* getNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
264 virtual unsigned int numberOfNonDefaultValuatedNodes()
const;
265 virtual unsigned int nodeValueSize()
const;
266 virtual void writeNodeDefaultValue(std::ostream&)
const;
267 virtual void writeNodeValue(std::ostream&, node)
const;
268 virtual bool readNodeDefaultValue(std::istream&);
269 virtual bool readNodeValue(std::istream&, node);
270 virtual tlp::Iterator<edge>* getNonDefaultValuatedEdges(
const Graph* g = NULL)
const;
271 virtual unsigned int numberOfNonDefaultValuatedEdges()
const;
272 virtual unsigned int edgeValueSize()
const;
273 virtual void writeEdgeDefaultValue(std::ostream&)
const;
274 virtual void writeEdgeValue(std::ostream&, edge)
const;
275 virtual bool readEdgeDefaultValue(std::istream&);
276 virtual bool readEdgeValue(std::istream&, edge);
277 virtual bool copy(
const node destination,
const node source, PropertyInterface *property,
278 bool ifNotDefault =
false) {
279 if (property == NULL)
286 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
287 tp->nodeProperties.get(source.id, notDefault);
289 if (ifNotDefault && !notDefault)
292 setNodeValue(destination, value);
295 virtual bool copy(
const edge destination,
const edge source, PropertyInterface *property,
296 bool ifNotDefault =
false) {
297 if (property == NULL)
304 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
305 tp->edgeProperties.get(source.id, notDefault);
307 if (ifNotDefault && !notDefault)
310 setEdgeValue(destination, value);
313 virtual void copy(PropertyInterface* property) {
316 assert(prop != NULL);
320 virtual DataMem* getNodeDefaultDataMemValue()
const {
321 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
323 virtual DataMem* getEdgeDefaultDataMemValue()
const {
324 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
326 virtual DataMem* getNodeDataMemValue(
const node n)
const {
327 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
329 virtual DataMem* getEdgeDataMemValue(
const edge e)
const {
330 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
332 virtual DataMem* getNonDefaultDataMemValue(
const node n )
const {
334 typename StoredType<typename Tnode::RealType>::ReturnedValue value = nodeProperties.get(n.id, notDefault);
337 return new TypedValueContainer<typename Tnode::RealType>(value);
341 virtual DataMem* getNonDefaultDataMemValue(
const edge e )
const {
343 typename StoredType<typename Tedge::RealType>::ReturnedValue value = edgeProperties.get(e.id, notDefault);
346 return new TypedValueContainer<typename Tedge::RealType>(value);
350 virtual void setNodeDataMemValue(
const node n,
const DataMem* v) {
351 setNodeValue(n, ((TypedValueContainer<typename Tnode::RealType> *) v)->value);
353 virtual void setEdgeDataMemValue(
const edge e,
const DataMem* v) {
354 setEdgeValue(e, ((TypedValueContainer<typename Tedge::RealType> *) v)->value);
356 virtual void setAllNodeDataMemValue(
const DataMem* v) {
357 setAllNodeValue(((TypedValueContainer<typename Tnode::RealType> *) v)->value);
359 virtual void setAllEdgeDataMemValue(
const DataMem* v) {
360 setAllEdgeValue(((TypedValueContainer<typename Tedge::RealType> *) v)->value);
366 virtual void computeMetaValue(node n, Graph* sg, Graph* mg) {
367 if (Tprop::metaValueCalculator)
369 Tprop::metaValueCalculator)->computeMetaValue(
this, n, sg, mg);
373 virtual void computeMetaValue(edge e, tlp::Iterator<edge>* itE, Graph* mg) {
374 if (Tprop::metaValueCalculator)
377 virtual void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *mvCalc) {
383 Tprop::metaValueCalculator = mvCalc;
386 int compare(
const node n1,
const node n2)
const;
387 int compare(
const edge e1,
const edge e2)
const;
406 edge, tlp::Iterator<edge>*,
415 MutableContainer<typename Tnode::RealType> nodeProperties;
416 MutableContainer<typename Tedge::RealType> edgeProperties;
417 typename Tnode::RealType nodeDefaultValue;
418 typename Tedge::RealType edgeDefaultValue;
421 template <
typename vectType,
typename eltType,
typename propType=VectorPropertyInterface>
422 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
424 AbstractVectorProperty(Graph *,
const std::string& name =
"");
427 bool setNodeStringValueAsVector(
const node,
const std::string&,
430 bool setEdgeStringValueAsVector(
const edge,
const std::string&,
441 void setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
449 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getNodeEltValue(
const node n,
unsigned int i)
const;
457 void pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
464 void popBackNodeEltValue(
const node n);
473 void resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
482 void setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
490 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getEdgeEltValue(
const edge n,
unsigned int i)
const;
498 void pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
505 void popBackEdgeEltValue(
const edge e);
514 void resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
519 #if !defined(_MSC_VER) || defined(DLL_TULIP) //When using VC++, we only want to include this when we are in the TULIP dll. With any other compiler, include it all the time
520 # include "cxx/AbstractProperty.cxx"
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 void erase(const edge e)
Resets the value of an edge to the default value.
virtual Tnode::RealType getNodeDefaultValue() const
Gets the default node value of the property.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
virtual void erase(const node n)
Resets the value of a node to the default value.
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.
virtual void clone_handler(AbstractProperty< Tnode, Tedge, Tprop > &)
Enable to clone part of sub_class.