diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index 28c1bb5c27..fbfe77dd77 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -1,6 +1,8 @@ #ifndef GAME_MWWORLD_LIVECELLREF_H #define GAME_MWWORLD_LIVECELLREF_H +#include + #include #include "refdata.hpp" @@ -10,6 +12,15 @@ namespace MWWorld class Ptr; class ESMStore; + /// Used to create pointers to hold any type of LiveCellRef<> object. + struct LiveCellRefBase + { + std::string mTypeName; + + LiveCellRefBase(std::string type) : mTypeName(type) + { } + }; + /// A reference to one object (of any type) in a cell. /// /// Constructing this with a CellRef instance in the constructor means that @@ -17,14 +28,14 @@ namespace MWWorld /// across to mData. If later adding data (such as position) to CellRef /// this would have to be manually copied across. template - struct LiveCellRef + struct LiveCellRef : public LiveCellRefBase { LiveCellRef(const ESM::CellRef& cref, const X* b = NULL) - : mBase(b), mRef(cref), mData(mRef) + : LiveCellRefBase(typeid(X).name()), mBase(b), mRef(cref), mData(mRef) {} LiveCellRef(const X* b = NULL) - : mBase(b), mData(mRef) + : LiveCellRefBase(typeid(X).name()), mBase(b), mData(mRef) {} // The object that this instance is based on. diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 2cb92ce2f8..de1064b2b6 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -1,8 +1,6 @@ #ifndef GAME_MWWORLD_PTR_H #define GAME_MWWORLD_PTR_H -#include - #include "cellstore.hpp" namespace MWWorld @@ -18,7 +16,7 @@ namespace MWWorld typedef MWWorld::CellStore CellStore; ///< \deprecated - boost::any mPtr; + MWWorld::LiveCellRefBase *mPtr; ESM::CellRef *mCellRef; RefData *mRefData; CellStore *mCell; @@ -27,17 +25,11 @@ namespace MWWorld public: - Ptr() : mCellRef (0), mRefData (0), mCell (0), mContainerStore (0) {} + Ptr() : mPtr (0), mCellRef (0), mRefData (0), mCell (0), mContainerStore (0) {} bool isEmpty() const { - return mPtr.empty(); - } - - const std::type_info& getType() const - { - assert (!mPtr.empty()); - return mPtr.type(); + return mPtr == 0; } const std::string& getTypeName() const @@ -59,7 +51,15 @@ namespace MWWorld template MWWorld::LiveCellRef *get() const { - return boost::any_cast*> (mPtr); + if(mPtr && mPtr->mTypeName == typeid(T).name()) + return static_cast*>(mPtr); + + std::stringstream str; + str<< "Bad LiveCellRef cast to "<mTypeName; + else str<< "an empty object"; + + throw std::runtime_error(str.str()); } ESM::CellRef& getCellRef() const;