FOX/ObjCryst++  2022
Undo.h
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2000- Vincent Favre-Nicolin vincefn@gmail.com
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef _OBJCRYST_UNDO_H_
20 #define _OBJCRYST_UNDO_H_
21 
22 #include <string>
23 #include <map>
24 // With C++11, could used std shared_ptr instead of boost
25 #include <boost/shared_ptr.hpp>
26 #include <boost/date_time.hpp>
27 
28 #include "ObjCryst/RefinableObj/IO.h"
29 #include "ObjCryst/ObjCryst/Crystal.h"
30 #include "ObjCryst/ObjCryst/PowderPattern.h"
31 #include "ObjCryst/ObjCryst/DiffractionDataSingleCrystal.h"
32 #include "ObjCryst/RefinableObj/GlobalOptimObj.h"
33 
34 namespace ObjCryst
35 {
40 class XMLConfig
41 {
42  public:
44  XMLConfig();
46  XMLConfig(const XMLConfig &old);
48  void Restore();
50  bool operator==(const XMLConfig &rhs) const;
52  bool operator!=(const XMLConfig &rhs) const;
54  const RefinableObjClock& GetClock() const;
55  protected:
56  std::map<Crystal*, boost::shared_ptr<std::string> > mvpCrystalXML;
57  std::map<PowderPattern*, boost::shared_ptr<std::string> > mvpPowderPatternXML;
58  std::map<DiffractionDataSingleCrystal*, boost::shared_ptr<std::string> > mvpDiffractionDataSingleCrystalXML;
59  std::map<OptimizationObj*, boost::shared_ptr<std::string> > mvpOptimizationObjXML;
60  boost::posix_time::ptime mTime;
63 };
64 
69 {
70  public:
74  XMLConfigHistory(const int maxnb=20);
78  bool Store();
80  void Restore(boost::shared_ptr<XMLConfig> &p);
82  std::list<boost::shared_ptr<XMLConfig> > GetList();
84  const std::list<boost::shared_ptr<XMLConfig> > GetList() const;
88  bool Previous();
92  bool Next();
93  private:
95  int mMaxNb;
97  std::list<boost::shared_ptr<XMLConfig> > mvpConfig;
100  boost::shared_ptr<XMLConfig> mpCurrentConfig;
102  bool mLock;
103 };
104 
107 
108 }
109 #endif //_OBJCRYST_UNDO_H_
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: doc-main.h:25
XMLConfigHistory gConfigHistory
Global object to hold configurations history.
Definition: Undo.cpp:26
Class to store & restore all top-level ObjCryst++ objects as their XML description.
Definition: Undo.h:41
RefinableObjClock mClock
Clock recording the creation of this XMLConfig.
Definition: Undo.h:62
XMLConfig()
Default cronstructor.
Definition: Undo.cpp:33
void Restore()
Restore the saved XML configuration.
Definition: Undo.cpp:177
bool operator!=(const XMLConfig &rhs) const
Non-equality operator.
Definition: Undo.cpp:345
bool operator==(const XMLConfig &rhs) const
Equality operator.
Definition: Undo.cpp:308
const RefinableObjClock & GetClock() const
Access the clock corresponding to the creation of this config.
Definition: Undo.cpp:350
Class to store XMLConfig configurations.
Definition: Undo.h:69
boost::shared_ptr< XMLConfig > mpCurrentConfig
The current configuration loaded (can be null if none is selected) This is reset every time a change ...
Definition: Undo.h:100
void Restore(boost::shared_ptr< XMLConfig > &p)
Restore a configuration.
Definition: Undo.cpp:391
XMLConfigHistory(const int maxnb=20)
Constructor.
Definition: Undo.cpp:358
std::list< boost::shared_ptr< XMLConfig > > GetList()
Access the list of configurations.
Definition: Undo.cpp:399
bool Next()
Reload the next (more recent) configuration in the list.
Definition: Undo.cpp:428
bool mLock
Lock used during Store and Restore.
Definition: Undo.h:102
std::list< boost::shared_ptr< XMLConfig > > mvpConfig
List of configurations.
Definition: Undo.h:97
int mMaxNb
Maximum number of stored configurations.
Definition: Undo.h:95
bool Store()
Store a new configuration.
Definition: Undo.cpp:362
bool Previous()
Reload the previous (older) configuration in the list.
Definition: Undo.cpp:403
We need to record exactly when refinable objects have been modified for the last time (to avoid re-co...
Definition: RefinableObj.h:140