#ifndef __POINTER_AMV
#define __POINTER_AMV
namespace amv {
template <class type>
class ipointer {
type *ptype;
public:
ipointer(): ptype(0)
{
}
ipointer(const ipointer &p)
{
if(p.ptype)
ptype=p->clone();
else
ptype=0;
}
ipointer(type *p)
{
ptype=p;
}
ipointer(const type &t)
{
ptype=new type(t);
}
~ipointer()
{
delete ptype;
}
void untie()
{
ptype=0;
}
ipointer &operator=(const ipointer &p)
{
delete ptype;
if(p.ptype)
ptype=p->clone();
else
ptype=0;
return *this;
}
ipointer &operator=(type *p)
{
delete ptype;
ptype=p;
return *this;
}
ipointer &operator=(const type &t)
{
delete ptype;
ptype=new type(t);
return *this;
}
type &operator*()
{
return *ptype;
}
const type &operator*() const
{
return *ptype;
}
type *operator->()
{
return ptype;
}
const type *operator->() const
{
return ptype;
}
operator bool() const
{
return ptype;
}
operator type *() const
{
return ptype;
}
operator type *()
{
return ptype;
}
};
template <class type>
class pointer {
type *ptype;
public:
pointer(): ptype(0)
{
}
pointer(const pointer &p)
{
if(p.ptype)
ptype=new type(*p);
else
ptype=0;
}
pointer(type *p)
{
ptype=p;
}
pointer(const type &t)
{
ptype=new type(t);
}
~pointer()
{
delete ptype;
}
void untie()
{
ptype=0;
}
pointer &operator=(const pointer &p)
{
delete ptype;
if(p.ptype)
ptype=new type(*p);
else
ptype=0;
return *this;
}
pointer &operator=(type *p)
{
delete ptype;
ptype=p;
return *this;
}
pointer &operator=(const type &t)
{
delete ptype;
ptype=new type(t);
return *this;
}
type &operator*()
{
return *ptype;
}
const type &operator*() const
{
return *ptype;
}
type *operator->()
{
return ptype;
}
const type *operator->() const
{
return ptype;
}
operator bool() const
{
return ptype;
}
operator type *() const
{
return ptype;
}
operator type *()
{
return ptype;
}
};
}
#endif