Commit 587472de authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'PolyLineProps' into 'master'

Poly line props

apply patch from Lukas Prediger to fix varios bugs with the polyline properties. #14 

See merge request !34
parents 243c5bf6 24315f46
Pipeline #102 skipped
...@@ -2132,12 +2132,12 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::custom_prop_ ...@@ -2132,12 +2132,12 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::custom_prop_
template <class PointT> template <class PointT>
typename PolyLineT<PointT>::CustomProperty* PolyLineT<PointT>::custom_prop(CustomPropertyHandle _handle) { typename PolyLineT<PointT>::CustomProperty* PolyLineT<PointT>::custom_prop(CustomPropertyHandle _handle) {
return (_handle >= 0 ? cprop_enum[_handle] : 0); return (_handle >= 0 && _handle < get_num_custom_properties() ? cprop_enum[_handle] : NULL);
} }
template <class PointT> template <class PointT>
const typename PolyLineT<PointT>::CustomProperty* PolyLineT<PointT>::custom_prop(CustomPropertyHandle _handle) const { const typename PolyLineT<PointT>::CustomProperty* PolyLineT<PointT>::custom_prop(CustomPropertyHandle _handle) const {
return (_handle >= 0 ? cprop_enum[_handle] : 0); return (_handle >= 0 && _handle < get_num_custom_properties() ? cprop_enum[_handle] : NULL);
} }
template <class PointT> template <class PointT>
...@@ -2145,10 +2145,10 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>:: ...@@ -2145,10 +2145,10 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
request_custom_property(const std::string& _name, request_custom_property(const std::string& _name,
unsigned int _prop_size) { unsigned int _prop_size) {
typename CustomPropertyMap::iterator entry = custom_properties.find(_name); CustomPropertyHandle h = get_custom_property_handle(_name);
CustomProperty* pcontainer = 0; CustomProperty* pcontainer = custom_prop(h);
if (entry == custom_properties.end()) { if (!pcontainer) {
// create new property container // create new property container
pcontainer = new CustomProperty; pcontainer = new CustomProperty;
...@@ -2166,8 +2166,6 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>:: ...@@ -2166,8 +2166,6 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
cprop_enum.push_back(pcontainer); cprop_enum.push_back(pcontainer);
} else { } else {
pcontainer = entry->second;
if (++pcontainer->ref_count < 1) if (++pcontainer->ref_count < 1)
pcontainer->ref_count = 1; pcontainer->ref_count = 1;
} }
...@@ -2181,7 +2179,7 @@ void PolyLineT<PointT>:: ...@@ -2181,7 +2179,7 @@ void PolyLineT<PointT>::
CustomProperty* p = custom_prop(_prop_handle); CustomProperty* p = custom_prop(_prop_handle);
if (p && --p->ref_count <= 0) if (p && --(p->ref_count) <= 0)
p->prop_data.clear(); p->prop_data.clear();
} }
...@@ -2189,14 +2187,8 @@ template <class PointT> ...@@ -2189,14 +2187,8 @@ template <class PointT>
void PolyLineT<PointT>:: void PolyLineT<PointT>::
release_custom_property(const std::string& _name) { release_custom_property(const std::string& _name) {
typename CustomPropertyMap::iterator entry = custom_properties.find(_name); CustomPropertyHandle h = get_custom_property_handle(_name);
release_custom_property(h);
if (entry != custom_properties.end()) {
CustomProperty* p = entry->second;
release_custom_property(custom_prop_handle(p));
}
} }
template <class PointT> template <class PointT>
...@@ -2206,7 +2198,7 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>:: ...@@ -2206,7 +2198,7 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
typename CustomPropertyMap::const_iterator it = custom_properties.find(_name); typename CustomPropertyMap::const_iterator it = custom_properties.find(_name);
if (it == custom_properties.end()) if (it == custom_properties.end())
return 0; return -1;
return custom_prop_handle(it->second); return custom_prop_handle(it->second);
} }
...@@ -2215,7 +2207,7 @@ template <class PointT> ...@@ -2215,7 +2207,7 @@ template <class PointT>
const std::string PolyLineT<PointT>:: const std::string PolyLineT<PointT>::
get_custom_property_name(CustomPropertyHandle _property_handle) const { get_custom_property_name(CustomPropertyHandle _property_handle) const {
CustomProperty* p = custom_prop(_property_handle); const CustomProperty* p = custom_prop(_property_handle);
if (p) if (p)
return p->name; return p->name;
...@@ -2277,9 +2269,9 @@ void PolyLineT<PointT>:: ...@@ -2277,9 +2269,9 @@ void PolyLineT<PointT>::
return; return;
} }
if (_property_handle) { const CustomProperty* p = custom_prop(_property_handle);
const CustomProperty* p = custom_prop(_property_handle); if (p) {
unsigned int offset = p->prop_size * _i; unsigned int offset = p->prop_size * _i;
...@@ -2381,7 +2373,7 @@ const void* PolyLineT<PointT>:: ...@@ -2381,7 +2373,7 @@ const void* PolyLineT<PointT>::
else else
std::cerr << "PolyLineT::get_custom_property_buffer - invalid handle" << std::endl; std::cerr << "PolyLineT::get_custom_property_buffer - invalid handle" << std::endl;
return 0; return NULL;
} }
template <class PointT> template <class PointT>
...@@ -2397,7 +2389,7 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>:: ...@@ -2397,7 +2389,7 @@ typename PolyLineT<PointT>::CustomPropertyHandle PolyLineT<PointT>::
if (_i < get_num_custom_properties()) if (_i < get_num_custom_properties())
return CustomPropertyHandle(_i); return CustomPropertyHandle(_i);
else else
return 0; return -1;
} }
//============================================================================= //=============================================================================
......
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