OpenMW
apps/esmtool/record.hpp
Go to the documentation of this file.
00001 #ifndef OPENMW_ESMTOOL_RECORD_H
00002 #define OPENMW_ESMTOOL_RECORD_H
00003 
00004 #include <string>
00005 
00006 #include <components/esm/records.hpp>
00007 
00008 namespace ESM
00009 {
00010     class ESMReader;
00011     class ESMWriter;
00012 }
00013 
00014 namespace EsmTool
00015 {
00016     template <class T> class Record;
00017 
00018     class RecordBase
00019     {
00020     protected:
00021         std::string mId;
00022         int mFlags;
00023         ESM::NAME mType;
00024         bool mPrintPlain;
00025 
00026     public:
00027         RecordBase ()
00028           : mFlags(0)
00029           , mPrintPlain(false)
00030         {
00031         }
00032 
00033         virtual ~RecordBase() {}
00034 
00035         const std::string &getId() const {
00036             return mId;
00037         }
00038 
00039         void setId(const std::string &id) { 
00040             mId = id;
00041         }
00042 
00043         int getFlags() const {
00044             return mFlags;
00045         }
00046 
00047         void setFlags(int flags) {
00048             mFlags = flags;
00049         }
00050 
00051         ESM::NAME getType() const {
00052             return mType;
00053         }
00054 
00055         bool getPrintPlain() const {
00056                 return mPrintPlain;
00057         }
00058 
00059         void setPrintPlain(bool plain) {
00060                 mPrintPlain = plain;
00061         }
00062 
00063         virtual void load(ESM::ESMReader &esm) = 0;
00064         virtual void save(ESM::ESMWriter &esm) = 0;
00065         virtual void print() = 0;
00066 
00067         static RecordBase *create(ESM::NAME type);
00068 
00069         // just make it a bit shorter
00070         template <class T>
00071         Record<T> *cast() {
00072             return static_cast<Record<T> *>(this);
00073         }
00074     };
00075 
00076     template <class T>
00077     class Record : public RecordBase
00078     {
00079         T mData;
00080 
00081     public:
00082         T &get() {
00083             return mData;
00084         }
00085 
00086         void save(ESM::ESMWriter &esm) {
00087             mData.save(esm);
00088         }
00089 
00090         void load(ESM::ESMReader &esm) {
00091             mData.load(esm);
00092         }
00093 
00094         void print();
00095     };
00096 
00097     template<> void Record<ESM::Activator>::print();
00098     template<> void Record<ESM::Potion>::print();
00099     template<> void Record<ESM::Armor>::print();
00100     template<> void Record<ESM::Apparatus>::print();
00101     template<> void Record<ESM::BodyPart>::print();
00102     template<> void Record<ESM::Book>::print();
00103     template<> void Record<ESM::BirthSign>::print();
00104     template<> void Record<ESM::Cell>::print();
00105     template<> void Record<ESM::Class>::print();
00106     template<> void Record<ESM::Clothing>::print();
00107     template<> void Record<ESM::Container>::print();
00108     template<> void Record<ESM::Creature>::print();
00109     template<> void Record<ESM::Dialogue>::print();
00110     template<> void Record<ESM::Door>::print();
00111     template<> void Record<ESM::Enchantment>::print();
00112     template<> void Record<ESM::Faction>::print();
00113     template<> void Record<ESM::Global>::print();
00114     template<> void Record<ESM::GameSetting>::print();
00115     template<> void Record<ESM::DialInfo>::print();
00116     template<> void Record<ESM::Ingredient>::print();
00117     template<> void Record<ESM::Land>::print();
00118     template<> void Record<ESM::CreatureLevList>::print();
00119     template<> void Record<ESM::ItemLevList>::print();
00120     template<> void Record<ESM::Light>::print();
00121     template<> void Record<ESM::Lockpick>::print();
00122     template<> void Record<ESM::Probe>::print();
00123     template<> void Record<ESM::Repair>::print();
00124     template<> void Record<ESM::LandTexture>::print();
00125     template<> void Record<ESM::MagicEffect>::print();
00126     template<> void Record<ESM::Miscellaneous>::print();
00127     template<> void Record<ESM::NPC>::print();
00128     template<> void Record<ESM::Pathgrid>::print();
00129     template<> void Record<ESM::Race>::print();
00130     template<> void Record<ESM::Region>::print();
00131     template<> void Record<ESM::Script>::print();
00132     template<> void Record<ESM::Skill>::print();
00133     template<> void Record<ESM::SoundGenerator>::print();
00134     template<> void Record<ESM::Sound>::print();
00135     template<> void Record<ESM::Spell>::print();
00136     template<> void Record<ESM::StartScript>::print();
00137     template<> void Record<ESM::Static>::print();
00138     template<> void Record<ESM::Weapon>::print();
00139 }
00140 
00141 #endif