OpenMW
apps/opencs/model/doc/savingstages.hpp
Go to the documentation of this file.
00001 #ifndef CSM_DOC_SAVINGSTAGES_H
00002 #define CSM_DOC_SAVINGSTAGES_H
00003 
00004 #include "stage.hpp"
00005 
00006 #include "../world/record.hpp"
00007 #include "../world/idcollection.hpp"
00008 
00009 #include "../filter/filter.hpp"
00010 
00011 #include "savingstate.hpp"
00012 
00013 namespace ESM
00014 {
00015     struct Dialogue;
00016 }
00017 
00018 namespace CSMWorld
00019 {
00020     class InfoCollection;
00021 }
00022 
00023 namespace CSMDoc
00024 {
00025     class Document;
00026     class SavingState;
00027 
00028     class OpenSaveStage : public Stage
00029     {
00030             Document& mDocument;
00031             SavingState& mState;
00032             bool mProjectFile;
00033 
00034         public:
00035 
00036             OpenSaveStage (Document& document, SavingState& state, bool projectFile);
00038 
00039             virtual int setup();
00041 
00042             virtual void perform (int stage, std::vector<std::string>& messages);
00044     };
00045 
00046     class WriteHeaderStage : public Stage
00047     {
00048             Document& mDocument;
00049             SavingState& mState;
00050             bool mSimple;
00051 
00052         public:
00053 
00054             WriteHeaderStage (Document& document, SavingState& state, bool simple);
00056 
00057             virtual int setup();
00059 
00060             virtual void perform (int stage, std::vector<std::string>& messages);
00062     };
00063 
00064 
00065     template<class CollectionT>
00066     class WriteCollectionStage : public Stage
00067     {
00068             const CollectionT& mCollection;
00069             SavingState& mState;
00070 
00071         public:
00072 
00073             WriteCollectionStage (const CollectionT& collection, SavingState& state);
00074 
00075             virtual int setup();
00077 
00078             virtual void perform (int stage, std::vector<std::string>& messages);
00080     };
00081 
00082     template<class CollectionT>
00083     WriteCollectionStage<CollectionT>::WriteCollectionStage (const CollectionT& collection,
00084         SavingState& state)
00085     : mCollection (collection), mState (state)
00086     {}
00087 
00088     template<class CollectionT>
00089     int WriteCollectionStage<CollectionT>::setup()
00090     {
00091         return mCollection.getSize();
00092     }
00093 
00094     template<class CollectionT>
00095     void WriteCollectionStage<CollectionT>::perform (int stage, std::vector<std::string>& messages)
00096     {
00097         CSMWorld::RecordBase::State state = mCollection.getRecord (stage).mState;
00098 
00099         if (state==CSMWorld::RecordBase::State_Modified ||
00100             state==CSMWorld::RecordBase::State_ModifiedOnly)
00101         {
00102             std::string type;
00103             for (int i=0; i<4; ++i)
00105                 type += reinterpret_cast<const char *> (&mCollection.getRecord (stage).mModified.sRecordId)[i];
00106 
00107             mState.getWriter().startRecord (type);
00108             mState.getWriter().writeHNCString ("NAME", mCollection.getId (stage));
00109             mCollection.getRecord (stage).mModified.save (mState.getWriter());
00110             mState.getWriter().endRecord (type);
00111         }
00112         else if (state==CSMWorld::RecordBase::State_Deleted)
00113         {
00115         }
00116     }
00117 
00118 
00119     class WriteDialogueCollectionStage : public Stage
00120     {
00121             Document& mDocument;
00122             SavingState& mState;
00123             const CSMWorld::IdCollection<ESM::Dialogue>& mTopics;
00124             CSMWorld::InfoCollection& mInfos;
00125 
00126         public:
00127 
00128             WriteDialogueCollectionStage (Document& document, SavingState& state, bool journal);
00129 
00130             virtual int setup();
00132 
00133             virtual void perform (int stage, std::vector<std::string>& messages);
00135     };
00136 
00137 
00138     class WriteRefIdCollectionStage : public Stage
00139     {
00140             Document& mDocument;
00141             SavingState& mState;
00142 
00143         public:
00144 
00145             WriteRefIdCollectionStage (Document& document, SavingState& state);
00146 
00147             virtual int setup();
00149 
00150             virtual void perform (int stage, std::vector<std::string>& messages);
00152     };
00153 
00154 
00155     class WriteFilterStage : public WriteCollectionStage<CSMWorld::IdCollection<CSMFilter::Filter> >
00156     {
00157             Document& mDocument;
00158             CSMFilter::Filter::Scope mScope;
00159 
00160         public:
00161 
00162             WriteFilterStage (Document& document, SavingState& state, CSMFilter::Filter::Scope scope);
00163 
00164             virtual void perform (int stage, std::vector<std::string>& messages);
00166     };
00167 
00168 
00169     class CloseSaveStage : public Stage
00170     {
00171             SavingState& mState;
00172 
00173         public:
00174 
00175             CloseSaveStage (SavingState& state);
00176 
00177             virtual int setup();
00179 
00180             virtual void perform (int stage, std::vector<std::string>& messages);
00182     };
00183 
00184     class FinalSavingStage : public Stage
00185     {
00186             Document& mDocument;
00187             SavingState& mState;
00188 
00189         public:
00190 
00191             FinalSavingStage (Document& document, SavingState& state);
00192 
00193             virtual int setup();
00195 
00196             virtual void perform (int stage, std::vector<std::string>& messages);
00198     };
00199 }
00200 
00201 #endif