20 #ifndef PROPERTYWRAPPER_H
21 #define PROPERTYWRAPPER_H
23 #include <tulip/DoubleProperty.h>
24 #include <tulip/IntegerProperty.h>
25 #include <tulip/LayoutProperty.h>
26 #include <tulip/BooleanProperty.h>
27 #include <tulip/ColorProperty.h>
28 #include <tulip/StringProperty.h>
29 #include <tulip/SizeProperty.h>
34 template<
typename PROPERTYTYPE,
typename Type>
43 void operator=(Type other) {
45 _prop->setNodeValue(_n, other);
48 _prop->setEdgeValue(_e, other);
54 operator Type()
const {
56 return _prop->getNodeValue(_n);
59 return _prop->getEdgeValue(_e);
61 std::cout <<
"WTF!?" << std::endl;
71 _prop->setNodeValue(_n, Type(other));
74 _prop->setEdgeValue(_e, Type(other));
83 template<
typename PROPERTYTYPE,
typename Type>
84 class PropertyWrapper {
87 PROPERTYTYPE* castedInternal =
dynamic_cast<PROPERTYTYPE*
>(
internal);
89 if(castedInternal ==
nullptr) {
90 tlp::error() <<
"error: could not convert tulip property to " <<
tlp::demangleTlpClassName(
typeid(PROPERTYTYPE).name()) << std::endl;
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);
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) {
155 ComplexValueWrapper(PROPERTYTYPE* prop,
tlp::edge e) : _prop(prop), _e(e) {
158 void operator=(NodeType other) {
160 _prop->setNodeValue(_n, other);
163 void operator=(EdgeType other) {
165 _prop->setEdgeValue(_e, other);
168 operator NodeType()
const {
170 return _prop->getNodeValue(_n);
172 operator EdgeType()
const {
174 return _prop->getEdgeValue(_e);
183 template<
typename PROPERTYTYPE,
typename NodeType,
typename EdgeType>
184 class ComplexPropertyWrapper {
187 PROPERTYTYPE* castedInternal =
dynamic_cast<PROPERTYTYPE*
>(
internal);
189 if(castedInternal ==
nullptr) {
190 tlp::error() <<
"error: could not convert tulip property to " <<
tlp::demangleTlpClassName(
typeid(PROPERTYTYPE).name()) << std::endl;
193 _internal = castedInternal;
195 ComplexPropertyWrapper() : _internal(nullptr) {}
197 bool isValid()
const {
198 return _internal !=
nullptr;
201 void setAllNodeValue(NodeType value) {
202 _internal->setAllNodeValue(value);
205 void setAllEdgeValue(EdgeType value) {
206 _internal->setAllEdgeValue(value);
209 NodeType getNodeValue(
tlp::node n)
const {
210 return _internal->getNodeValue(n);
212 void setNodeValue(
tlp::node n, EdgeType value) {
213 _internal->setNodeValue(n, value);
216 NodeType getEdgeValue(
tlp::edge e)
const {
217 return _internal->getEdgeValue(e);
219 void setEdgeValue(
tlp::edge e, NodeType value) {
220 _internal->setEdgeValue(e, value);
224 return _internal->getNodeValue(n);
227 return _internal->getEdgeValue(e);
229 ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType> operator[](
tlp::node n) {
230 return ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType>(_internal, n);
233 ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType> operator[](
tlp::edge e) {
234 return ComplexValueWrapper<PROPERTYTYPE, NodeType, EdgeType>(_internal, e);
237 PROPERTYTYPE*
internal()
const;
239 operator PROPERTYTYPE*() {
244 PROPERTYTYPE* _internal;
247 typedef PropertyWrapper<tlp::DoubleProperty, double> DoublePropertyWrapper;
248 typedef PropertyWrapper<tlp::IntegerProperty, int> IntegerPropertyWrapper;
249 typedef PropertyWrapper<tlp::BooleanProperty, bool> BooleanPropertyWrapper;
250 typedef PropertyWrapper<tlp::ColorProperty, tlp::Color> ColorPropertyWrapper;
251 typedef PropertyWrapper<tlp::StringProperty, std::string> StringPropertyWrapper;
252 typedef PropertyWrapper<tlp::SizeProperty, tlp::Size> SizePropertyWrapper;
253 typedef ComplexPropertyWrapper<tlp::LayoutProperty, tlp::Coord, tlp::LineType> LayoutPropertyWrapper;
255 #endif // PROPERTYWRAPPER_H
PropertyInterface describes the interface of a graph property.
void operator=(ValueWrapper< PROPERTYTYPE, Type > other)
operator= when prop[n] = prop[n2]
bool isValid() const
isValid checks if the node is valid. An invalid node is a node whose id is UINT_MAX.
simple implementation of the copy-on-write idiom.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
bool isValid() const
isValid checks if the edge is valid. An invalid edge is an edge whose id is UINT_MAX.
std::string demangleTlpClassName(const char *className)
Demangles the name of a C++ class defined in the tlp namespace.