internal name mechanism added at property creation
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,3 +4,5 @@ CMakeLists.txt.user
|
|||||||
build*
|
build*
|
||||||
*.swp
|
*.swp
|
||||||
.settings
|
.settings
|
||||||
|
# ignore mac temporal files
|
||||||
|
.DS_Store
|
||||||
|
|||||||
@@ -232,8 +232,8 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit PropertyT(const std::string& _name = "<unknown>")
|
explicit PropertyT(const std::string& _name = "<unknown>", const std::string& _internal_type_name="" )
|
||||||
: BaseProperty(_name)
|
: BaseProperty(_name, _internal_type_name)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public: // inherited from BaseProperty
|
public: // inherited from BaseProperty
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <OpenMesh/Core/Utils/Property.hh>
|
#include <OpenMesh/Core/Utils/Property.hh>
|
||||||
|
#include <OpenMesh/Core/Utils/TypeName.hh>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
namespace OpenMesh
|
namespace OpenMesh
|
||||||
@@ -104,7 +105,7 @@ public:
|
|||||||
int idx=0;
|
int idx=0;
|
||||||
for ( ; p_it!=p_end && *p_it!=nullptr; ++p_it, ++idx ) {};
|
for ( ; p_it!=p_end && *p_it!=nullptr; ++p_it, ++idx ) {};
|
||||||
if (p_it==p_end) properties_.push_back(nullptr);
|
if (p_it==p_end) properties_.push_back(nullptr);
|
||||||
properties_[idx] = new PropertyT<T>(_name);
|
properties_[idx] = new PropertyT<T>(_name, get_type_name<T>() ); // create a new property with requested name and given (system dependent) internal typename
|
||||||
return BasePropHandleT<T>(idx);
|
return BasePropHandleT<T>(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
src/OpenMesh/Core/Utils/typename.hh
Normal file
29
src/OpenMesh/Core/Utils/typename.hh
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef TYPENAME_HH
|
||||||
|
#define TYPENAME_HH
|
||||||
|
|
||||||
|
/// Get an internal name for a type
|
||||||
|
/// Important, this is depends on compilers and versions, do NOT se in file formats!
|
||||||
|
/// This provides property type safty when only limited RTTI is available
|
||||||
|
/// Solution adapted from OpenVolumeMesh
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
|
namespace OpenMesh {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::string get_type_name()
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
// MSVC'S type_name returns only a friendly name with name() method,
|
||||||
|
// to get a unique name use raw_name() method instead
|
||||||
|
return typeid(T).raw_name();
|
||||||
|
#else
|
||||||
|
// GCC and clang curently return mangled name as name(), there is no raw_name() method
|
||||||
|
return typeid(T).name();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TYPENAME_HH
|
||||||
Reference in New Issue
Block a user