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);
114 virtual void setAllNodeValue(
const typename Tnode::RealType &v);
123 virtual void setAllEdgeValue(
const typename Tedge::RealType &v);
133 setNodeValue(n, nodeDefaultValue);
144 setEdgeValue(e, edgeDefaultValue);
160 if (Tprop::graph == NULL) Tprop::graph = prop.Tprop::graph;
162 if (Tprop::graph == prop.Tprop::graph) {
165 Iterator<node> *itN = prop.getNonDefaultValuatedNodes();
167 while (itN->hasNext()) {
168 node itn = itN->next();
173 Iterator<edge> *itE = prop.getNonDefaultValuatedEdges();
175 while (itE->hasNext()) {
176 edge ite = itE->next();
184 Iterator<node>* itN = Tprop::graph->getNodes();
186 while (itN->hasNext()) {
187 node itn=itN->next();
189 if (prop.Tprop::graph->isElement(itn))
194 Iterator<edge>*itE = Tprop::graph->getEdges();
196 while (itE->hasNext()) {
197 edge ite=itE->next();
199 if (prop.Tprop::graph->isElement(ite))
213 virtual std::string getNodeDefaultStringValue()
const {
214 typename Tnode::RealType v = getNodeDefaultValue();
215 return Tnode::toString( v );
217 virtual std::string getEdgeDefaultStringValue()
const {
218 typename Tedge::RealType v = getEdgeDefaultValue();
219 return Tedge::toString( v );
221 virtual std::string getNodeStringValue(
const node n )
const {
222 typename Tnode::RealType v = getNodeValue( n );
223 return Tnode::toString( v );
225 virtual std::string getEdgeStringValue(
const edge e )
const {
226 typename Tedge::RealType v = getEdgeValue( e );
227 return Tedge::toString( v );
229 virtual bool setNodeStringValue(
const node inN,
const std::string & inV ) {
230 typename Tnode::RealType v;
232 if( !Tnode::fromString(v,inV) )
235 setNodeValue( inN, v );
238 virtual bool setEdgeStringValue(
const edge inE,
const std::string & inV ) {
239 typename Tedge::RealType v;
241 if( !Tedge::fromString(v,inV) )
244 setEdgeValue( inE, v );
247 virtual bool setAllNodeStringValue(
const std::string & inV ) {
248 typename Tnode::RealType v;
250 if( !Tnode::fromString(v,inV) )
253 setAllNodeValue( v );
256 virtual bool setAllEdgeStringValue(
const std::string & inV ) {
257 typename Tedge::RealType v;
259 if( !Tedge::fromString(v,inV) )
262 setAllEdgeValue( v );
265 virtual tlp::Iterator<node>* getNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
266 virtual unsigned int numberOfNonDefaultValuatedNodes(
const Graph* g = NULL)
const;
267 virtual unsigned int nodeValueSize()
const;
268 virtual void writeNodeDefaultValue(std::ostream&)
const;
269 virtual void writeNodeValue(std::ostream&, node)
const;
270 virtual bool readNodeDefaultValue(std::istream&);
271 virtual bool readNodeValue(std::istream&, node);
272 virtual tlp::Iterator<edge>* getNonDefaultValuatedEdges(
const Graph* g = NULL)
const;
273 virtual unsigned int numberOfNonDefaultValuatedEdges(
const Graph* = NULL)
const;
274 virtual unsigned int edgeValueSize()
const;
275 virtual void writeEdgeDefaultValue(std::ostream&)
const;
276 virtual void writeEdgeValue(std::ostream&, edge)
const;
277 virtual bool readEdgeDefaultValue(std::istream&);
278 virtual bool readEdgeValue(std::istream&, edge);
279 virtual bool copy(
const node destination,
const node source, PropertyInterface *property,
280 bool ifNotDefault =
false) {
281 if (property == NULL)
288 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
289 tp->nodeProperties.get(source.id, notDefault);
291 if (ifNotDefault && !notDefault)
294 setNodeValue(destination, value);
297 virtual bool copy(
const edge destination,
const edge source, PropertyInterface *property,
298 bool ifNotDefault =
false) {
299 if (property == NULL)
306 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
307 tp->edgeProperties.get(source.id, notDefault);
309 if (ifNotDefault && !notDefault)
312 setEdgeValue(destination, value);
315 virtual void copy(PropertyInterface* property) {
318 assert(prop != NULL);
322 virtual DataMem* getNodeDefaultDataMemValue()
const {
323 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
325 virtual DataMem* getEdgeDefaultDataMemValue()
const {
326 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
328 virtual DataMem* getNodeDataMemValue(
const node n)
const {
329 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
331 virtual DataMem* getEdgeDataMemValue(
const edge e)
const {
332 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
334 virtual DataMem* getNonDefaultDataMemValue(
const node n )
const {
336 typename StoredType<typename Tnode::RealType>::ReturnedValue value = nodeProperties.get(n.id, notDefault);
339 return new TypedValueContainer<typename Tnode::RealType>(value);
343 virtual DataMem* getNonDefaultDataMemValue(
const edge e )
const {
345 typename StoredType<typename Tedge::RealType>::ReturnedValue value = edgeProperties.get(e.id, notDefault);
348 return new TypedValueContainer<typename Tedge::RealType>(value);
352 virtual void setNodeDataMemValue(
const node n,
const DataMem* v) {
353 setNodeValue(n, ((TypedValueContainer<typename Tnode::RealType> *) v)->value);
355 virtual void setEdgeDataMemValue(
const edge e,
const DataMem* v) {
356 setEdgeValue(e, ((TypedValueContainer<typename Tedge::RealType> *) v)->value);
358 virtual void setAllNodeDataMemValue(
const DataMem* v) {
359 setAllNodeValue(((TypedValueContainer<typename Tnode::RealType> *) v)->value);
361 virtual void setAllEdgeDataMemValue(
const DataMem* v) {
362 setAllEdgeValue(((TypedValueContainer<typename Tedge::RealType> *) v)->value);
368 virtual void computeMetaValue(node n, Graph* sg, Graph* mg) {
369 if (Tprop::metaValueCalculator)
371 Tprop::metaValueCalculator)->computeMetaValue(
this, n, sg, mg);
375 virtual void computeMetaValue(edge e, tlp::Iterator<edge>* itE, Graph* mg) {
376 if (Tprop::metaValueCalculator)
379 virtual void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *mvCalc) {
385 Tprop::metaValueCalculator = mvCalc;
388 int compare(
const node n1,
const node n2)
const;
389 int compare(
const edge e1,
const edge e2)
const;
408 edge, tlp::Iterator<edge>*,
417 MutableContainer<typename Tnode::RealType> nodeProperties;
418 MutableContainer<typename Tedge::RealType> edgeProperties;
419 typename Tnode::RealType nodeDefaultValue;
420 typename Tedge::RealType edgeDefaultValue;
423 template <
typename vectType,
typename eltType,
typename propType=VectorPropertyInterface>
424 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
426 AbstractVectorProperty(Graph *,
const std::string& name =
"");
429 bool setNodeStringValueAsVector(
const node,
const std::string&,
432 bool setEdgeStringValueAsVector(
const edge,
const std::string&,
443 void setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
451 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getNodeEltValue(
const node n,
unsigned int i)
const;
459 void pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
466 void popBackNodeEltValue(
const node n);
475 void resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
484 void setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
492 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getEdgeEltValue(
const edge n,
unsigned int i)
const;
500 void pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
507 void popBackEdgeEltValue(
const edge e);
516 void resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
521 #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
522 # 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.