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 tlp::Iterator<edge>* getNonDefaultValuatedEdges(
const Graph* g = NULL)
const;
265 virtual bool copy(
const node destination,
const node source, PropertyInterface *property,
266 bool ifNotDefault =
false) {
267 if (property == NULL)
274 typename StoredType<typename Tnode::RealType>::ReturnedValue value =
275 tp->nodeProperties.get(source.id, notDefault);
277 if (ifNotDefault && !notDefault)
280 setNodeValue(destination, value);
283 virtual bool copy(
const edge destination,
const edge source, PropertyInterface *property,
284 bool ifNotDefault =
false) {
285 if (property == NULL)
292 typename StoredType<typename Tedge::RealType>::ReturnedValue value =
293 tp->edgeProperties.get(source.id, notDefault);
295 if (ifNotDefault && !notDefault)
298 setEdgeValue(destination, value);
301 virtual void copy(PropertyInterface* property) {
304 assert(prop != NULL);
308 virtual DataMem* getNodeDefaultDataMemValue()
const {
309 return new TypedValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
311 virtual DataMem* getEdgeDefaultDataMemValue()
const {
312 return new TypedValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
314 virtual DataMem* getNodeDataMemValue(
const node n)
const {
315 return new TypedValueContainer<typename Tnode::RealType>(getNodeValue(n));
317 virtual DataMem* getEdgeDataMemValue(
const edge e)
const {
318 return new TypedValueContainer<typename Tedge::RealType>(getEdgeValue(e));
320 virtual DataMem* getNonDefaultDataMemValue(
const node n )
const {
322 typename StoredType<typename Tnode::RealType>::ReturnedValue value = nodeProperties.get(n.id, notDefault);
325 return new TypedValueContainer<typename Tnode::RealType>(value);
329 virtual DataMem* getNonDefaultDataMemValue(
const edge e )
const {
331 typename StoredType<typename Tedge::RealType>::ReturnedValue value = edgeProperties.get(e.id, notDefault);
334 return new TypedValueContainer<typename Tedge::RealType>(value);
338 virtual void setNodeDataMemValue(
const node n,
const DataMem* v) {
339 setNodeValue(n, ((TypedValueContainer<typename Tnode::RealType> *) v)->value);
341 virtual void setEdgeDataMemValue(
const edge e,
const DataMem* v) {
342 setEdgeValue(e, ((TypedValueContainer<typename Tedge::RealType> *) v)->value);
344 virtual void setAllNodeDataMemValue(
const DataMem* v) {
345 setAllNodeValue(((TypedValueContainer<typename Tnode::RealType> *) v)->value);
347 virtual void setAllEdgeDataMemValue(
const DataMem* v) {
348 setAllEdgeValue(((TypedValueContainer<typename Tedge::RealType> *) v)->value);
354 virtual void computeMetaValue(node n, Graph* sg, Graph* mg) {
355 if (Tprop::metaValueCalculator)
357 Tprop::metaValueCalculator)->computeMetaValue(
this, n, sg, mg);
361 virtual void computeMetaValue(edge e, tlp::Iterator<edge>* itE, Graph* mg) {
362 if (Tprop::metaValueCalculator)
365 virtual void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *mvCalc) {
371 Tprop::metaValueCalculator = mvCalc;
374 int compare(
const node n1,
const node n2)
const;
375 int compare(
const edge e1,
const edge e2)
const;
394 edge, tlp::Iterator<edge>*,
403 MutableContainer<typename Tnode::RealType> nodeProperties;
404 MutableContainer<typename Tedge::RealType> edgeProperties;
405 typename Tnode::RealType nodeDefaultValue;
406 typename Tedge::RealType edgeDefaultValue;
409 template <
typename vectType,
typename eltType,
typename propType=PropertyInterface>
410 class TLP_SCOPE AbstractVectorProperty :
public AbstractProperty<vectType, vectType, propType> {
412 AbstractVectorProperty(Graph *, std::string name =
"");
422 void setNodeEltValue(
const node n,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
430 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getNodeEltValue(
const node n,
unsigned int i)
const;
438 void pushBackNodeEltValue(
const node n,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
445 void popBackNodeEltValue(
const node n);
454 void resizeNodeValue(
const node n,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
463 void setEdgeEltValue(
const edge e,
unsigned int i,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
471 typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue getEdgeEltValue(
const edge n,
unsigned int i)
const;
479 void pushBackEdgeEltValue(
const edge e,
typename tlp::StoredType<typename eltType::RealType>::ReturnedConstValue v);
486 void popBackEdgeEltValue(
const edge e);
495 void resizeEdgeValue(
const edge e,
size_t size,
typename eltType::RealType elt = eltType::defaultValue());
500 #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
501 # include "cxx/AbstractProperty.cxx"