2010-07-03 15:46:55 +00:00
|
|
|
#ifndef GAME_MWWORLD_PTR_H
|
|
|
|
#define GAME_MWWORLD_PTR_H
|
|
|
|
|
2012-06-29 14:48:50 +00:00
|
|
|
#include "cellstore.hpp"
|
2010-07-03 15:46:55 +00:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
2012-03-21 11:20:19 +00:00
|
|
|
class ContainerStore;
|
|
|
|
|
2010-07-03 15:46:55 +00:00
|
|
|
/// \brief Pointer to a LiveCellRef
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-03 15:46:55 +00:00
|
|
|
class Ptr
|
|
|
|
{
|
2013-08-13 13:42:02 +00:00
|
|
|
static const std::string sEmptyString;
|
|
|
|
|
2010-07-10 11:19:04 +00:00
|
|
|
public:
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2012-06-29 16:54:23 +00:00
|
|
|
typedef MWWorld::CellStore CellStore;
|
|
|
|
///< \deprecated
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2013-08-15 00:05:42 +00:00
|
|
|
MWWorld::LiveCellRefBase *mRef;
|
2010-07-10 11:19:04 +00:00
|
|
|
CellStore *mCell;
|
2012-03-21 11:20:19 +00:00
|
|
|
ContainerStore *mContainerStore;
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-03 15:46:55 +00:00
|
|
|
public:
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2013-08-15 00:05:42 +00:00
|
|
|
Ptr() : mRef(0), mCell(0), mContainerStore(0) { }
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-05 10:09:04 +00:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
2013-08-15 00:05:42 +00:00
|
|
|
return mRef == 0;
|
2010-07-27 12:43:46 +00:00
|
|
|
}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-08-03 09:14:57 +00:00
|
|
|
const std::string& getTypeName() const
|
|
|
|
{
|
2013-08-15 00:05:42 +00:00
|
|
|
return mRef ? mRef->mTypeName : sEmptyString;
|
2010-08-03 09:14:57 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 08:55:51 +00:00
|
|
|
Ptr (MWWorld::LiveCellRefBase *liveCellRef, CellStore *cell)
|
2012-03-21 11:20:19 +00:00
|
|
|
: mContainerStore (0)
|
2010-07-03 15:46:55 +00:00
|
|
|
{
|
2013-08-15 00:05:42 +00:00
|
|
|
mRef = liveCellRef;
|
2010-07-10 11:19:04 +00:00
|
|
|
mCell = cell;
|
2010-07-03 15:46:55 +00:00
|
|
|
}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-03 15:46:55 +00:00
|
|
|
template<typename T>
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<T> *get() const
|
2010-07-03 15:46:55 +00:00
|
|
|
{
|
2013-08-15 03:26:50 +00:00
|
|
|
MWWorld::LiveCellRef<T> *ref = dynamic_cast<MWWorld::LiveCellRef<T>*>(mRef);
|
|
|
|
if(ref) return ref;
|
2013-08-13 13:32:20 +00:00
|
|
|
|
|
|
|
std::stringstream str;
|
|
|
|
str<< "Bad LiveCellRef cast to "<<typeid(T).name()<<" from ";
|
2013-08-15 00:05:42 +00:00
|
|
|
if(mRef != 0) str<< mRef->mTypeName;
|
2013-08-13 13:32:20 +00:00
|
|
|
else str<< "an empty object";
|
|
|
|
|
|
|
|
throw std::runtime_error(str.str());
|
2010-07-03 15:46:55 +00:00
|
|
|
}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2012-03-21 11:29:07 +00:00
|
|
|
ESM::CellRef& getCellRef() const;
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2012-03-21 11:29:07 +00:00
|
|
|
RefData& getRefData() const;
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-10 11:19:04 +00:00
|
|
|
Ptr::CellStore *getCell() const
|
|
|
|
{
|
2013-05-15 15:54:18 +00:00
|
|
|
assert(mCell);
|
2010-07-10 11:19:04 +00:00
|
|
|
return mCell;
|
|
|
|
}
|
2012-03-21 11:20:19 +00:00
|
|
|
|
2012-05-15 16:05:53 +00:00
|
|
|
bool isInCell() const
|
|
|
|
{
|
2013-08-05 04:33:11 +00:00
|
|
|
return (mContainerStore == 0) && (mCell != 0);
|
2012-05-15 16:05:53 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 11:20:19 +00: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 15:46:55 +00:00
|
|
|
};
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-27 10:04:52 +00:00
|
|
|
inline bool operator== (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
2013-08-15 00:05:42 +00:00
|
|
|
return left.mRef==right.mRef;
|
2010-07-27 10:04:52 +00:00
|
|
|
}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-27 10:04:52 +00:00
|
|
|
inline bool operator!= (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return !(left==right);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator< (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
2013-08-15 00:05:42 +00:00
|
|
|
return left.mRef<right.mRef;
|
2010-07-27 10:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 15:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|