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
65dfef64
Commit
65dfef64
authored
19 years ago
by
Adrian Burri
Browse files
Options
Downloads
Patches
Plain Diff
Autopointer class as used in ALU3dGrid
[[Imported from SVN: r2122]]
parent
304adc1c
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
common/autoptr.hh
+94
-0
94 additions, 0 deletions
common/autoptr.hh
with
94 additions
and
0 deletions
common/autoptr.hh
0 → 100644
+
94
−
0
View file @
65dfef64
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_AUTOPTR_HH
#define DUNE_AUTOPTR_HH
namespace
Dune
{
/** \brief An auto pointer class */
template
<
class
Pointer
>
class
AutoPointer
{
//! Pointer to Object
Pointer
*
ptr_
;
//! number of copies that exist from this Object
mutable
int
*
refCount_
;
//! true if we own the pointer
mutable
bool
owner_
;
public:
//! if a copy is made, the refcount is increased
inline
AutoPointer
(
const
AutoPointer
<
Pointer
>
&
copy
)
{
ptr_
=
0
;
refCount_
=
0
;
if
(
copy
.
ptr_
)
{
ptr_
=
copy
.
ptr_
;
refCount_
=
copy
.
refCount_
;
(
*
refCount_
)
++
;
// now we own the pointer
owner_
=
true
;
copy
.
owner_
=
false
;
}
}
//! initialize the member variables
AutoPointer
()
:
ptr_
(
0
)
,
refCount_
(
0
)
,
owner_
(
false
)
{}
// store object pointer and create refCount
void
store
(
Pointer
*
ptr
)
{
assert
(
ptr_
==
0
);
ptr_
=
ptr
;
if
(
ptr_
)
{
int
*
tmp
=
new
int
;
refCount_
=
tmp
;
(
*
refCount_
)
=
1
;
owner_
=
true
;
}
}
//! set Stack free, if no more refences exist
~
AutoPointer
()
{
if
(
refCount_
&&
ptr_
)
{
(
*
refCount_
)
--
;
if
((
*
refCount_
)
<=
0
)
{
if
(
ptr_
)
delete
ptr_
;
if
(
refCount_
)
delete
refCount_
;
owner_
=
false
;
}
}
}
//! return object reference
Pointer
&
operator
*
()
const
{
assert
(
ptr_
!=
0
);
assert
(
owner_
);
return
*
ptr_
;
}
//! return object pointer
Pointer
*
operator
->
()
const
{
assert
(
ptr_
!=
0
);
assert
(
owner_
);
return
ptr_
;
}
private
:
//! if copy is made than one more Reference exists
AutoPointer
<
Pointer
>
&
operator
=
(
const
AutoPointer
<
Pointer
>
&
copy
)
{
assert
(
false
);
return
(
*
this
);
}
};
}
// end namespace Dune
#endif
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