1 //------------------------------------------------------------------------------ 2 // emRecFileModel.h 3 // 4 // Copyright (C) 2005-2008,2010,2014,2018 Oliver Hamann. 5 // 6 // Homepage: http://eaglemode.sourceforge.net/ 7 // 8 // This program is free software: you can redistribute it and/or modify it under 9 // the terms of the GNU General Public License version 3 as published by the 10 // Free Software Foundation. 11 // 12 // This program is distributed in the hope that it will be useful, but WITHOUT 13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for 15 // more details. 16 // 17 // You should have received a copy of the GNU General Public License version 3 18 // along with this program. If not, see <http://www.gnu.org/licenses/>. 19 //------------------------------------------------------------------------------ 20 21 #ifndef emRecFileModel_h 22 #define emRecFileModel_h 23 24 #ifndef emRec_h 25 #include <emCore/emRec.h> 26 #endif 27 28 #ifndef emFileModel_h 29 #include <emCore/emFileModel.h> 30 #endif 31 32 33 //============================================================================== 34 //=============================== emRecFileModel =============================== 35 //============================================================================== 36 37 class emRecFileModel : public emFileModel { 38 39 public: 40 41 // Base class for an emFileModel where the data is an emRec. This class 42 // solves loading and saving of the record, and it provides a signal for 43 // getting informed about modifications of the record. In addition, the 44 // file state is automatically set to FS_UNSAVED on modifications. A 45 // derived class has to specify the record through calling PostConstruct 46 // from its constructor. Hint: There is a similar class which is not an 47 // emFileModel and which could be used for configuration files: 48 // emConfigModel. 49 50 const emSignal & GetChangeSignal() const; 51 // Signaled on every modification of the record. 52 53 protected: 54 55 emRecFileModel(emContext & context, const emString & name); 56 // Do not forget to call PostConstruct from an overloaded 57 // constructor. 58 59 void PostConstruct(emRec & rec); 60 // Must be called by the constructor of the derived class after 61 // the record has been constructed. 62 63 virtual ~emRecFileModel(); 64 // Destructor. 65 66 emRec & GetRec(); 67 // Not valid before PostConstruct has been called. 68 69 virtual void ResetData(); 70 virtual void TryStartLoading(); 71 virtual bool TryContinueLoading(); 72 virtual void QuitLoading(); 73 virtual void TryStartSaving(); 74 virtual bool TryContinueSaving(); 75 virtual void QuitSaving(); 76 virtual emUInt64 CalcMemoryNeed(); 77 virtual double CalcFileProgress(); 78 79 private: 80 81 class RecLink : public emRecListener { 82 public: 83 RecLink(emRecFileModel & model); 84 protected: 85 virtual void OnRecChanged(); 86 private: 87 emRecFileModel & Model; 88 }; 89 friend class RecLink; 90 91 emSignal ChangeSignal; 92 RecLink Link; 93 emRecFileReader * Reader; 94 emRecFileWriter * Writer; 95 int ProtectFileState; 96 emUInt64 MemoryNeed; 97 int MemoryNeedOutOfDate; 98 int ReadStep, ReadStepOfMemCalc; 99 }; 100 GetChangeSignal()101inline const emSignal & emRecFileModel::GetChangeSignal() const 102 { 103 return ChangeSignal; 104 } 105 GetRec()106inline emRec & emRecFileModel::GetRec() 107 { 108 return *Link.GetListenedRec(); 109 } 110 111 112 #endif 113