2010-07-03 17:46:55 +02:00
|
|
|
#ifndef GAME_MWWORLD_PTR_H
|
|
|
|
#define GAME_MWWORLD_PTR_H
|
|
|
|
|
2012-06-29 16:48:50 +02:00
|
|
|
#include "cellstore.hpp"
|
2010-07-03 17:46:55 +02:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
2012-03-21 12:20:19 +01:00
|
|
|
class ContainerStore;
|
|
|
|
|
2010-07-03 17:46:55 +02:00
|
|
|
/// \brief Pointer to a LiveCellRef
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-03 17:46:55 +02:00
|
|
|
class Ptr
|
|
|
|
{
|
2013-08-13 06:42:02 -07:00
|
|
|
static const std::string sEmptyString;
|
|
|
|
|
2010-07-10 13:19:04 +02:00
|
|
|
public:
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2012-06-29 18:54:23 +02:00
|
|
|
typedef MWWorld::CellStore CellStore;
|
|
|
|
///< \deprecated
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2013-08-13 06:32:20 -07:00
|
|
|
MWWorld::LiveCellRefBase *mPtr;
|
2010-07-03 17:46:55 +02:00
|
|
|
ESM::CellRef *mCellRef;
|
|
|
|
RefData *mRefData;
|
2010-07-10 13:19:04 +02:00
|
|
|
CellStore *mCell;
|
2012-03-21 12:20:19 +01:00
|
|
|
ContainerStore *mContainerStore;
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-03 17:46:55 +02:00
|
|
|
public:
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2013-08-13 06:32:20 -07:00
|
|
|
Ptr() : mPtr (0), mCellRef (0), mRefData (0), mCell (0), mContainerStore (0) {}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-05 12:09:04 +02:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
2013-08-13 06:32:20 -07:00
|
|
|
return mPtr == 0;
|
2010-07-27 14:43:46 +02:00
|
|
|
}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-08-03 11:14:57 +02:00
|
|
|
const std::string& getTypeName() const
|
|
|
|
{
|
2013-08-13 06:42:02 -07:00
|
|
|
return mPtr ? mPtr->mTypeName : sEmptyString;
|
2010-08-03 11:14:57 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 01:55:51 -07:00
|
|
|
Ptr (MWWorld::LiveCellRefBase *liveCellRef, CellStore *cell)
|
2012-03-21 12:20:19 +01:00
|
|
|
: mContainerStore (0)
|
2010-07-03 17:46:55 +02:00
|
|
|
{
|
|
|
|
mPtr = liveCellRef;
|
2012-11-05 16:07:59 +04:00
|
|
|
mCellRef = &liveCellRef->mRef;
|
2010-07-03 17:46:55 +02:00
|
|
|
mRefData = &liveCellRef->mData;
|
2010-07-10 13:19:04 +02:00
|
|
|
mCell = cell;
|
2010-07-03 17:46:55 +02:00
|
|
|
}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-03 17:46:55 +02:00
|
|
|
template<typename T>
|
2012-06-29 18:54:23 +02:00
|
|
|
MWWorld::LiveCellRef<T> *get() const
|
2010-07-03 17:46:55 +02:00
|
|
|
{
|
2013-08-13 06:32:20 -07:00
|
|
|
if(mPtr && mPtr->mTypeName == typeid(T).name())
|
|
|
|
return static_cast<MWWorld::LiveCellRef<T>*>(mPtr);
|
|
|
|
|
|
|
|
std::stringstream str;
|
|
|
|
str<< "Bad LiveCellRef cast to "<<typeid(T).name()<<" from ";
|
|
|
|
if(mPtr != 0) str<< mPtr->mTypeName;
|
|
|
|
else str<< "an empty object";
|
|
|
|
|
|
|
|
throw std::runtime_error(str.str());
|
2010-07-03 17:46:55 +02:00
|
|
|
}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2012-03-21 12:29:07 +01:00
|
|
|
ESM::CellRef& getCellRef() const;
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2012-03-21 12:29:07 +01:00
|
|
|
RefData& getRefData() const;
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-10 13:19:04 +02:00
|
|
|
Ptr::CellStore *getCell() const
|
|
|
|
{
|
2013-05-15 17:54:18 +02:00
|
|
|
assert(mCell);
|
2010-07-10 13:19:04 +02:00
|
|
|
return mCell;
|
|
|
|
}
|
2012-03-21 12:20:19 +01:00
|
|
|
|
2012-05-15 18:05:53 +02:00
|
|
|
bool isInCell() const
|
|
|
|
{
|
2013-08-04 21:33:11 -07:00
|
|
|
return (mContainerStore == 0) && (mCell != 0);
|
2012-05-15 18:05:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 12:20:19 +01:00
|
|
|
void setContainerStore (ContainerStore *store);
|
|
|
|
///< Must not be called on references that are in a cell.
|
|
|
|
|
|
|
|
ContainerStore *getContainerStore() const;
|
|
|
|
///< May return a 0-pointer, if reference is not in a container.
|
2010-07-03 17:46:55 +02:00
|
|
|
};
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-27 12:04:52 +02:00
|
|
|
inline bool operator== (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return left.mRefData==right.mRefData;
|
|
|
|
}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-27 12:04:52 +02:00
|
|
|
inline bool operator!= (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return !(left==right);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator< (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return left.mRefData<right.mRefData;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator>= (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return !(left<right);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator> (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return right<left;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<= (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return !(left>right);
|
|
|
|
}
|
2010-07-03 17:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|