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) {}
40 ValueWrapper(PROPERTYTYPE *prop,
tlp::edge e) : _prop(prop), _e(e) {}
42 void operator=(Type other) {
44 _prop->setNodeValue(_n, other);
47 _prop->setEdgeValue(_e, other);
53 operator Type()
const {
55 return _prop->getNodeValue(_n);
58 return _prop->getEdgeValue(_e);
60 std::cout <<
"WTF!?" << std::endl;
68 void operator=(ValueWrapper<PROPERTYTYPE, Type> other) {
70 _prop->setNodeValue(_n, Type(other));
73 _prop->setEdgeValue(_e, Type(other));
82 template <
typename PROPERTYTYPE,
typename Type>
83 class PropertyWrapper {
86 PROPERTYTYPE *castedInternal =
dynamic_cast<PROPERTYTYPE *
>(
internal);
88 if (castedInternal ==
nullptr) {
89 tlp::error() <<
"error: could not convert tulip property to " 93 _internal = castedInternal;
95 PropertyWrapper() : _internal(nullptr) {}
97 bool isValid()
const {
98 return _internal !=
nullptr;
101 void setAllNodeValue(Type value) {
102 _internal->setAllNodeValue(value);
105 void setAllEdgeValue(Type value) {
106 _internal->setAllEdgeValue(value);
110 return _internal->getNodeValue(n);
112 void setNodeValue(
tlp::node n, Type value) {
113 _internal->setNodeValue(n, value);
117 return _internal->getEdgeValue(e);
119 void setEdgeValue(
tlp::edge e, Type value) {
120 _internal->setEdgeValue(e, value);
124 return _internal->getNodeValue(n);
127 return _internal->getEdgeValue(e);
129 ValueWrapper<PROPERTYTYPE, Type> operator[](
tlp::node n) {
130 return ValueWrapper<PROPERTYTYPE, Type>(_internal, n);
133 ValueWrapper<PROPERTYTYPE, Type> operator[](
tlp::edge e) {
134 return ValueWrapper<PROPERTYTYPE, Type>(_internal, e);
137 PROPERTYTYPE *
internal()
const {
141 operator PROPERTYTYPE *() {
146 PROPERTYTYPE *_internal;
149 template <
typename PROPERTYTYPE,
typename NodeType,
typename EdgeType>
150 class ComplexValueWrapper {
152 ComplexValueWrapper(PROPERTYTYPE *prop,
tlp::node n) : _prop(prop), _n(n) {}
154 ComplexValueWrapper(PROPERTYTYPE *prop,
tlp::edge e) : _prop(prop), _e(e) {}
156 void operator=(NodeType other) {
158 _prop->setNodeValue(_n, other);
161 void operator=(EdgeType other) {
163 _prop->setEdgeValue(_e, other);
166 operator NodeType()
const {
168 return _prop->getNodeValue(_n);
170 operator EdgeType()
const {
172 return _prop->getEdgeValue(_e);
181 template <
typename PROPERTYTYPE,
typename NodeType,
typename EdgeType>
182 class ComplexPropertyWrapper {
185 PROPERTYTYPE *castedInternal =
dynamic_cast<PROPERTYTYPE *
>(
internal);
187 if (castedInternal ==
nullptr) {
188 tlp::error() <<
"error: could not convert tulip property to " 192 _internal = castedInternal;
194 ComplexPropertyWrapper() : _internal(nullptr) {}
196 bool isValid()
const {
197 return _internal !=
nullptr;
200 void setAllNodeValue(NodeType value) {
201 _internal->setAllNodeValue(value);
204 void setAllEdgeValue(EdgeType value) {
205 _internal->setAllEdgeValue(value);
208 NodeType getNodeValue(
tlp::node n)
const {
209 return _internal->getNodeValue(n);
211 void setNodeValue(
tlp::node n, EdgeType value) {
212 _internal->setNodeValue(n, value);
215 NodeType getEdgeValue(
tlp::edge e)
const {
216 return _internal->getEdgeValue(e);
218 void setEdgeValue(
tlp::edge e, NodeType value) {
219 _internal->setEdgeValue(e, value);
223 return _internal->getNodeValue(n);
226 return _internal->getEdgeValue(e);
228 ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType> operator[](
tlp::node n) {
229 return ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType>(_internal, n);
232 ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType> operator[](
tlp::edge e) {
233 return ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType>(_internal, e);
236 PROPERTYTYPE *
internal()
const;
238 operator PROPERTYTYPE *() {
243 PROPERTYTYPE *_internal;
246 typedef PropertyWrapper<tlp::DoubleProperty, double> DoublePropertyWrapper;
247 typedef PropertyWrapper<tlp::IntegerProperty, int> IntegerPropertyWrapper;
248 typedef PropertyWrapper<tlp::BooleanProperty, bool> BooleanPropertyWrapper;
249 typedef PropertyWrapper<tlp::ColorProperty, tlp::Color> ColorPropertyWrapper;
250 typedef PropertyWrapper<tlp::StringProperty, std::string> StringPropertyWrapper;
251 typedef PropertyWrapper<tlp::SizeProperty, tlp::Size> SizePropertyWrapper;
252 typedef ComplexPropertyWrapper<tlp::LayoutProperty, tlp::Coord, tlp::LineType>
253 LayoutPropertyWrapper;
255 #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.