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"
|
2013-08-15 01:21:43 -07:00
|
|
|
#include "livecellref.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
|
|
|
|
{
|
2010-07-10 13:19:04 +02:00
|
|
|
public:
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2013-08-14 17:05:42 -07:00
|
|
|
MWWorld::LiveCellRefBase *mRef;
|
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:
|
2013-08-15 04:52:01 -07:00
|
|
|
Ptr(MWWorld::LiveCellRefBase *liveCellRef=0, CellStore *cell=0)
|
|
|
|
: mRef(liveCellRef), mCell(cell), mContainerStore(0)
|
|
|
|
{
|
|
|
|
}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2010-07-05 12:09:04 +02:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
2013-08-14 17:05:42 -07:00
|
|
|
return mRef == 0;
|
2010-07-27 14:43:46 +02:00
|
|
|
}
|
2010-07-28 18:27:46 +02:00
|
|
|
|
2013-08-16 04:18:48 -07:00
|
|
|
const std::string& getTypeName() const;
|
|
|
|
|
|
|
|
const Class& getClass() const
|
2010-08-03 11:14:57 +02:00
|
|
|
{
|
2013-08-15 04:52:01 -07:00
|
|
|
if(mRef != 0)
|
2013-08-16 04:18:48 -07:00
|
|
|
return *(mRef->mClass);
|
|
|
|
throw std::runtime_error("Cannot get class of an empty object");
|
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-14 20:26:50 -07:00
|
|
|
MWWorld::LiveCellRef<T> *ref = dynamic_cast<MWWorld::LiveCellRef<T>*>(mRef);
|
|
|
|
if(ref) return ref;
|
2013-08-13 06:32:20 -07:00
|
|
|
|
|
|
|
std::stringstream str;
|
|
|
|
str<< "Bad LiveCellRef cast to "<<typeid(T).name()<<" from ";
|
2013-08-16 04:18:48 -07:00
|
|
|
if(mRef != 0) str<< getTypeName();
|
2013-08-13 06:32:20 -07:00
|
|
|
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
|
|
|
|
2014-01-31 13:25:32 +01:00
|
|
|
MWWorld::LiveCellRefBase *getBase() const;
|
|
|
|
|
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
|
|
|
|
2013-12-05 13:21:26 +01:00
|
|
|
CellStore *getCell() const
|
2010-07-10 13:19:04 +02:00
|
|
|
{
|
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.
|
2014-02-23 18:17:41 +01:00
|
|
|
|
|
|
|
operator const void *();
|
|
|
|
///< Return a 0-pointer, if Ptr is empty; return a non-0-pointer, if Ptr is not empty
|
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)
|
|
|
|
{
|
2013-08-14 17:05:42 -07:00
|
|
|
return left.mRef==right.mRef;
|
2010-07-27 12:04:52 +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==right);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator< (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
2013-08-14 17:05:42 -07:00
|
|
|
return left.mRef<right.mRef;
|
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 right<left;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator<= (const Ptr& left, const Ptr& right)
|
|
|
|
{
|
|
|
|
return !(left>right);
|
|
|
|
}
|
2010-07-03 17:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|