OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
record.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_ESMTOOL_RECORD_H
2 #define OPENMW_ESMTOOL_RECORD_H
3 
4 #include <string>
5 
7 
8 namespace ESM
9 {
10  class ESMReader;
11  class ESMWriter;
12 }
13 
14 namespace EsmTool
15 {
16  template <class T> class Record;
17 
18  class RecordBase
19  {
20  protected:
21  std::string mId;
22  uint32_t mFlags;
25 
26  public:
28  : mFlags(0)
29  , mPrintPlain(false)
30  {
31  }
32 
33  virtual ~RecordBase() {}
34 
35  virtual std::string getId() const = 0;
36 
37  uint32_t getFlags() const {
38  return mFlags;
39  }
40 
41  void setFlags(uint32_t flags) {
42  mFlags = flags;
43  }
44 
45  ESM::NAME getType() const {
46  return mType;
47  }
48 
49  void setPrintPlain(bool plain) {
50  mPrintPlain = plain;
51  }
52 
53  virtual void load(ESM::ESMReader &esm) = 0;
54  virtual void save(ESM::ESMWriter &esm) = 0;
55  virtual void print() = 0;
56 
57  static RecordBase *create(ESM::NAME type);
58 
59  // just make it a bit shorter
60  template <class T>
62  return static_cast<Record<T> *>(this);
63  }
64  };
65 
66  template <class T>
67  class Record : public RecordBase
68  {
69  T mData;
70  bool mIsDeleted;
71 
72  public:
74  : mIsDeleted(false)
75  {}
76 
77  std::string getId() const {
78  return mData.mId;
79  }
80 
81  T &get() {
82  return mData;
83  }
84 
85  void save(ESM::ESMWriter &esm) {
86  mData.save(esm, mIsDeleted);
87  }
88 
89  void load(ESM::ESMReader &esm) {
90  mData.load(esm, mIsDeleted);
91  }
92 
93  void print();
94  };
95 
96  template<> std::string Record<ESM::Cell>::getId() const;
97  template<> std::string Record<ESM::Land>::getId() const;
98  template<> std::string Record<ESM::MagicEffect>::getId() const;
99  template<> std::string Record<ESM::Pathgrid>::getId() const;
100  template<> std::string Record<ESM::Skill>::getId() const;
101 
102  template<> void Record<ESM::Activator>::print();
103  template<> void Record<ESM::Potion>::print();
104  template<> void Record<ESM::Armor>::print();
105  template<> void Record<ESM::Apparatus>::print();
106  template<> void Record<ESM::BodyPart>::print();
107  template<> void Record<ESM::Book>::print();
108  template<> void Record<ESM::BirthSign>::print();
109  template<> void Record<ESM::Cell>::print();
110  template<> void Record<ESM::Class>::print();
111  template<> void Record<ESM::Clothing>::print();
112  template<> void Record<ESM::Container>::print();
113  template<> void Record<ESM::Creature>::print();
114  template<> void Record<ESM::Dialogue>::print();
115  template<> void Record<ESM::Door>::print();
116  template<> void Record<ESM::Enchantment>::print();
117  template<> void Record<ESM::Faction>::print();
118  template<> void Record<ESM::Global>::print();
119  template<> void Record<ESM::GameSetting>::print();
120  template<> void Record<ESM::DialInfo>::print();
121  template<> void Record<ESM::Ingredient>::print();
122  template<> void Record<ESM::Land>::print();
123  template<> void Record<ESM::CreatureLevList>::print();
124  template<> void Record<ESM::ItemLevList>::print();
125  template<> void Record<ESM::Light>::print();
126  template<> void Record<ESM::Lockpick>::print();
127  template<> void Record<ESM::Probe>::print();
128  template<> void Record<ESM::Repair>::print();
129  template<> void Record<ESM::LandTexture>::print();
130  template<> void Record<ESM::MagicEffect>::print();
131  template<> void Record<ESM::Miscellaneous>::print();
132  template<> void Record<ESM::NPC>::print();
133  template<> void Record<ESM::Pathgrid>::print();
134  template<> void Record<ESM::Race>::print();
135  template<> void Record<ESM::Region>::print();
136  template<> void Record<ESM::Script>::print();
137  template<> void Record<ESM::Skill>::print();
138  template<> void Record<ESM::SoundGenerator>::print();
139  template<> void Record<ESM::Sound>::print();
140  template<> void Record<ESM::Spell>::print();
141  template<> void Record<ESM::StartScript>::print();
142  template<> void Record<ESM::Static>::print();
143  template<> void Record<ESM::Weapon>::print();
144 }
145 
146 #endif
virtual void load(ESM::ESMReader &esm)=0
Definition: record.hpp:18
Definition: record.hpp:16
ESM::NAME getType() const
Definition: record.hpp:45
uint32_t getFlags() const
Definition: record.hpp:37
Definition: esmreader.hpp:21
static RecordBase * create(ESM::NAME type)
Definition: record.cpp:178
Definition: esmcommon.hpp:89
Record()
Definition: record.hpp:73
void setFlags(uint32_t flags)
Definition: record.hpp:41
Definition: esmwriter.hpp:17
bool mIsDeleted
Definition: record.hpp:70
std::string getId() const
Definition: record.hpp:77
std::string mId
Definition: record.hpp:21
void save(ESM::ESMWriter &esm)
Definition: record.hpp:85
Record< T > * cast()
Definition: record.hpp:61
virtual ~RecordBase()
Definition: record.hpp:33
virtual std::string getId() const =0
virtual void save(ESM::ESMWriter &esm)=0
virtual void print()=0
void load(ESM::ESMReader &esm)
Definition: record.hpp:89
void setPrintPlain(bool plain)
Definition: record.hpp:49
uint32_t mFlags
Definition: record.hpp:22
RecordBase()
Definition: record.hpp:27
bool mPrintPlain
Definition: record.hpp:24
ESM::NAME mType
Definition: record.hpp:23
T mData
Definition: record.hpp:69