VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtRecordSettingsBackup.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include <vrvCore/DtDe.h>
15 
16 namespace makVrv
17 {
18  class DtElementDefinitionManager;
19 
24  {
25  public:
26  DtRecordSettingsBackupInterface(DtDe& de, const std::string& classType, const std::string& descriptiveName)
27  : myDe(de)
28  , myClassType(classType)
29  , myDescriptiveName(descriptiveName)
30  , myCanBackup(true)
31  {
32  DtDeSettings* settings = DtDeSettingsManager::instance(myDe).findSettings(classType);
33  if (settings)
34  {
35  setFactoryFile(settings->factoryFilePath());
36  }
38  }
39 
41  : myDe(orig.myDe)
42  , myClassType(orig.myClassType)
43  , myCanBackup(orig.myCanBackup)
44  , myDescriptiveName(orig.myDescriptiveName)
45  {
46  }
47 
49  {
50  }
51 
52  std::string backupClassType() const
53  {
54  return myClassType;
55  }
56 
57  std::string backupName() const
58  {
59  return myDescriptiveName;
60  }
61 
62  virtual void backup()
63  {
64  if (canBackup())
65  {
67  }
68  }
69 
70  virtual void backupByDir()
71  {
72  if (canBackup())
73  {
75  }
76  }
77 
78  void setCanBackup(bool b)
79  {
80  myCanBackup = b;
81  }
82 
83  bool canBackup() const
84  {
85  return myCanBackup;
86  }
87 
88  protected:
90  std::string myClassType;
91  std::string myDescriptiveName;
93  };
94 
95 
96 
100  template <typename SettingsClass, typename ArchiveClass>
102  {
103  public:
104  DtRecordSettingsBackup(DtDe& de, SettingsClass* parent, const std::string& classType, const std::string& descriptiveName)
105  : DtRecordSettingsBackupInterface(de, classType, descriptiveName)
106  , myParent(parent)
107  {
108  }
109 
112  , myParent(orig.myParent)
113  {
114  }
115 
117  {
118  }
119 
120  void restore(const DtSettingsBackup* from)
121  {
122  bool can = canBackup();
123 
124  setCanBackup(false);
125 
126  myParent->setFromRecord(
128 
129  setCanBackup(can);
130  }
131 
133  {
135  }
136 
137  void write(boost::archive::xml_oarchive& ar)
138  {
139  ArchiveClass rec;
140 
141  myParent->getRecord(rec);
142 
143  ar << boost::serialization::make_nvp(myClassType.c_str(), rec);
144  }
145 
146  template<class Q = SettingsClass>
147  typename std::enable_if<!std::is_same<Q, DtElementDefinitionManager>::value, void>::type writeDirSpecialised( std::vector<std::ostringstream*>& outStreamVec, std::vector<std::string>& fileNames )
148  {
149  // intentional no-op, only implemented for DtElementDefinitionManager
150  }
151 
152  template<class Q = SettingsClass>
153  typename std::enable_if<std::is_same<Q, DtElementDefinitionManager>::value, void>::type writeDirSpecialised( std::vector<std::ostringstream*>& outStreamVec, std::vector<std::string>& fileNames )
154  {
155  std::vector<ArchiveClass> rec;
156 
157  myParent->getSplitRecord( rec, fileNames );
158 
159  assert( rec.size() == fileNames.size() );
160 
161  unsigned int recSize = rec.size();
162  outStreamVec.resize( recSize );
163 
164  for( unsigned int i = 0; i < recSize; ++i )
165  {
166  outStreamVec[i] = new std::ostringstream();
167  boost::archive::xml_oarchive oa( *(outStreamVec[i]) );
168 
169  oa << boost::serialization::make_nvp( myClassType.c_str(), rec[i] );
170  }
171  }
172 
173  // Allocates the outStreamVec, delete after use - use vec<ptr> for Linux build
174  void writeDir(std::vector<std::ostringstream*>& outStreamVec, std::vector<std::string>& fileNames)
175  {
176  writeDirSpecialised( outStreamVec, fileNames );
177  }
178 
179  void readRecords(boost::archive::xml_iarchive& ar, ArchiveClass& recordsResult)
180  {
181  ar >> boost::serialization::make_nvp(myClassType.c_str(), recordsResult);
182  }
183 
184  template<class Q = SettingsClass>
185  typename std::enable_if<!std::is_same<Q, DtElementDefinitionManager>::value, void>::type readIncrementalSpecialised( boost::archive::xml_iarchive& ar )
186  {
187  // intentional no-op, only implemented for DtElementDefinitionManager
188  }
189 
190  template<class Q = SettingsClass>
191  typename std::enable_if<std::is_same<Q, DtElementDefinitionManager>::value, void>::type readIncrementalSpecialised( boost::archive::xml_iarchive& ar )
192  {
193  ArchiveClass rec;
194  myParent->enableFilePathReadWriteOnRecord( rec );
195  ar >> boost::serialization::make_nvp( myClassType.c_str(), rec );
196  myParent->addRecords( rec, myRestoredRecord );
197  }
198 
199  virtual void readIncremental( boost::archive::xml_iarchive& ar )
200  {
202  }
203 
204  void read(boost::archive::xml_iarchive& ar)
205  {
206  ar >> boost::serialization::make_nvp(myClassType.c_str(), myRestoredRecord);
207  }
208 
209  const ArchiveClass& restoredRecord() const
210  {
211  return myRestoredRecord;
212  }
213 
214  protected:
215  ArchiveClass myRestoredRecord;
216  SettingsClass* myParent;
217  };
218 
222  template <typename SettingsClass, typename ArchiveClass>
224  {
225  public:
226 
227  DtSharedRecordSettingsBackup(DtSharedSettingsManager& manager, const std::string& classType, const std::string& descriptiveName)
228  : myManager(manager)
229  , myClassType(classType)
230  , myCanBackup(true)
231  , myDescriptiveName(descriptiveName)
232  {
233  }
234 
236  {
237  }
238 
239  void restore(const DtSettingsBackup* from)
240  {
241  bool can = canBackup();
242 
243  myCanBackup = false;
244 
246 
248 
249  myCanBackup = can;
250  }
251 
252  std::string backupClassType() const
253  {
254  return myClassType;
255  }
256 
257  std::string backupName() const
258  {
259  return myDescriptiveName;
260  }
261 
263  {
265  }
266 
267  void write(boost::archive::xml_oarchive& ar)
268  {
269  ar << boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
270  }
271 
272  void read(std::vector<boost::archive::xml_iarchive>& ar)
273  {
274  if (!ar.empty())
275  {
276  ar[0] >> boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
277  }
278  }
279 
280  void read(boost::archive::xml_iarchive& ar)
281  {
282  ar >> boost::serialization::make_nvp(backupClassType().c_str(), myRestoredRecord);
283  }
284 
285  const ArchiveClass& restoredRecord() const
286  {
287  return myRestoredRecord;
288  }
289 
290  void backup(const ArchiveClass& rec)
291  {
292  if (myCanBackup)
293  {
294  myRestoredRecord = rec;
296  }
297  }
298 
299  void setCanBackup(bool b)
300  {
301  myCanBackup = b;
302  }
303 
304  bool canBackup() const
305  {
306  return myCanBackup;
307  }
308 
309  protected:
311  ArchiveClass myRestoredRecord;
313  std::string myClassType;
314  std::string myDescriptiveName;
315  };
316 }
virtual DtDeSettings * findSettings(const std::string &settingsType)
Get the settings object for a particular settings type. If the Settings of the given type does not ex...
Contains makVrv::DtDeSettingsManager class.
virtual ~DtRecordSettingsBackupInterface()
Definition: DtRecordSettingsBackup.h:48
static DtDeSettingsManager & instance(DtDe &de)
Get an instance of the settings manager.
Interaction makVrv::DtWriteSettingsLock class.
DtSettingsBackup * create() const
Returns a new empty class of type. Will be called from restore() method to restore data into...
Definition: DtRecordSettingsBackup.h:262
DtSettingsBackup * create() const
Returns a new empty class of type. Will be called from restore() method to restore data into...
Definition: DtRecordSettingsBackup.h:132
std::string myClassType
Definition: DtRecordSettingsBackup.h:90
virtual ~DtRecordSettingsBackup()
Definition: DtRecordSettingsBackup.h:116
void backup(const ArchiveClass &rec)
Definition: DtRecordSettingsBackup.h:290
void restore(const DtSettingsBackup *from)
Called with the object that needs to be restored from. The object passed in should be considered temp...
Definition: DtRecordSettingsBackup.h:239
virtual std::string factoryFilePath() const
bool canBackup() const
Definition: DtRecordSettingsBackup.h:304
void read(std::vector< boost::archive::xml_iarchive > &ar)
Definition: DtRecordSettingsBackup.h:272
std::string myDescriptiveName
Definition: DtRecordSettingsBackup.h:91
virtual void readIncremental(boost::archive::xml_iarchive &ar)
Support for reading files from a directory by looping over files and incrementally adding their conte...
Definition: DtRecordSettingsBackup.h:199
DtRecordSettingsBackupInterface(DtDe &de, const std::string &classType, const std::string &descriptiveName)
Definition: DtRecordSettingsBackup.h:26
Contains makVrv::DtDe class.
void read(boost::archive::xml_iarchive &ar)
Override to read from given stream. Implementation need not be more than ia &gt;&gt; *this.
Definition: DtRecordSettingsBackup.h:204
bool canBackup() const
Definition: DtRecordSettingsBackup.h:83
The shared settings manager, is the global object responsible for managing any shared settings object...
Definition: DtSharedSettingsManager.h:42
The makVrv::DtRecordSettingsBackup is a templaced class that settings records will use in order to ba...
Definition: DtRecordSettingsBackup.h:101
void write(boost::archive::xml_oarchive &ar)
Override to write to given stream. Implementation need not be more than oa &lt;&lt; *this.
Definition: DtRecordSettingsBackup.h:267
std::string backupClassType() const
Override to return the class name of this object. Will be used as a key to look itself up in the back...
Definition: DtRecordSettingsBackup.h:252
void setCanBackup(bool b)
Definition: DtRecordSettingsBackup.h:299
ArchiveClass myRestoredRecord
Definition: DtRecordSettingsBackup.h:215
std::string backupClassType() const
Override to return the class name of this object. Will be used as a key to look itself up in the back...
Definition: DtRecordSettingsBackup.h:52
ArchiveClass myRestoredRecord
Definition: DtRecordSettingsBackup.h:311
std::enable_if< std::is_same< Q, DtElementDefinitionManager >::value, void >::type writeDirSpecialised(std::vector< std::ostringstream * > &outStreamVec, std::vector< std::string > &fileNames)
Definition: DtRecordSettingsBackup.h:153
void restore(const DtSettingsBackup *from)
Called with the object that needs to be restored from. The object passed in should be considered temp...
Definition: DtRecordSettingsBackup.h:120
std::enable_if< std::is_same< Q, DtElementDefinitionManager >::value, void >::type readIncrementalSpecialised(boost::archive::xml_iarchive &ar)
Definition: DtRecordSettingsBackup.h:191
void readRecords(boost::archive::xml_iarchive &ar, ArchiveClass &recordsResult)
Definition: DtRecordSettingsBackup.h:179
std::string myDescriptiveName
Definition: DtRecordSettingsBackup.h:314
std::string myClassType
Definition: DtRecordSettingsBackup.h:313
std::string backupName() const
Returns a more readable backup name (for dialogs). Will return backupClassType by default...
Definition: DtRecordSettingsBackup.h:257
#define DT_DLL_VRVCORE
Definition: vrvCore.h:20
DtRecordSettingsBackup(const DtRecordSettingsBackup &orig)
Definition: DtRecordSettingsBackup.h:110
const ArchiveClass & restoredRecord() const
Definition: DtRecordSettingsBackup.h:285
DtDe & myDe
Definition: DtRecordSettingsBackup.h:89
Provides a method of doign settings backup.
Definition: DtSettingsBackup.h:23
virtual void backupByDir()
Backs up settings to backup directory. If directory does not exist, will create. Emits signal_backedU...
a write settings lock on a setting object. The object can be read and modified, but no other threads ...
Definition: DtWriteSettingsLock.h:47
void read(boost::archive::xml_iarchive &ar)
Override to read from given stream. Implementation need not be more than ia &gt;&gt; *this.
Definition: DtRecordSettingsBackup.h:280
DtSharedRecordSettingsBackup(DtSharedSettingsManager &manager, const std::string &classType, const std::string &descriptiveName)
Definition: DtRecordSettingsBackup.h:227
virtual ~DtSharedRecordSettingsBackup()
Definition: DtRecordSettingsBackup.h:235
bool myCanBackup
Definition: DtRecordSettingsBackup.h:92
Settings class for reading and writing settings to/from files.
Definition: DtDeSettings.h:29
void write(boost::archive::xml_oarchive &ar)
Override to write to given stream. Implementation need not be more than oa &lt;&lt; *this.
Definition: DtRecordSettingsBackup.h:137
void writeDir(std::vector< std::ostringstream * > &outStreamVec, std::vector< std::string > &fileNames)
Support for writing settings to files in a directory.
Definition: DtRecordSettingsBackup.h:174
virtual void backup()
Backs up settings to backup file. If file does not exist, will create. Emits signal_backedUp when thi...
virtual void registerSettingsBackup(DtSettingsBackup *backup)
Registers the settings class with the manager. If the name supplied for registration already exists...
std::string backupName() const
Returns a more readable backup name (for dialogs). Will return backupClassType by default...
Definition: DtRecordSettingsBackup.h:57
bool myCanBackup
Definition: DtRecordSettingsBackup.h:312
std::enable_if<!std::is_same< Q, DtElementDefinitionManager >::value, void >::type writeDirSpecialised(std::vector< std::ostringstream * > &outStreamVec, std::vector< std::string > &fileNames)
Definition: DtRecordSettingsBackup.h:147
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
const ArchiveClass & restoredRecord() const
Definition: DtRecordSettingsBackup.h:209
DtRecordSettingsBackup(DtDe &de, SettingsClass *parent, const std::string &classType, const std::string &descriptiveName)
Definition: DtRecordSettingsBackup.h:104
The makVrv::DtRecordSettingsBackupInterface provides an interface to record-based backups...
Definition: DtRecordSettingsBackup.h:23
DtSharedSettingsManager & myManager
Definition: DtRecordSettingsBackup.h:310
SettingsClass * myParent
Definition: DtRecordSettingsBackup.h:216
virtual void backupByDir()
Backs up settings to backup directory. If directory does not exist, will create. Emits signal_backedU...
Definition: DtRecordSettingsBackup.h:70
The makVrv::DtSharedRecordSettingsBackup is a templaced class that settings records will use in order...
Definition: DtRecordSettingsBackup.h:223
void setCanBackup(bool b)
Definition: DtRecordSettingsBackup.h:78
std::enable_if<!std::is_same< Q, DtElementDefinitionManager >::value, void >::type readIncrementalSpecialised(boost::archive::xml_iarchive &ar)
Definition: DtRecordSettingsBackup.h:185
virtual void backup()
Backs up settings to backup file. If file does not exist, will create. Emits signal_backedUp when thi...
Definition: DtRecordSettingsBackup.h:62
DtRecordSettingsBackupInterface(const DtRecordSettingsBackupInterface &orig)
Definition: DtRecordSettingsBackup.h:40
static DtSettingsBackupManager & instance(DtDe &de)
Get an instance of the settings manager.

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)