OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
livecellref.hpp
Go to the documentation of this file.
1 #ifndef GAME_MWWORLD_LIVECELLREF_H
2 #define GAME_MWWORLD_LIVECELLREF_H
3 
4 #include <typeinfo>
5 
6 #include "cellref.hpp"
7 
8 #include "refdata.hpp"
9 
10 namespace ESM
11 {
12  struct ObjectState;
13 }
14 
15 namespace MWWorld
16 {
17  class Ptr;
18  class ESMStore;
19  class Class;
20 
23  {
24  const Class *mClass;
25 
30 
33 
34  LiveCellRefBase(const std::string& type, const ESM::CellRef &cref=ESM::CellRef());
35  /* Need this for the class to be recognized as polymorphic */
36  virtual ~LiveCellRefBase() { }
37 
38  virtual void load (const ESM::ObjectState& state) = 0;
42 
43  virtual void save (ESM::ObjectState& state) const = 0;
45 
46  protected:
47 
48  void loadImp (const ESM::ObjectState& state);
53 
54  void saveImp (ESM::ObjectState& state) const;
56 
57  static bool checkStateImp (const ESM::ObjectState& state);
63  };
64 
65  inline bool operator== (const LiveCellRefBase& cellRef, const ESM::RefNum refNum)
66  {
67  return cellRef.mRef.getRefNum()==refNum;
68  }
69 
76  template <typename X>
77  struct LiveCellRef : public LiveCellRefBase
78  {
79  LiveCellRef(const ESM::CellRef& cref, const X* b = NULL)
80  : LiveCellRefBase(typeid(X).name(), cref), mBase(b)
81  {}
82 
83  LiveCellRef(const X* b = NULL)
84  : LiveCellRefBase(typeid(X).name()), mBase(b)
85  {}
86 
87  // The object that this instance is based on.
88  const X* mBase;
89 
90  virtual void load (const ESM::ObjectState& state);
94 
95  virtual void save (ESM::ObjectState& state) const;
97 
98  static bool checkState (const ESM::ObjectState& state);
104  };
105 
106  template <typename X>
108  {
109  loadImp (state);
110  }
111 
112  template <typename X>
114  {
115  saveImp (state);
116  }
117 
118  template <typename X>
120  {
121  return checkStateImp (state);
122  }
123 
124 }
125 
126 #endif
Used to create pointers to hold any type of LiveCellRef<> object.
Definition: livecellref.hpp:22
Encapsulated variant of ESM::CellRef with change tracking.
Definition: cellref.hpp:15
bool operator==(const LiveCellRef< X > &ref, int pRefnum)
Definition: cellstore.cpp:205
virtual void load(const ESM::ObjectState &state)
Definition: livecellref.hpp:107
virtual void save(ESM::ObjectState &state) const
Save LiveCellRef state into state.
Definition: livecellref.hpp:113
LiveCellRef(const X *b=NULL)
Definition: livecellref.hpp:83
MWWorld::CellRef mRef
Definition: livecellref.hpp:29
Definition: livecellref.hpp:77
const Class * mClass
Definition: livecellref.hpp:24
Definition: refdata.hpp:29
LiveCellRef(const ESM::CellRef &cref, const X *b=NULL)
Definition: livecellref.hpp:79
RefData mData
Definition: livecellref.hpp:32
Base class for referenceable esm records.
Definition: class.hpp:52
Definition: cellref.hpp:14
void saveImp(ESM::ObjectState &state) const
Save LiveCellRef state into state.
Definition: livecellref.cpp:53
virtual void save(ESM::ObjectState &state) const =0
Save LiveCellRef state into state.
<
Definition: objectstate.hpp:19
static bool checkStateImp(const ESM::ObjectState &state)
Definition: livecellref.cpp:64
LiveCellRefBase(const std::string &type, const ESM::CellRef &cref=ESM::CellRef())
Definition: livecellref.cpp:14
const X * mBase
Definition: livecellref.hpp:88
void loadImp(const ESM::ObjectState &state)
Definition: livecellref.cpp:19
Definition: cellref.hpp:34
virtual ~LiveCellRefBase()
Definition: livecellref.hpp:36
static bool checkState(const ESM::ObjectState &state)
Definition: livecellref.hpp:119
const ESM::RefNum & getRefNum() const
Definition: cellref.cpp:8
virtual void load(const ESM::ObjectState &state)=0
const char * name
Definition: crashcatcher.cpp:59