Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenVolumeMesh
OpenVolumeMesh
Commits
435cf124
Commit
435cf124
authored
May 23, 2019
by
Martin Heistermann
Browse files
Properties: Store and compare type names instead of relying on dynamic_cast
parent
4368575b
Pipeline
#10496
passed with stage
in 8 minutes and 10 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/OpenVolumeMesh/Core/BaseProperty.hh
View file @
435cf124
...
...
@@ -32,14 +32,6 @@
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#ifndef BASEPROPERTY_HH_
#define BASEPROPERTY_HH_
...
...
@@ -93,6 +85,8 @@ public:
protected:
virtual
const
std
::
string
&
internal_type_name
()
const
=
0
;
/// Copy data from other property. `other` MUST point to an object with the same type as `this`!
/// Currently no type check is performed.
virtual
void
assign_values_from
(
const
BaseProperty
*
other
)
=
0
;
...
...
src/OpenVolumeMesh/Core/OpenVolumeMeshBaseProperty.hh
View file @
435cf124
...
...
@@ -32,15 +32,6 @@
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* $LastChangedBy$ *
* *
\*===========================================================================*/
#ifndef OPENVOLUMEMESHBASEPROPERTY_HH
#define OPENVOLUMEMESHBASEPROPERTY_HH
...
...
@@ -71,9 +62,14 @@ public:
public:
explicit
OpenVolumeMeshBaseProperty
(
const
std
::
string
&
_name
=
"<unknown>"
)
:
name_
(
_name
),
persistent_
(
false
),
handle_
(
-
1
)
{
}
explicit
OpenVolumeMeshBaseProperty
(
const
std
::
string
&
_name
=
"<unknown>"
,
const
std
::
string
&
_internal_type_name
=
"<unknown>"
)
:
name_
(
_name
),
internal_type_name_
(
_internal_type_name
),
persistent_
(
false
),
handle_
(
-
1
)
{}
OpenVolumeMeshBaseProperty
(
const
OpenVolumeMeshBaseProperty
&
_rhs
)
=
default
;
...
...
@@ -107,6 +103,10 @@ public:
return
name_
;
}
const
std
::
string
&
internal_type_name
()
const
{
return
internal_type_name_
;
}
// Function to serialize a property
virtual
void
serialize
(
std
::
ostream
&
/*_ostr*/
)
const
{}
...
...
@@ -148,6 +148,7 @@ protected:
private:
std
::
string
name_
;
std
::
string
internal_type_name_
;
bool
persistent_
;
...
...
src/OpenVolumeMesh/Core/OpenVolumeMeshProperty.hh
View file @
435cf124
...
...
@@ -62,7 +62,7 @@ template<class T>
class
OpenVolumeMeshPropertyT
:
public
OpenVolumeMeshBaseProperty
{
public:
template
<
class
PropT
,
class
HandleT
>
friend
class
PropertyPtr
;
template
<
class
PropT
,
class
Entity
>
friend
class
PropertyPtr
;
typedef
T
Value
;
typedef
std
::
vector
<
T
>
vector_type
;
...
...
@@ -72,10 +72,13 @@ public:
public:
OpenVolumeMeshPropertyT
(
const
std
::
string
&
_name
=
"<unknown>"
,
const
T
&
_def
=
T
())
:
OpenVolumeMeshBaseProperty
(
_name
),
def_
(
_def
)
{
}
explicit
OpenVolumeMeshPropertyT
(
const
std
::
string
&
_name
=
"<unknown>"
,
const
std
::
string
&
_internal_type_name
=
"<unknown>"
,
const
T
&
_def
=
T
())
:
OpenVolumeMeshBaseProperty
(
_name
,
_internal_type_name
),
def_
(
_def
)
{}
OpenVolumeMeshPropertyT
(
const
OpenVolumeMeshPropertyT
&
_rhs
)
=
default
;
...
...
src/OpenVolumeMesh/Core/PropertyDefines.hh
View file @
435cf124
...
...
@@ -89,7 +89,7 @@ public:
:
PropertyTT
(
std
::
move
(
mesh
->
template
request_property
<
T
,
Entity
>(
_name
,
_def
)))
{}
using
PropertyHandleT
=
OpenVolumeMesh
::
PropHandleT
<
Entity
>
;
PropertyTT
(
const
std
::
string
&
_name
,
ResourceManager
&
_resMan
,
PropertyHandleT
_handle
,
const
T
_def
=
T
());
PropertyTT
(
const
std
::
string
&
_name
,
const
std
::
string
&
_internal_type_name
,
ResourceManager
&
_resMan
,
PropertyHandleT
_handle
,
const
T
_def
=
T
());
virtual
~
PropertyTT
()
=
default
;
virtual
BaseProperty
*
clone
(
ResourceManager
&
_resMan
,
OpenVolumeMeshHandle
_handle
)
const
;
virtual
const
std
::
string
entityType
()
const
{
return
entityTypeName
<
Entity
>
();
}
...
...
src/OpenVolumeMesh/Core/PropertyDefinesT_impl.hh
View file @
435cf124
...
...
@@ -42,8 +42,8 @@
namespace
OpenVolumeMesh
{
template
<
typename
T
,
typename
Entity
>
PropertyTT
<
T
,
Entity
>::
PropertyTT
(
const
std
::
string
&
_name
,
ResourceManager
&
_resMan
,
PropertyHandleT
_handle
,
const
T
_def
)
:
PropertyPtr
<
OpenVolumeMeshPropertyT
<
T
>
,
Entity
>
(
new
OpenVolumeMeshPropertyT
<
T
>
(
_name
,
_def
),
_resMan
,
_handle
)
{
PropertyTT
<
T
,
Entity
>::
PropertyTT
(
const
std
::
string
&
_name
,
const
std
::
string
&
_internal_type_name
,
ResourceManager
&
_resMan
,
PropertyHandleT
_handle
,
const
T
_def
)
:
PropertyPtr
<
OpenVolumeMeshPropertyT
<
T
>
,
Entity
>
(
new
OpenVolumeMeshPropertyT
<
T
>
(
_name
,
_internal_type_name
,
_def
),
_resMan
,
_handle
)
{
}
...
...
src/OpenVolumeMesh/Core/PropertyPtr.hh
View file @
435cf124
...
...
@@ -114,6 +114,7 @@ public:
virtual
bool
anonymous
()
const
{
return
ptr
::
shared_ptr
<
PropT
>::
get
()
->
name
().
empty
();
}
protected:
virtual
const
std
::
string
&
internal_type_name
()
const
{
return
ptr
::
shared_ptr
<
PropT
>::
get
()
->
internal_type_name
();
}
void
assign_values_from
(
const
BaseProperty
*
other
)
override
;
void
move_values_from
(
BaseProperty
*
other
)
override
;
...
...
src/OpenVolumeMesh/Core/ResourceManagerT_impl.hh
View file @
435cf124
...
...
@@ -44,9 +44,11 @@
#include
"ResourceManager.hh"
#include
"PropertyDefines.hh"
#include
"TypeName.hh"
namespace
OpenVolumeMesh
{
template
<
class
T
>
VertexPropertyT
<
T
>
ResourceManager
::
request_vertex_property
(
const
std
::
string
&
_name
,
const
T
_def
)
{
...
...
@@ -90,25 +92,24 @@ MeshPropertyT<T> ResourceManager::request_mesh_property(const std::string& _name
}
template
<
class
StdVecT
,
class
PropT
,
class
HandleT
,
class
T
>
PropT
ResourceManager
::
internal_request_property
(
StdVecT
&
_vec
,
const
std
::
string
&
_name
,
size_t
_size
,
const
T
_def
)
{
PropT
ResourceManager
::
internal_request_property
(
StdVecT
&
_vec
,
const
std
::
string
&
_name
,
size_t
_size
,
const
T
_def
)
{
auto
type_name
=
get_type_name
<
T
>
();
if
(
!
_name
.
empty
())
{
for
(
typename
StdVecT
::
iterator
it
=
_vec
.
begin
();
it
!=
_vec
.
end
();
++
it
)
{
if
((
*
it
)
->
name
()
==
_name
)
{
#if OVM_FORCE_STATIC_CAST
if
((
*
it
)
->
name
()
==
_name
&&
(
*
it
)
->
internal_type_name
()
==
type_name
)
{
return
*
static_cast
<
PropT
*>
(
*
it
);
#else
PropT
*
prop
=
dynamic_cast
<
PropT
*>
(
*
it
);
if
(
prop
!=
NULL
)
return
*
prop
;
#endif
}
}
}
HandleT
handle
((
int
)
_vec
.
size
());
PropT
*
prop
=
new
PropT
(
_name
,
*
this
,
handle
,
_def
);
PropT
*
prop
=
new
PropT
(
_name
,
type_name
,
*
this
,
handle
,
_def
);
prop
->
resize
(
_size
);
// Store property pointer
...
...
src/OpenVolumeMesh/Core/TypeName.hh
0 → 100644
View file @
435cf124
#include
<string>
#include
<typeinfo>
/// Get an internal name for a type. Important: this differs between
/// compilers and versions, do NOT use in file formats!
/// We need this in order to provide property type safety when
/// only limited RTTI support is available.
template
<
typename
T
>
std
::
string
get_type_name
()
{
#ifdef _MSC_VER
// MSVC's type_name only returns a friendly name with .name(),
// get the more unique mangled name using .raw_name():
return
typeid
(
T
).
raw_name
();
#else
// GCC and clang currently return the mangled name as .name(),
// there is no .raw_name()
return
typeid
(
T
).
name
();
#endif
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment