mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-28 23:06:24 +02:00
ff635edc0b
preparation for having client and server in a single process
84 lines
1.2 KiB
C++
84 lines
1.2 KiB
C++
/*
|
|
* 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
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
class CGameHandler;
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
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;
|
|
};
|
|
|
|
VCMI_LIB_NAMESPACE_END
|