2010-12-14 23:55:23 +02:00
|
|
|
#pragma once
|
|
|
|
|
2010-12-26 16:34:11 +02:00
|
|
|
class CGameHandler;
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
/*
|
|
|
|
* ConstTransitivePtr.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-12-14 23:55:23 +02:00
|
|
|
template <typename T>
|
|
|
|
class ConstTransitivePtr
|
|
|
|
{
|
|
|
|
T *ptr;
|
2010-12-26 16:34:11 +02:00
|
|
|
ConstTransitivePtr(const T *Ptr)
|
|
|
|
: ptr(const_cast<T*>(Ptr))
|
|
|
|
{}
|
2010-12-14 23:55:23 +02:00
|
|
|
public:
|
2010-12-17 00:32:53 +02:00
|
|
|
ConstTransitivePtr(T *Ptr = NULL)
|
2010-12-14 23:55:23 +02:00
|
|
|
: ptr(Ptr)
|
|
|
|
{}
|
|
|
|
|
2010-12-17 20:47:07 +02:00
|
|
|
const T& operator*() const
|
|
|
|
{
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
T& operator*()
|
|
|
|
{
|
|
|
|
return *ptr;
|
|
|
|
}
|
2010-12-14 23:55:23 +02:00
|
|
|
operator const T*() const
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
2010-12-19 00:11:28 +02:00
|
|
|
T* get()
|
2010-12-17 20:47:07 +02:00
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
2010-12-19 00:11:28 +02:00
|
|
|
const T* get() const
|
2010-12-17 20:47:07 +02:00
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
2010-12-14 23:55:23 +02:00
|
|
|
operator T*()
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
T *operator->()
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
const T *operator->() const
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
2011-02-04 16:58:14 +02:00
|
|
|
const T*operator=(T *t)
|
|
|
|
{
|
|
|
|
return ptr = t;
|
|
|
|
}
|
2010-12-14 23:55:23 +02:00
|
|
|
|
2010-12-26 16:34:11 +02:00
|
|
|
void dellNull()
|
|
|
|
{
|
|
|
|
delete ptr;
|
|
|
|
ptr = NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-14 23:55:23 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & ptr;
|
|
|
|
}
|
2010-12-26 16:34:11 +02:00
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
friend class CGameHandler;
|
2010-12-19 00:11:28 +02:00
|
|
|
};
|