From 02ac4e77f2ed04dede7545f93f12efe0e3430cbc Mon Sep 17 00:00:00 2001 From: berenger-bramas <berenger-bramas@2616d619-271b-44dc-8df4-d4a8f33a7222> Date: Tue, 14 Feb 2012 09:08:38 +0000 Subject: [PATCH] Add comments to the smart pointer class. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/scalfmm/scalfmm/trunk@382 2616d619-271b-44dc-8df4-d4a8f33a7222 --- Src/Utils/FSmartPointer.hpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Src/Utils/FSmartPointer.hpp b/Src/Utils/FSmartPointer.hpp index 64fba7b31..3f6d275ab 100644 --- a/Src/Utils/FSmartPointer.hpp +++ b/Src/Utils/FSmartPointer.hpp @@ -1,37 +1,48 @@ #ifndef FSMARTPOINTER_HPP #define FSMARTPOINTER_HPP +/** This class is a basic smart pointer class + * + */ template <class ClassType> class FSmartPointer { - ClassType* pointer; - int* counter; + ClassType* pointer; //< The pointer to the memory area + int* counter; //< Reference counter public: + // The type of data managed by the pointer typedef ClassType ValueType; + /** Empty constructor */ FSmartPointer() : pointer(0), counter(0) { } + /** Constructor from the memory pointer */ FSmartPointer(ClassType* const inPointer) : pointer(0), counter(0) { assign(inPointer); } + /** Constructor from a smart pointer */ FSmartPointer(const FSmartPointer& inPointer) : pointer(0), counter(0) { assign(inPointer); } + /** Destructor, same as release */ ~FSmartPointer(){ release(); } + /** Assign operator, same as assign */ void operator=(ClassType* const inPointer){ assign(inPointer); } + /** Assign operator, same as assign */ void operator=(const FSmartPointer& inPointer){ assign(inPointer); } + /** Point to a new pointer, release if needed */ void assign(ClassType* const inPointer){ release(); pointer = inPointer; @@ -39,6 +50,7 @@ public: (*counter) = 1; } + /** Point to a new pointer, release if needed */ void assign(const FSmartPointer& inPointer){ release(); pointer = inPointer.pointer; @@ -46,6 +58,7 @@ public: if(counter) (*counter) = (*counter) + 1; } + /** Dec counter and Release the memory last */ void release(){ if(counter){ (*counter) = (*counter) - 1; @@ -57,50 +70,62 @@ public: } } + /** To know if the smart pointer is pointing to a memory */ bool isAssigned() const{ return pointer != 0; } + /** Is last => counter == 0 */ bool isLast() const{ return counter && (*counter) == 1; } + /** Get the direct pointer */ ClassType* getPtr(){ return pointer; } + /** Get the direct pointer */ const ClassType* getPtr() const { return pointer; } + /** Operator [] */ ClassType& operator[](const int& index){ return pointer[index]; } + /** Operator [] */ const ClassType& operator[](const int& index) const { return pointer[index]; } + /** Operator * return a reference to the pointer object */ ClassType& operator*(){ return (*pointer); } + /** Operator * return a reference to the pointer object */ const ClassType& operator*() const { return (*pointer); } + /** Return the pointing address */ ClassType* operator->(){ return pointer; } + /** Return the pointing address */ const ClassType* operator->() const { return pointer; } + /** To cast to class type pointer */ operator const ClassType*() const { return pointer; } + /** To cast to class type pointer */ operator ClassType*() { return pointer; } -- GitLab