2010-07-03 15:46:55 +00:00
|
|
|
#ifndef GAME_MWWORLD_PTR_H
|
|
|
|
#define GAME_MWWORLD_PTR_H
|
|
|
|
|
|
|
|
#include <boost/any.hpp>
|
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
|
2010-07-03 15:46:55 +00:00
|
|
|
boost::any mPtr;
|
|
|
|
ESM::CellRef *mCellRef;
|
|
|
|
RefData *mRefData;
|
2010-07-10 11:19:04 +00:00
|
|
|
CellStore *mCell;
|
2010-08-03 09:14:57 +00:00
|
|
|
std::string mTypeName;
|
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
|
|
|
|
2012-03-21 11:20:19 +00:00
|
|
|
Ptr() : mCellRef (0), mRefData (0), mCell (0), mContainerStore (0) {}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-07-05 10:09:04 +00:00
|
|
|
bool isEmpty() const
|
|
|
|
{
|
|
|
|
return mPtr.empty();
|
|
|
|
}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2012-03-30 15:01:23 +00:00
|
|
|
const std::type_info& getType() const
|
2010-07-27 12:43:46 +00:00
|
|
|
{
|
|
|
|
assert (!mPtr.empty());
|
|
|
|
return mPtr.type();
|
|
|
|
}
|
2010-07-28 16:27:46 +00:00
|
|
|
|
2010-08-03 09:14:57 +00:00
|
|
|
const std::string& getTypeName() const
|
|
|
|
{
|
|
|
|
return mTypeName;
|
|
|
|
}
|
|
|
|
|
2010-07-03 15:46:55 +00:00
|
|
|
template<typename T>
|
2012-06-29 16:54:23 +00:00
|
|
|
Ptr (MWWorld::LiveCellRef<T> *liveCellRef, CellStore *cell)
|
2012-03-21 11:20:19 +00:00
|
|
|
: mContainerStore (0)
|
2010-07-03 15:46:55 +00:00
|
|
|
{
|
|
|
|
mPtr = liveCellRef;
|
2012-11-05 12:07:59 +00:00
|
|
|
mCellRef = &liveCellRef->mRef;
|
2010-07-03 15:46:55 +00:00
|
|
|
mRefData = &liveCellRef->mData;
|
2010-07-10 11:19:04 +00:00
|
|
|
mCell = cell;
|
2010-08-03 09:14:57 +00:00
|
|
|
mTypeName = typeid (T).name();
|
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
|
|
|
{
|
2012-06-29 16:54:23 +00:00
|
|
|
return boost::any_cast<MWWorld::LiveCellRef<T>*> (mPtr);
|
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
|
|
|
|
{
|
|
|
|
assert (mCell);
|
|
|
|
return mCell;
|
|
|
|
}
|
2012-03-21 11:20:19 +00:00
|
|
|
|
2012-05-15 16:05:53 +00:00
|
|
|
bool isInCell() const
|
|
|
|
{
|
|
|
|
return (mCell != 0);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return left.mRefData==right.mRefData;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
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 15:46:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|