Skip to content
Snippets Groups Projects
Commit d07f55fb authored by Markus Blatt's avatar Markus Blatt
Browse files

Added method for deallocation.

[[Imported from SVN: r1047]]
parent d361be13
No related branches found
No related tags found
No related merge requests found
......@@ -11,12 +11,12 @@
* pointer.
* @author Markus Blatt
*/
namespace Dune {
namespace Dune
{
/** @addtogroup Common
*
* @{
*/
int smcounter=0;
/**
* @brief A reference counting smart pointer.
*
......@@ -25,7 +25,8 @@ namespace Dune {
* references to it.
*/
template<class T>
class SmartPointer {
class SmartPointer
{
public:
/**
* @brief The data type we are a pointer for.
......@@ -60,6 +61,11 @@ namespace Dune {
inline const MemberType* operator->() const;
/**
* @brief Deallocates the references object if no other
* pointers reference it.
*/
inline void deallocate();
int count() const;
private:
/** @brief The object we reference. */
......@@ -79,7 +85,6 @@ namespace Dune {
inline SmartPointer<T>::SmartPointer()
{
rep_ = new PointerRep(MemberType());
//std::cout<<"Constructing "<<smcounter++<<std::endl;
}
template<class T>
......@@ -101,7 +106,6 @@ namespace Dune {
inline SmartPointer<T>::~SmartPointer()
{
if(rep_!=0 && --(rep_->count_)==0) {
//std::cout<< "Deleting! "<<rep_->count_<<" "<<rep_<<std::endl;
delete rep_;
rep_=0;
}
......@@ -137,6 +141,13 @@ namespace Dune {
return rep_->count_;
}
template<class T>
inline void SmartPointer<T>::deallocate()
{
assert(rep_!=0 && rep_->count_==1);
delete rep_;
rep_=0;
}
/** @} */
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment