Commit e6b7d936 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'no-dynamic-cast' into 'master'

use internal_type_name in property_exists() instead of dynamic_cast

Closes #13

See merge request !71
parents 919e020d 17719a78
Pipeline #11293 passed with stage
in 6 minutes and 21 seconds
...@@ -84,6 +84,8 @@ template <> const std::string entityTypeName<Entity::Mesh>(); ...@@ -84,6 +84,8 @@ template <> const std::string entityTypeName<Entity::Mesh>();
template<typename T, typename Entity> template<typename T, typename Entity>
class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> { class PropertyTT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, Entity> {
public: public:
using value_type = T;
using entity_type = Entity;
template<typename MeshT> template<typename MeshT>
PropertyTT(MeshT *mesh, const std::string& _name, const T &_def = T()) PropertyTT(MeshT *mesh, const std::string& _name, const T &_def = T())
: PropertyTT(std::move(mesh->template request_property<T, Entity>(_name, _def))) : PropertyTT(std::move(mesh->template request_property<T, Entity>(_name, _def)))
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "OpenVolumeMeshProperty.hh" #include "OpenVolumeMeshProperty.hh"
#include "PropertyHandles.hh" #include "PropertyHandles.hh"
#include "TypeName.hh"
#include "ForwardDeclarations.hh" #include "ForwardDeclarations.hh"
namespace OpenVolumeMesh { namespace OpenVolumeMesh {
...@@ -222,7 +223,9 @@ public: ...@@ -222,7 +223,9 @@ public:
private: private:
template <class FullPropT, class PropIterT> template <class FullPropT, class PropIterT>
bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const { bool property_exists(const PropIterT& _begin, const PropIterT& _end, const std::string& _name) const
{
auto type_name = get_type_name<typename FullPropT::value_type>();
if(_name.empty()) { if(_name.empty()) {
#ifndef NDEBUG #ifndef NDEBUG
...@@ -235,16 +238,10 @@ private: ...@@ -235,16 +238,10 @@ private:
PropIterT it = _begin; PropIterT it = _begin;
for(; it != _end; ++it) for(; it != _end; ++it)
{ {
if((*it)->name() == _name ) if((*it)->name() == _name
{ && (*it)->internal_type_name() == type_name)
#if defined OVM_FORCE_STATIC_CAST && OVM_FORCE_STATIC_CAST
return true;
#else
if(dynamic_cast<FullPropT*>(*it) != nullptr)
{ {
return true; return true;
}
#endif
} }
} }
return false; return false;
......
#pragma once
#include <string> #include <string>
#include <typeinfo> #include <typeinfo>
...@@ -6,7 +8,7 @@ ...@@ -6,7 +8,7 @@
/// We need this in order to provide property type safety when /// We need this in order to provide property type safety when
/// only limited RTTI support is available. /// only limited RTTI support is available.
template<typename T> template<typename T>
std::string get_type_name() inline std::string get_type_name()
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
// MSVC's type_name only returns a friendly name with .name(), // MSVC's type_name only returns a friendly name with .name(),
......
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