/usr/include/tulip/cxx/AbstractProperty.cxx is in libtulip-dev 3.1.2-2.3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | //-*-c++-*-
/**
Authors: David Auber, Patrick Mary, Morgan Mathiaut
from the LaBRI Visualization Team
Email : auber@tulip-software.org
Last modification : 13/03/2009
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*/
#ifndef NDEBUG
#include <iostream>
#endif
// This is not the right place to do the initialization below
// because this file is include in many cpp files
// The initialization has to take place in only one cpp file
// TlpTools.cpp seems to be a good choice to do this
/*template <class Tnode, class Tedge, class TPROPERTY>
TemplateFactory<PropertyFactory<TPROPERTY >, TPROPERTY, PropertyContext > AbstractProperty<Tnode,Tedge,TPROPERTY>::factory;*/
template <class Tnode, class Tedge, class TPROPERTY>
tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::AbstractProperty(tlp::Graph *sg):
graph(sg) {
circularCall = false;
nodeDefaultValue = Tnode::defaultValue();
edgeDefaultValue = Tedge::defaultValue();
nodeProperties.setAll(Tnode::defaultValue());
edgeProperties.setAll(Tedge::defaultValue());
}
//=============================================================
static bool isAncestor(tlp::Graph *g1, tlp::Graph *g2) {
if(g1 == g2->getRoot())
return true;
tlp::Graph *currentGraph = g2;
while(currentGraph->getSuperGraph() != currentGraph) {
if(currentGraph == g1)
return true;
currentGraph = currentGraph->getSuperGraph();
}
return false;
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
bool tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::compute(const std::string &algorithm, std::string &msg, const PropertyContext& context) {
if(!isAncestor(this->graph, context.graph))
return false;
#ifndef NDEBUG
std::cerr << __PRETTY_FUNCTION__ << std::endl;
#endif
if(circularCall) {
#ifndef NDEBUG
std::cerr << "Circular call of " << __PRETTY_FUNCTION__ << " " << msg << std::endl;
#endif
return false;
}
tlp::Observable::holdObservers();
circularCall = true;
tlp::PropertyContext tmpContext(context);
tmpContext.propertyProxy = this;
tlp::PropertyAlgorithm *tmpAlgo = factory->getPluginObject(algorithm, tmpContext);
bool result;
if (tmpAlgo != 0) {
result = tmpAlgo->check(msg);
if (result) {
tmpAlgo->run();
}
delete tmpAlgo;
}
else {
msg = "No algorithm available with this name";
result=false;
}
circularCall = false;
notifyObservers();
tlp::Observable::unholdObservers();
return result;
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
typename Tnode::RealType tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNodeDefaultValue() {
return nodeDefaultValue;
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
typename Tedge::RealType tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getEdgeDefaultValue() {
return edgeDefaultValue;
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
typename tlp::ReturnType<typename Tnode::RealType>::Value tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNodeValue(const node n ) {
return nodeProperties.get(n.id);
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
typename tlp::ReturnType<typename Tedge::RealType>::Value tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getEdgeValue(const edge e) {
return edgeProperties.get(e.id);
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setNodeValue(const node n,const typename Tnode::RealType &v) {
notifyBeforeSetNodeValue(this, n);
nodeProperties.set(n.id,v);
notifyAfterSetNodeValue(this, n);
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setEdgeValue(const edge e,const typename Tedge::RealType &v) {
notifyBeforeSetEdgeValue(this, e);
edgeProperties.set(e.id,v);
notifyAfterSetEdgeValue(this, e);
}
//=============================================================
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setAllNodeValue(const typename Tnode::RealType &v) {
notifyBeforeSetAllNodeValue(this);
nodeDefaultValue = v;
nodeProperties.setAll(v);
notifyAfterSetAllNodeValue(this);
}
//============================================================
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setAllEdgeValue(const typename Tedge::RealType &v) {
notifyBeforeSetAllEdgeValue(this);
edgeDefaultValue = v;
edgeProperties.setAll(v);
notifyAfterSetAllEdgeValue(this);
}
//==============================================================
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::erase(const node n) {
setNodeValue(n, nodeDefaultValue);
}
//=================================================================================
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::erase(const edge e) {
setEdgeValue(e, edgeDefaultValue);
}
//==============================================================
template <class Tnode, class Tedge, class TPROPERTY>
std::string tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getTypename() {
return tlp::PropertyInterface::getTypename( this );
}
//==============================================================
// Untyped accessors
template <class Tnode, class Tedge, class TPROPERTY>
std::string tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNodeDefaultStringValue() {
typename Tnode::RealType v = getNodeDefaultValue();
return Tnode::toString( v );
}
template <class Tnode, class Tedge, class TPROPERTY>
std::string tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getEdgeDefaultStringValue() {
typename Tedge::RealType v = getEdgeDefaultValue();
return Tedge::toString( v );
}
template <class Tnode, class Tedge, class TPROPERTY>
std::string tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNodeStringValue( const node inN ) {
typename Tnode::RealType v = getNodeValue( inN );
return Tnode::toString( v );
}
template <class Tnode, class Tedge, class TPROPERTY> std::string
tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getEdgeStringValue( const edge inE ) {
typename Tedge::RealType v = getEdgeValue( inE );
return Tedge::toString( v );
}
template <class Tnode, class Tedge, class TPROPERTY>
bool tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setNodeStringValue( const node inN, const std::string & inV ) {
typename Tnode::RealType v;
if( !Tnode::fromString(v,inV) )
return false;
setNodeValue( inN, v );
return true;
}
template <class Tnode, class Tedge, class TPROPERTY>
bool tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setEdgeStringValue( const edge inE, const std::string & inV ) {
typename Tedge::RealType v;
if( !Tedge::fromString(v,inV) )
return false;
setEdgeValue( inE, v );
return true;
}
template <class Tnode, class Tedge, class TPROPERTY>
bool tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setAllNodeStringValue( const std::string & inV ) {
typename Tnode::RealType v;
if( !Tnode::fromString(v,inV) )
return false;
setAllNodeValue( v );
return true;
}
template <class Tnode, class Tedge, class TPROPERTY> bool
tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setAllEdgeStringValue( const std::string & inV ) {
typename Tedge::RealType v;
if( !Tedge::fromString(v,inV) )
return false;
setAllEdgeValue( v );
return true;
}
template<typename T>
struct PropertyValueContainer :public tlp::DataMem {
T value;
PropertyValueContainer(const T& val) : value(val) {
value = val;
}
~PropertyValueContainer() {
}
};
template <class Tnode, class Tedge, class TPROPERTY>
tlp::DataMem* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNodeDefaultDataMemValue() {
return new PropertyValueContainer<typename Tnode::RealType>(getNodeDefaultValue());
}
template <class Tnode, class Tedge, class TPROPERTY>
tlp::DataMem* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getEdgeDefaultDataMemValue() {
return new PropertyValueContainer<typename Tedge::RealType>(getEdgeDefaultValue());
}
template <class Tnode, class Tedge, class TPROPERTY>
tlp::DataMem* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNodeDataMemValue( const node inN ) {
return new PropertyValueContainer<typename Tnode::RealType>(getNodeValue(inN));
}
template <class Tnode, class Tedge, class TPROPERTY> tlp::DataMem*
tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getEdgeDataMemValue( const edge inE ) {
return new PropertyValueContainer<typename Tedge::RealType>(getEdgeValue(inE));
}
template <class Tnode, class Tedge, class TPROPERTY>
tlp::DataMem* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNonDefaultDataMemValue(const node n) {
typename Tnode::RealType value;
if (nodeProperties.getIfNotDefaultValue(n.id, value))
return new PropertyValueContainer<typename Tnode::RealType>(value);
return NULL;
}
template <class Tnode, class Tedge, class TPROPERTY>
tlp::DataMem* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNonDefaultDataMemValue( const edge e ) {
typename Tedge::RealType value;
if (edgeProperties.getIfNotDefaultValue(e.id, value))
return new PropertyValueContainer<typename Tedge::RealType>(value);
return NULL;
}
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setNodeDataMemValue( const node inN, const tlp::DataMem* inV ) {
setNodeValue(inN, ((PropertyValueContainer<typename Tnode::RealType> *) inV)->value);
}
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setEdgeDataMemValue( const edge inE, const tlp::DataMem* inV ) {
setEdgeValue(inE, ((PropertyValueContainer<typename Tedge::RealType> *) inV)->value);
}
template <class Tnode, class Tedge, class TPROPERTY>
void tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setAllNodeDataMemValue( const DataMem* inV ) {
setAllNodeValue(((PropertyValueContainer<typename Tnode::RealType> *) inV)->value);
}
template <class Tnode, class Tedge, class TPROPERTY> void
tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::setAllEdgeDataMemValue( const DataMem* inV ) {
setAllEdgeValue(((PropertyValueContainer<typename Tedge::RealType> *) inV)->value);
}
template <class Tnode, class Tedge, class TPROPERTY>
tlp::Iterator<tlp::node>* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNonDefaultValuatedNodes() {
return new tlp::UINTIterator<tlp::node>(nodeProperties.findAll(nodeDefaultValue, false));
}
template <class Tnode, class Tedge, class TPROPERTY>
tlp::Iterator<tlp::edge>* tlp::AbstractProperty<Tnode,Tedge,TPROPERTY>::getNonDefaultValuatedEdges() {
return new tlp::UINTIterator<tlp::edge>(edgeProperties.findAll(edgeDefaultValue, false));
}
|