Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
OpenMesh
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenMesh
OpenMesh
Commits
70d7ae8a
Commit
70d7ae8a
authored
Apr 14, 2016
by
Janis Born
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add factory functions for creating PropertyManagers without restating the mesh type in C++11
parent
eda7782a
Pipeline
#1251
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
11 deletions
+71
-11
src/OpenMesh/Core/Utils/PropertyManager.hh
src/OpenMesh/Core/Utils/PropertyManager.hh
+71
-11
No files found.
src/OpenMesh/Core/Utils/PropertyManager.hh
View file @
70d7ae8a
...
...
@@ -60,7 +60,23 @@ namespace OpenMesh {
* It also defines convenience operators to access the encapsulated
* property's value.
*
* Usage example:
* For C++11, it is recommended to use the factory functions
* makePropertyManagerFromNew, makePropertyManagerFromExisting,
* makePropertyManagerFromExistingOrNew to construct a PropertyManager, e.g.
*
* \code
* TriMesh mesh;
* auto visited = makePropertyManagerFromNew<VPropHandleT<bool>>(mesh, "visited.plugin-example.i8.informatik.rwth-aachen.de");
*
* for (auto vh : mesh.vertices()) {
* if (!visited[vh]) {
* visitComponent(mesh, vh, visited);
* }
* }
* \endcode
*
* For C++98, it is usually more convenient to use the constructor explicitly,
* i.e.
*
* \code
* TriMesh mesh;
...
...
@@ -107,6 +123,9 @@ class PropertyManager {
* the property is deleted upon destruction of the PropertyManager instance). If true,
* the instance merely acts as a convenience wrapper around an existing property with no
* lifecycle management whatsoever.
*
* @see PropertyManager::createIfNotExists, makePropertyManagerFromNew,
* makePropertyManagerFromExisting, makePropertyManagerFromExistingOrNew
*/
PropertyManager
(
MeshT
&
mesh
,
const
char
*
propname
,
bool
existing
=
false
)
:
mesh_
(
&
mesh
),
retain_
(
existing
),
name_
(
propname
)
{
if
(
existing
)
{
...
...
@@ -164,15 +183,14 @@ class PropertyManager {
* Move assignment. Transfers ownership (delete responsibility).
*/
PropertyManager
&
operator
=
(
PropertyManager
&&
rhs
)
{
deleteProperty
();
mesh_
=
rhs
.
mesh_
;
prop_
=
rhs
.
prop_
;
retain_
=
rhs
.
retain_
;
name_
=
rhs
.
name_
;
rhs
.
retain_
=
true
;
if
(
&
rhs
!=
this
)
{
deleteProperty
();
mesh_
=
rhs
.
mesh_
;
prop_
=
rhs
.
prop_
;
retain_
=
rhs
.
retain_
;
name_
=
rhs
.
name_
;
rhs
.
retain_
=
true
;
}
return
*
this
;
}
...
...
@@ -180,6 +198,8 @@ class PropertyManager {
* Create a property manager for the supplied property and mesh.
* If the property doesn't exist, it is created. In any case,
* lifecycle management is disabled.
*
* @see makePropertyManagerFromExistingOrNew
*/
static
PropertyManager
createIfNotExists
(
MeshT
&
mesh
,
const
char
*
propname
)
{
PROPTYPE
dummy_prop
;
...
...
@@ -192,7 +212,7 @@ class PropertyManager {
PropertyManager
duplicate
(
const
char
*
clone_name
)
{
PropertyManager
pm
(
*
mesh_
,
clone_name
,
false
);
pm
.
mesh_
->
property
(
pm
.
prop_
)
=
mesh_
->
property
(
prop_
);
return
std
::
move
(
pm
)
;
return
pm
;
}
/**
...
...
@@ -237,6 +257,8 @@ class PropertyManager {
* Create a property manager for the supplied property and mesh.
* If the property doesn't exist, it is created. In any case,
* lifecycle management is disabled.
*
* @see makePropertyManagerFromExistingOrNew
*/
static
Proxy
createIfNotExists
(
MeshT
&
mesh
,
const
char
*
propname
)
{
PROPTYPE
dummy_prop
;
...
...
@@ -406,5 +428,43 @@ class PropertyManager {
std
::
string
name_
;
};
/**
* Creates a new property whose lifecycle is managed by the returned
* PropertyManager.
*
* Intended for temporary properties. Shadows any existsing properties of
* matching name and type.
*/
template
<
typename
PROPTYPE
,
typename
MeshT
>
PropertyManager
<
PROPTYPE
,
MeshT
>
makePropertyManagerFromNew
(
MeshT
&
mesh
,
const
char
*
propname
)
{
return
PropertyManager
<
PROPTYPE
,
MeshT
>
(
mesh
,
propname
,
false
);
}
/**
* Creates a non-owning wrapper for an existing mesh property (no lifecycle
* management).
*
* Intended for convenient access.
*
* @pre Property with the name \p propname of matching type exists.
* @throws std::runtime_error if no property with the name \p propname of
* matching type exists.
*/
template
<
typename
PROPTYPE
,
typename
MeshT
>
PropertyManager
<
PROPTYPE
,
MeshT
>
makePropertyManagerFromExisting
(
MeshT
&
mesh
,
const
char
*
propname
)
{
return
PropertyManager
<
PROPTYPE
,
MeshT
>
(
mesh
,
propname
,
true
);
}
/**
* Creates a non-owning wrapper for a mesh property (no lifecycle management).
* If the given property does not exist, it is created.
*
* Intended for creating or accessing persistent properties.
*/
template
<
typename
PROPTYPE
,
typename
MeshT
>
PropertyManager
<
PROPTYPE
,
MeshT
>
makePropertyManagerFromExistingOrNew
(
MeshT
&
mesh
,
const
char
*
propname
)
{
return
PropertyManager
<
PROPTYPE
,
MeshT
>::
createIfNotExists
(
mesh
,
propname
);
}
}
/* namespace OpenMesh */
#endif
/* PROPERTYMANAGER_HH_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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