VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtBaseSettingsManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2023 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvUtil/vrvUtil.h>
13 
17 
20 
21 #include <vlutil/vlUtil.h>
22 
23 namespace makVrv
24 {
25 
34  template <typename RecordType>
36  {
37  public:
38 
43  DtCommonBaseSettingsManager( DtDe& de, const std::string& name,
44  const std::string& displayName, const std::string& ext )
45  : myName( name )
46  , myExtension( ext )
47  , myDisplayName( displayName )
49  , myAutoSaveFlag( true )
50  , mySettingsBackup( 0 )
51  , myDe( de )
52  {
53  // Create the settings object
55  }
56 
59  {
60  }
61 
65  virtual void autoSaveIfNecessary()
66  {
67  if ( autoSave() )
68  {
70  }
71  }
72 
75  virtual void setAutoSave( bool doit )
76  {
77  myAutoSaveFlag = doit;
78  }
79 
82  virtual bool autoSave() const
83  {
84  return myAutoSaveFlag;
85  }
86 
91  virtual void setUseDefaultSettingsRecord( bool useit )
92  {
94  }
95 
100  virtual bool useDefaultSettingsRecord() const
101  {
103  }
104 
108  {
109  DtDeSettings* deSettings =
111  if ( ! deSettings )
112  {
113  DtTHROW_NEW( DtCorruptedState, "DtDeSettings have gone missing!" );
114  }
115  return deSettings;
116  }
117 
120  virtual const DtDeSettings* settings() const
121  {
122  DtDeSettings* deSettings =
124  if ( ! deSettings )
125  {
126  DtTHROW_NEW( DtCorruptedState, "DtDeSettings have gone missing!" );
127  }
128  return deSettings;
129  }
130 
133  {
134  return mySettingsBackup;
135  }
136 
138  virtual const DtSettingsBackup* settingsBackup() const
139  {
140  return mySettingsBackup;
141  }
142 
145 
150  virtual void loadDefaults()
151  {
152  // Disable auto saving and store state.
153  bool autoSaved = autoSave();
154  setAutoSave( false );
155 
156  // Either set from the default record (if present) or load defaults.
157  RecordType record;
160  {
161  // This code path:
162  // - allows toolkit users to set a default settings record before application initialization.
163  // - is seldom used by MAK.
164  setFromRecord( record );
165  }
166  else if (getOverriddenFactoryRecord(record))
167  {
168  // This code path:
169  // - allows VRV developers to override settings, through code, with more ease.
170  // - should never be used in production.
171  setFromRecord(record);
172  }
173  else
174  {
175  // This code path:
176  // - is almost always used.
177  // - will read from the appData directory (if false is passed)
178  // - will read from the factory directory (if true is passed)
179  loadDefaultSettings( false );
180  }
181 
182  // Restore the auto save state.
183  setAutoSave( autoSaved );
184 
185  // Initialize the settings backup.
187  }
188 
190  virtual void initializeBackup() = 0;
191 
193  virtual void saveDefaultSettings()
194  {
195  RecordType record;
196  getRecord( record );
197  settings()->writeDefaultRecord( record );
198  }
199 
203  virtual void loadDefaultSettings( bool loadOnlyFactorySettings )
204  {
205  DtDeSettings* deSettings = settings();
206  RecordType record;
207  if ( loadOnlyFactorySettings )
208  {
209  if ( deSettings->readFactoryDefaultRecord(record) )
210  {
211  setFromRecord( record );
212  }
213  }
214  else
215  {
216  if ( deSettings->readDefaultRecord(record) )
217  {
218  setFromRecord( record );
219  }
220  }
221  }
222 
224  virtual void importSettings( const std::string& filePath )
225  {
226  RecordType record;
227  if ( settings()->readRecordFrom(record,filePath) )
228  {
229  setFromRecord( record );
231  }
232  }
233 
235  virtual void exportSettings( const std::string& filePath ) const
236  {
237  RecordType record;
238  getRecord( record );
239  settings()->writeRecordTo( record, filePath );
240  }
241 
243  virtual void setFromRecord( const RecordType& record ) = 0;
244 
246  virtual void getRecord( RecordType& record ) const = 0;
247 
252  virtual bool getOverriddenFactoryRecord( RecordType& record ) const = 0;
253 
256  virtual void getSplitRecord(std::vector<RecordType>& rec,
257  std::vector<std::string>& fileNames) {};
258 
261  virtual void addRecords(RecordType& rec, RecordType& combinedRec) {};
262 
264 
265  protected:
266 
268 
269  std::string myName;
270  std::string myExtension;
271  std::string myDisplayName;
272 
275 
277 
279 
280  };
281 
282 
290  template <typename RecordType>
292  {
293  protected:
294 
297 
298  public:
299 
302  DtBaseSettingsManager( DtDe& de, const std::string& name,
303  const std::string& displayName, const std::string& ext )
304  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
305  {
306  }
307 
310  {
311  DtDELETE( this->mySettingsBackup );
312  }
313 
316 
318  virtual void initializeBackup()
319  {
320  DtDELETE( this->mySettingsBackup );
321  this->mySettingsBackup = new RecordBackupType( this->myDe, this, this->myName, this->myDisplayName );
322  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
324  this->mySettingsBackup->backup();
325  }
326 
328  virtual void setFromRecord( const RecordType& record ) = 0;
329 
331  virtual void getRecord( RecordType& record ) const = 0;
332 
337  virtual bool applyFactoryOverrides( RecordType& record ) const = 0;
338 
343  virtual bool getOverriddenFactoryRecord(RecordType& record) const
344  {
345  // get the factory record
346  const DtDeSettings* deSettings = this->settings();
347  deSettings->readFactoryDefaultRecord(record);
348 
349  // Can be overridden by child classes
350  return applyFactoryOverrides(record);
351  }
352 
354 
355  };
356 
357 
371  template <typename RecordType,typename SettingsType>
373  {
374  protected:
375 
378 
379  public:
380 
383  DtBaseSharedSettingsManager( DtDe& de, const std::string& name,
384  const std::string& displayName, const std::string& ext )
385  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
386  {
387  }
388 
391  {
392  // Don't delete the settings backup (it's owned by the settings object).
393  }
394 
397 
399  virtual void initializeBackup()
400  {
402  writeSettings( DtSharedSettingsManager::instance(this->myDe) );
403  this->mySettingsBackup = writeSettings->settingsBackup();
404  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
406  writeSettings->backup();
407  }
408 
410  virtual void setFromRecord( const RecordType& record )
411  {
412  {
415  settings->setFromRecord( record );
416  }
417  this->saveDefaultSettings();
418  }
419 
421  virtual void getRecord( RecordType& record ) const
422  {
425  settings->getRecord( record );
426  }
427 
432  virtual bool getOverriddenFactoryRecord(RecordType& record) const
433  {
434  // get the factory record
435  const DtDeSettings* deSettings = this->settings();
436  deSettings->readFactoryDefaultRecord(record);
437 
438  // pass the factory record to the getFactoryOverrideRecord and let the shared settings class
439  // decide whether or not there are overridden values
442  return settings->applyFactoryOverrides(record);
443  }
444 
446 
447  };
448 
449 }
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...
virtual void loadDefaultSettings(bool loadOnlyFactorySettings)
Loads the default settings from disk. If loadOnlyFactorySettings is true, only the factory record wil...
Definition: DtBaseSettingsManager.h:203
Base class for (non-shared) settings managers. Extends the functionality provided by the DtCommonBase...
Definition: DtBaseSettingsManager.h:291
Base class for shared settings managers. Extends the functionality provided by the DtCommonBaseSettin...
Definition: DtBaseSettingsManager.h:372
a read settings lock on a setting object. The object can only get read access aka const functions...
Definition: DtReadSettingsLock.h:48
virtual void initializeBackup()=0
Creates a backup of the settings&#39; current state (abstract).
virtual void addRecords(RecordType &rec, RecordType &combinedRec)
For directory support, when reading in a directory, add the records from each file to the combined re...
Definition: DtBaseSettingsManager.h:261
static DtDeSettingsManager & instance(DtDe &de)
Get an instance of the settings manager.
bool myAutoSaveFlag
Definition: DtBaseSettingsManager.h:274
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
Interaction makVrv::DtWriteSettingsLock class.
virtual bool useDefaultSettingsRecord() const
Gets whether setting initialization should check for a default record. If set and a default record is...
Definition: DtBaseSettingsManager.h:100
virtual void setUseDefaultSettingsRecord(bool useit)
Sets whether setting initialization should check for a default record. If set and a default record is...
Definition: DtBaseSettingsManager.h:91
virtual void initializeBackup()
Creates a backup of the settings&#39; current state.
Definition: DtBaseSettingsManager.h:399
virtual void autoSaveIfNecessary()
Saves the current settings as defaults if autosave is enabled. This method is mainly provided to make...
Definition: DtBaseSettingsManager.h:65
virtual void getRecord(RecordType &record) const
Store the current settings&#39; state in the given record.
Definition: DtBaseSettingsManager.h:421
DtSignalConnectionManager myConnections
Definition: DtBaseSettingsManager.h:261
std::string myExtension
Definition: DtBaseSettingsManager.h:270
bool findDefaultSettingsRecord(const std::string &name, RecordType &record) const
Find a settings default records.
Definition: DtDeInitializer.h:366
Common base class for all types of settings managers. This class provides the interface for creating ...
Definition: DtBaseSettingsManager.h:35
virtual bool autoSave() const
Gets whether autosave is enabled for the settings manager. If autosave is enabled, the settings will be saved as they&#39;re changed.
Definition: DtBaseSettingsManager.h:82
virtual ~DtBaseSharedSettingsManager()
Virtual DTOR.
Definition: DtBaseSettingsManager.h:390
The makVrv::DtRecordSettingsBackup is a templaced class that settings records will use in order to ba...
Definition: DtRecordSettingsBackup.h:100
virtual void saveDefaultSettings()
Saves the current settings&#39; state as the default (on disk).
Definition: DtBaseSettingsManager.h:193
bool readDefaultRecord(RecordType &r)
Read a record from the default settings.
DtSharedRecordSettingsBackup< SettingsType, RecordType > SharedRecordBackupType
Definition: DtBaseSettingsManager.h:377
Contains DLL export macros.
DtSettingsBackup * mySettingsBackup
Definition: DtBaseSettingsManager.h:276
void setFactoryFile(const std::string &s)
Definition: DtSettingsBackup.h:170
virtual void getRecord(RecordType &record) const =0
Store the current settings&#39; state in the given record (abstract).
bool writeRecordTo(const RecordType &r, const std::string &exportFileName) const
Write a record to a specific location.
Contains makVrv::DtVirtualBaseClass class.
DtDe & myDe
Definition: DtBaseSettingsManager.h:278
virtual DtSettingsBackup * settingsBackup()
Accessor for the manager&#39;s settings backup.
Definition: DtBaseSettingsManager.h:132
DtBaseSettingsManager(DtDe &de, const std::string &name, const std::string &displayName, const std::string &ext)
CTOR.
Definition: DtBaseSettingsManager.h:302
std::string myDisplayName
Definition: DtBaseSettingsManager.h:271
bool myUseDefaultSettingsRecordFlag
Definition: DtBaseSettingsManager.h:273
virtual void initializeBackup()
Creates a backup of the settings&#39; current state.
Definition: DtBaseSettingsManager.h:318
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
static DtSharedSettingsManager & instance(DtDe &)
Get an instance of the shared settings manager from the DtDe;.
Provides a method of doign settings backup.
Definition: DtSettingsBackup.h:23
std::string myName
Definition: DtBaseSettingsManager.h:269
a write settings lock on a setting object. The object can be read and modified, but no other threads ...
Definition: DtWriteSettingsLock.h:47
virtual ~DtBaseSettingsManager()
Virtual DTOR.
Definition: DtBaseSettingsManager.h:309
virtual void getSplitRecord(std::vector< RecordType > &rec, std::vector< std::string > &fileNames)
For directory support, split the main record into different sub-records and give them each a file nam...
Definition: DtBaseSettingsManager.h:256
bool readFactoryDefaultRecord(RecordType &r) const
DtCommonBaseSettingsManager(DtDe &de, const std::string &name, const std::string &displayName, const std::string &ext)
CTOR The name, displayName, and extension parameters are used for creating the settings object (DtDeS...
Definition: DtBaseSettingsManager.h:43
Contains makVrv::DtReadSettingsLock class.
virtual void createSettings(const std::string &settingsType, const std::string &settingsExt)
Create a settings object with a name and extension.
virtual void importSettings(const std::string &filePath)
Load the settings&#39; state from the given file.
Definition: DtBaseSettingsManager.h:224
Base class to provide boost signal/slot management.
virtual DtDeSettings * settings()
Accessor for the manager&#39;s DtDeSettings object.
Definition: DtBaseSettingsManager.h:107
virtual bool getOverriddenFactoryRecord(RecordType &record) const
Get overrides to the factory record, if any. If there are overrides, this function returns true...
Definition: DtBaseSettingsManager.h:432
Settings class for reading and writing settings to/from files.
Definition: DtDeSettings.h:29
virtual void backup()
Backs up settings to backup file. If file does not exist, will create. Emits signal_backedUp when thi...
DtBaseSharedSettingsManager(DtDe &de, const std::string &name, const std::string &displayName, const std::string &ext)
CTOR.
Definition: DtBaseSettingsManager.h:383
virtual void loadDefaults()
Initializes the settings and creates a backup. If the useDefaultSettingsRecord is enabled and a defau...
Definition: DtBaseSettingsManager.h:150
virtual void registerSettingsBackup(DtSettingsBackup *backup)
Registers the settings class with the manager. If the name supplied for registration already exists...
virtual bool getOverriddenFactoryRecord(RecordType &record) const
Get overrides to the factory record, if any. If there are overrides, this function returns true...
Definition: DtBaseSettingsManager.h:343
virtual void setFromRecord(const RecordType &record)=0
Set the current settings&#39; state from the given record (abstract).
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:72
virtual const DtSettingsBackup * settingsBackup() const
Accessor for the manager&#39;s settings backup (const).
Definition: DtBaseSettingsManager.h:138
virtual void setAutoSave(bool doit)
Sets whether autosave is enabled for the settings manager. If autosave is enabled, the settings will be saved as they&#39;re changed.
Definition: DtBaseSettingsManager.h:75
virtual void getRecord(RecordType &record) const =0
Store the current settings&#39; state in the given record (abstract).
virtual void setFromRecord(const RecordType &record)
Set the current settings&#39; state from the given record.
Definition: DtBaseSettingsManager.h:410
virtual ~DtCommonBaseSettingsManager()
Virtual DTOR.
Definition: DtBaseSettingsManager.h:58
virtual void exportSettings(const std::string &filePath) const
Save the current settings&#39; state to the given file.
Definition: DtBaseSettingsManager.h:235
virtual bool getOverriddenFactoryRecord(RecordType &record) const =0
Get overrides to the factory record, if any. If there are overrides, this function returns true...
virtual const DtDeInitializer & deInitializer() const
Return the DtDeInitializer.
virtual bool applyFactoryOverrides(RecordType &record) const =0
Get overrides to the factory record, if any. If there are overrides, this function returns true...
The makVrv::DtSharedRecordSettingsBackup is a templaced class that settings records will use in order...
Definition: DtRecordSettingsBackup.h:197
DtRecordSettingsBackup< DtBaseSettingsManager< RecordType >, RecordType > RecordBackupType
Definition: DtBaseSettingsManager.h:296
bool writeDefaultRecord(const RecordType &r)
Write a record as the default settings.
virtual void setFromRecord(const RecordType &record)=0
Set the current settings&#39; state from the given record (abstract).
virtual const DtDeSettings * settings() const
Accessor for the manager&#39;s DtDeSettings object (const).
Definition: DtBaseSettingsManager.h:120
static DtSettingsBackupManager & instance(DtDe &de)
Get an instance of the settings manager.

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)