Commit 02ac4e77 authored by berenger-bramas's avatar berenger-bramas

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
parent 00014c51
#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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment