Re: Reference Counting
These are difference template arguments:
template template arguments
and
template typename arguments
There is also template arguments that are just integer literals or pointers.
What is template template arguments and template typename arguments ?
The reason i write in policy based design is because this is the
requirement of the assignment.
My code so far:
[code]
#include "StoragePolicy.h"
template <typename T,
template <class>
class StoragePolicy = DefaultSPStorage,
template <class>
class OwnershipPolicy = RCPtr,
template <class>
class ConversionPolicy = DisallowConversion
>
class smart_ptr
{
T* operator->()
{
return aType;
}
T& operator*()
{
return *aType;
}
};
template <class aType>
class DefaultSPStorage
{
private:
/*
SmartPtr passes StoragePolicy<T>::T*
to Ownership- Policy.
*/
aType * pImpl;
public:
DefaultSPStorage () : pImpl(new aType())
{
}
explicit DefaultSPStorage<aType>(aType* pointee)
{
if (!pointee)
{
throw NullPointerException();
}
else
{
pImpl = pointee;
}
}
~DefaultSPStorage<aType>()
{
delete pImpl;
}
aType* operator->()
{
if (!pointee)
{
throw NullPointerException();
}
else
{
return pIpml;
}
}
aType& operator*()
{
if (!pointee)
{
throw NullPointerException();
}
else
{
return *pImpl;
}
}
aType* GetImpl(const DefaultSPStorage & that)
{
return that.pImpl;
}
aType& GetImplRef(const DefaultSPStorage & that)
{
return that.pImpl;
}
};
template <class sameType>
class RCPtr
{
private:
unsigned int* referenceCountPtr;
public:
RCPtr<sameType>() : refereceCountPtr(new unsigned int(1))
{
}
RCPtr<sameType>(const RCPtr & that)
{
unsigned int *temp = new unsigned int(1);
temp = that.referenceCountPtr;
referenceCountPtr = temp;
}
~RCPtr<sameType>()
{
delete referenceCountPtr;
}
void IncreaseRef()
{
*referenceCountPtr++;
}
void DecreaseRef()
{
*referenceCountPtr--;
}
/*
IncreaseRef
DecreaseRef
Realease
*/
/* The Ownership policy must support
intrusive as well as nonintrusive
reference counting.
Therefore, deallocation of memory is
called by function rather than
implicitly destructor called because
it can explicit called by user
*/
};
int main(int argc, char *argv[])
{
/* typedef smart_ptr<int,
DefaultSPStorage, RCPtr> aSmtPtr;
*/
smart_ptr<number, DefaultSPStorage, RCPtr> aSmtPtr;
return 0;
}
[/code]
I really need you all help.
Please help me.
A billion thanks in advance for your help.