1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00
vcmi/lib/ConstTransitivePtr.h
Michał W. Urbańczyk b62bb096a7 Fixed #1430, work-around to make #1435 non-crashing.
Fixed at least one of the #1428 infinite turns cases.
2013-09-11 21:57:08 +00:00

81 lines
1.1 KiB
C++

#pragma once
class CGameHandler;
/*
* 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
*
*/
template <typename T>
class ConstTransitivePtr
{
T *ptr;
ConstTransitivePtr(const T *Ptr)
: ptr(const_cast<T*>(Ptr))
{}
public:
ConstTransitivePtr(T *Ptr = nullptr)
: ptr(Ptr)
{}
ConstTransitivePtr(std::nullptr_t)
: ptr(nullptr)
{}
const T& operator*() const
{
return *ptr;
}
T& operator*()
{
return *ptr;
}
operator const T*() const
{
return ptr;
}
T* get()
{
return ptr;
}
const T* get() const
{
return ptr;
}
operator T*()
{
return ptr;
}
T *operator->()
{
return ptr;
}
const T *operator->() const
{
return ptr;
}
const T*operator=(T *t)
{
return ptr = t;
}
void dellNull()
{
delete ptr;
ptr = nullptr;
}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ptr;
}
friend class CGameHandler;
};