Commit 30f49c09 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'PolyLineCustomProps' into 'master'

refactor handle access to custom properties in poly lines

fix for #8

not sure if it gcc compiles because of the template - typename stuff

See merge request !21
parents caf3d5c0 346f2436
......@@ -2120,18 +2120,22 @@ split_into_one_per_component(MeshT &_mesh,
}
template <class PointT>
typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::CustomProperty::handle() const {
return (CustomPropertyHandle)(this);
typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::custom_prop_handle(const CustomProperty* _prop) const {
size_t n = cprop_enum.size();
for (int i = 0; i < n; ++i)
if (cprop_enum[i] == _prop)
return i;
return -1;
}
template <class PointT>
typename PolyLineT<PointT>::CustomProperty* PolyLineT<PointT>::custom_prop(CustomPropertyHandle _handle) {
return reinterpret_cast<CustomProperty*>(_handle);
return (_handle >= 0 ? cprop_enum[_handle] : 0);
}
template <class PointT>
const typename PolyLineT<PointT>::CustomProperty* PolyLineT<PointT>::custom_prop(CustomPropertyHandle _handle) const {
return reinterpret_cast<const CustomProperty*>(_handle);
return (_handle >= 0 ? cprop_enum[_handle] : 0);
}
template <class PointT>
......@@ -2166,20 +2170,17 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
pcontainer->ref_count = 1;
}
return pcontainer->handle();
return custom_prop_handle(pcontainer);
}
template <class PointT>
void PolyLineT<PointT>::
release_custom_property(CustomPropertyHandle _prop_handle) {
if (_prop_handle) {
CustomProperty* p = custom_prop(_prop_handle);
CustomProperty* p = custom_prop(_prop_handle);
if (--p->ref_count <= 0)
p->prop_data.clear();
}
if (p && --p->ref_count <= 0)
p->prop_data.clear();
}
template <class PointT>
......@@ -2192,7 +2193,7 @@ void PolyLineT<PointT>::
CustomProperty* p = entry->second;
release_custom_property(p->handle());
release_custom_property(custom_prop_handle(p));
}
}
......@@ -2205,7 +2206,7 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
if (it == custom_properties.end())
return 0;
return it->second->handle();
return custom_prop_handle(it->second);
}
template <class PointT>
......@@ -2234,10 +2235,9 @@ void PolyLineT<PointT>::
return;
}
if (_property_handle) {
CustomProperty* p = custom_prop(_property_handle);
CustomProperty* p = custom_prop(_property_handle);
if (p) {
unsigned int offset = p->prop_size * _i;
// check out of range
......@@ -2260,13 +2260,8 @@ void PolyLineT<PointT>::
unsigned int _i,
const void* _data) {
typename CustomPropertyMap::iterator entry = custom_properties.find(_name);
if (entry != custom_properties.end()) {
CustomProperty* p = entry->second;
set_custom_property(p->handle(), _i, _data);
}
CustomPropertyHandle h = get_custom_property_handle(_name);
set_custom_property(h, _i, _data);
}
template <class PointT>
......@@ -2305,13 +2300,8 @@ void PolyLineT<PointT>::
unsigned int _i,
void* _data) const {
typename CustomPropertyMap::const_iterator entry = custom_properties.find(_name);
if (entry != custom_properties.end()) {
const CustomProperty* p = entry->second;
get_custom_property(p->handle(), _i, _data);
}
CustomPropertyHandle h = get_custom_property_handle(_name);
get_custom_property(h, _i, _data);
}
......@@ -2332,15 +2322,8 @@ template <class PointT>
bool PolyLineT<PointT>::
custom_property_available(const std::string& _name) const {
typename CustomPropertyMap::const_iterator entry = custom_properties.find(_name);
if (entry != custom_properties.end()) {
const CustomProperty* p = entry->second;
return custom_property_available(p->handle());
}
return false;
CustomPropertyHandle h = get_custom_property_handle(_name);
return custom_property_available(h);
}
......@@ -2410,7 +2393,7 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
enumerate_custom_property_handles(unsigned int _i) const {
if (_i < get_num_custom_properties())
return cprop_enum[_i]->handle();
return CustomPropertyHandle(_i);
else
return 0;
}
......
......@@ -488,7 +488,7 @@ public:
}
*/
typedef void* CustomPropertyHandle;
typedef int CustomPropertyHandle;
// request properties, returns handle of custom property
CustomPropertyHandle request_custom_property(const std::string& _name, unsigned int _prop_size);
......@@ -718,8 +718,6 @@ private:
char* buffer() {return prop_data.empty() ? 0 : &prop_data[0];}
const char* buffer() const {return prop_data.empty() ? 0 : &prop_data[0];}
CustomPropertyHandle handle() const;
};
typedef std::map< std::string, CustomProperty* > CustomPropertyMap;
......@@ -727,6 +725,8 @@ private:
CustomProperty* custom_prop(CustomPropertyHandle _handle);
const CustomProperty* custom_prop(CustomPropertyHandle _handle) const;
CustomPropertyHandle custom_prop_handle(const CustomProperty*) const;
// map from property name to property data
CustomPropertyMap custom_properties;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment