21 #ifndef PROPERTYWRAPPER_H 22 #define PROPERTYWRAPPER_H 24 #include <tulip/DoubleProperty.h> 25 #include <tulip/IntegerProperty.h> 26 #include <tulip/LayoutProperty.h> 27 #include <tulip/BooleanProperty.h> 28 #include <tulip/ColorProperty.h> 29 #include <tulip/StringProperty.h> 30 #include <tulip/SizeProperty.h> 35 template<
typename PROPERTYTYPE,
typename Type>
38 ValueWrapper(PROPERTYTYPE* prop,
tlp::node n) : _prop(prop), _n(n) {
41 ValueWrapper(PROPERTYTYPE* prop,
tlp::edge e) : _prop(prop), _e(e) {
44 void operator=(Type other) {
46 _prop->setNodeValue(_n, other);
49 _prop->setEdgeValue(_e, other);
55 operator Type()
const {
57 return _prop->getNodeValue(_n);
60 return _prop->getEdgeValue(_e);
62 std::cout <<
"WTF!?" << std::endl;
70 void operator=(ValueWrapper<PROPERTYTYPE, Type> other) {
72 _prop->setNodeValue(_n, Type(other));
75 _prop->setEdgeValue(_e, Type(other));
84 template<
typename PROPERTYTYPE,
typename Type>
85 class PropertyWrapper {
88 PROPERTYTYPE* castedInternal =
dynamic_cast<PROPERTYTYPE*
>(
internal);
90 if(castedInternal ==
nullptr) {
91 tlp::error() <<
"error: could not convert tulip property to " <<
tlp::demangleTlpClassName(
typeid(PROPERTYTYPE).name()) << std::endl;
94 _internal = castedInternal;
96 PropertyWrapper() : _internal(nullptr) {}
98 bool isValid()
const {
99 return _internal !=
nullptr;
102 void setAllNodeValue(Type value) {
103 _internal->setAllNodeValue(value);
106 void setAllEdgeValue(Type value) {
107 _internal->setAllEdgeValue(value);
111 return _internal->getNodeValue(n);
113 void setNodeValue(
tlp::node n, Type value) {
114 _internal->setNodeValue(n, value);
118 return _internal->getEdgeValue(e);
120 void setEdgeValue(
tlp::edge e, Type value) {
121 _internal->setEdgeValue(e, value);
125 return _internal->getNodeValue(n);
128 return _internal->getEdgeValue(e);
130 ValueWrapper<PROPERTYTYPE, Type> operator[](
tlp::node n) {
131 return ValueWrapper<PROPERTYTYPE, Type>(_internal, n);
134 ValueWrapper<PROPERTYTYPE, Type> operator[](
tlp::edge e) {
135 return ValueWrapper<PROPERTYTYPE, Type>(_internal, e);
138 PROPERTYTYPE*
internal()
const {
142 operator PROPERTYTYPE*() {
147 PROPERTYTYPE* _internal;
150 template<
typename PROPERTYTYPE,
typename NodeType,
typename EdgeType>
151 class ComplexValueWrapper {
153 ComplexValueWrapper(PROPERTYTYPE* prop,
tlp::node n) : _prop(prop), _n(n) {
156 ComplexValueWrapper(PROPERTYTYPE* prop,
tlp::edge e) : _prop(prop), _e(e) {
159 void operator=(NodeType other) {
161 _prop->setNodeValue(_n, other);
164 void operator=(EdgeType other) {
166 _prop->setEdgeValue(_e, other);
169 operator NodeType()
const {
171 return _prop->getNodeValue(_n);
173 operator EdgeType()
const {
175 return _prop->getEdgeValue(_e);
184 template<
typename PROPERTYTYPE,
typename NodeType,
typename EdgeType>
185 class ComplexPropertyWrapper {
188 PROPERTYTYPE* castedInternal =
dynamic_cast<PROPERTYTYPE*
>(
internal);
190 if(castedInternal ==
nullptr) {
191 tlp::error() <<
"error: could not convert tulip property to " <<
tlp::demangleTlpClassName(
typeid(PROPERTYTYPE).name()) << std::endl;
194 _internal = castedInternal;
196 ComplexPropertyWrapper() : _internal(nullptr) {}
198 bool isValid()
const {
199 return _internal !=
nullptr;
202 void setAllNodeValue(NodeType value) {
203 _internal->setAllNodeValue(value);
206 void setAllEdgeValue(EdgeType value) {
207 _internal->setAllEdgeValue(value);
210 NodeType getNodeValue(
tlp::node n)
const {
211 return _internal->getNodeValue(n);
213 void setNodeValue(
tlp::node n, EdgeType value) {
214 _internal->setNodeValue(n, value);
217 NodeType getEdgeValue(
tlp::edge e)
const {
218 return _internal->getEdgeValue(e);
220 void setEdgeValue(
tlp::edge e, NodeType value) {
221 _internal->setEdgeValue(e, value);
225 return _internal->getNodeValue(n);
228 return _internal->getEdgeValue(e);
230 ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType> operator[](
tlp::node n) {
231 return ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType>(_internal, n);
234 ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType> operator[](
tlp::edge e) {
235 return ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType>(_internal, e);
238 PROPERTYTYPE*
internal()
const;
240 operator PROPERTYTYPE*() {
245 PROPERTYTYPE* _internal;
248 typedef PropertyWrapper<tlp::DoubleProperty, double> DoublePropertyWrapper;
249 typedef PropertyWrapper<tlp::IntegerProperty, int> IntegerPropertyWrapper;
250 typedef PropertyWrapper<tlp::BooleanProperty, bool> BooleanPropertyWrapper;
251 typedef PropertyWrapper<tlp::ColorProperty, tlp::Color> ColorPropertyWrapper;
252 typedef PropertyWrapper<tlp::StringProperty, std::string> StringPropertyWrapper;
253 typedef PropertyWrapper<tlp::SizeProperty, tlp::Size> SizePropertyWrapper;
254 typedef ComplexPropertyWrapper<tlp::LayoutProperty, tlp::Coord, tlp::LineType> LayoutPropertyWrapper;
256 #endif // PROPERTYWRAPPER_H PropertyInterface describes the interface of a graph property.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
std::string demangleTlpClassName(const char *className)
Demangles the name of a C++ class defined in the tlp namespace.