Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Koch
dune-common
Commits
88951451
Commit
88951451
authored
13 years ago
by
Oliver Sander
Browse files
Options
Downloads
Patches
Plain Diff
Use the auto_ptr from the standard library instead of implementing your own
[[Imported from SVN: r6490]]
parent
001d2d06
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dune/common/singleton.hh
+7
-44
7 additions, 44 deletions
dune/common/singleton.hh
with
7 additions
and
44 deletions
dune/common/singleton.hh
+
7
−
44
View file @
88951451
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
// vi: set et ts=4 sw=2 sts=2:
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_SINGLETON_HH
#ifndef DUNE_SINGLETON_HH
#define DUNE_SINGLETON_HH
#define DUNE_SINGLETON_HH
#include
<memory>
/**
/**
* @file
* @file
* @brief Usefull wrapper for creating singletons.
* @brief Usefull wrapper for creating singletons.
...
@@ -50,48 +53,8 @@ namespace Dune
...
@@ -50,48 +53,8 @@ namespace Dune
template
<
class
T
>
template
<
class
T
>
class
Singleton
class
Singleton
{
{
public:
/**
* @brief A simple smart pointer responsible for creation
* and deletion of the instance.
*/
class
InstancePointer
{
public:
/** @brief Construct a null pointer. */
InstancePointer
()
:
pointer_
(
0
)
{}
/** @brief Delete the instance we point to. */
~
InstancePointer
()
{
if
(
pointer_
!=
0
)
delete
pointer_
;
}
/**
* @brief Get a pointer to the instance.
* @return The instance we store.
*/
T
*
get
()
{
return
pointer_
;
}
/**
* @brief Set the pointer.
* @param pointer A pointer to the instance.
*/
void
set
(
T
*
pointer
)
{
if
(
pointer
!=
0
)
{
delete
pointer_
;
pointer_
=
pointer
;
}
}
private
:
T
*
pointer_
;
};
private
:
/** @brief Smartpointer to the instance. */
/** @brief Smartpointer to the instance. */
static
InstancePointer
instance_
;
static
std
::
auto_ptr
<
T
>
instance_
;
protected:
protected:
/* @brief Private constructor. */
/* @brief Private constructor. */
Singleton
(){}
Singleton
(){}
...
@@ -108,13 +71,13 @@ namespace Dune
...
@@ -108,13 +71,13 @@ namespace Dune
static
T
&
instance
()
static
T
&
instance
()
{
{
if
(
instance_
.
get
()
==
0
)
if
(
instance_
.
get
()
==
0
)
instance_
.
set
(
new
T
());
instance_
=
std
::
auto_ptr
<
T
>
(
new
T
());
return
*
instance_
.
get
()
;
return
*
instance_
;
}
}
};
};
template
<
class
T
>
template
<
class
T
>
typename
Singleton
<
T
>::
InstancePointer
Singleton
<
T
>::
instance_
;
typename
std
::
auto_ptr
<
T
>
Singleton
<
T
>::
instance_
;
}
// namespace Dune
}
// namespace Dune
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment