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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class CGameHandler;
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
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:
|
2013-06-26 14:18:27 +03:00
|
|
|
ConstTransitivePtr(T *Ptr = nullptr)
|
2010-12-14 23:55:23 +02:00
|
|
|
: ptr(Ptr)
|
|
|
|
{}
|
2013-09-12 00:57:08 +03:00
|
|
|
ConstTransitivePtr(std::nullptr_t)
|
|
|
|
: ptr(nullptr)
|
|
|
|
{}
|
|
|
|
|
2010-12-14 23:55:23 +02:00
|
|
|
|
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;
|
2013-06-26 14:18:27 +03:00
|
|
|
ptr = nullptr;
|
2010-12-26 16:34:11 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
friend class ::CGameHandler;
|
2010-12-19 00:11:28 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|