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) 2025 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 
254 
256 
257  protected:
258 
260 
261  std::string myName;
262  std::string myExtension;
263  std::string myDisplayName;
264 
267 
269 
271 
272  };
273 
274 
282  template <typename RecordType>
284  {
285  protected:
286 
289 
290  public:
291 
294  DtBaseSettingsManager( DtDe& de, const std::string& name,
295  const std::string& displayName, const std::string& ext )
296  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
297  {
298  }
299 
302  {
303  DtDELETE( this->mySettingsBackup );
304  }
305 
308 
310  virtual void initializeBackup()
311  {
312  DtDELETE( this->mySettingsBackup );
313  this->mySettingsBackup = new RecordBackupType( this->myDe, this, this->myName, this->myDisplayName );
314  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
316  this->mySettingsBackup->backup();
317  }
318 
320  virtual void setFromRecord( const RecordType& record ) = 0;
321 
323  virtual void getRecord( RecordType& record ) const = 0;
324 
329  virtual bool applyFactoryOverrides( RecordType& record ) const = 0;
330 
335  virtual bool getOverriddenFactoryRecord(RecordType& record) const
336  {
337  // get the factory record
338  const DtDeSettings* deSettings = this->settings();
339  deSettings->readFactoryDefaultRecord(record);
340 
341  // Can be overridden by child classes
342  return applyFactoryOverrides(record);
343  }
344 
346 
347  };
348 
349 
363  template <typename RecordType,typename SettingsType>
365  {
366  protected:
367 
370 
371  public:
372 
375  DtBaseSharedSettingsManager( DtDe& de, const std::string& name,
376  const std::string& displayName, const std::string& ext )
377  : DtCommonBaseSettingsManager<RecordType>( de, name, displayName, ext )
378  {
379  }
380 
383  {
384  // Don't delete the settings backup (it's owned by the settings object).
385  }
386 
389 
391  virtual void initializeBackup()
392  {
394  writeSettings( DtSharedSettingsManager::instance(this->myDe) );
395  this->mySettingsBackup = writeSettings->settingsBackup();
396  this->mySettingsBackup->setFactoryFile( this->settings()->factoryFilePath() );
398  writeSettings->backup();
399  }
400 
402  virtual void setFromRecord( const RecordType& record )
403  {
404  {
407  settings->setFromRecord( record );
408  }
409  this->saveDefaultSettings();
410  }
411 
413  virtual void getRecord( RecordType& record ) const
414  {
417  settings->getRecord( record );
418  }
419 
424  virtual bool getOverriddenFactoryRecord(RecordType& record) const
425  {
426  // get the factory record
427  const DtDeSettings* deSettings = this->settings();
428  deSettings->readFactoryDefaultRecord(record);
429 
430  // pass the factory record to the getFactoryOverrideRecord and let the shared settings class
431  // decide whether or not there are overridden values
434  return settings->applyFactoryOverrides(record);
435  }
436 
438 
439  };
440 
441 }
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:283
Base class for shared settings managers. Extends the functionality provided by the DtCommonBaseSettin...
Definition: DtBaseSettingsManager.h:364
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).
static DtDeSettingsManager & instance(DtDe &de)
Get an instance of the settings manager.
bool myAutoSaveFlag
Definition: DtBaseSettingsManager.h:266
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:391
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:413
DtSignalConnectionManager myConnections
Definition: DtBaseSettingsManager.h:259
std::string myExtension
Definition: DtBaseSettingsManager.h:262
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:382
The makVrv::DtRecordSettingsBackup is a templaced class that settings records will use in order to ba...
Definition: DtRecordSettingsBackup.h:101
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:369
Contains DLL export macros.
DtSettingsBackup * mySettingsBackup
Definition: DtBaseSettingsManager.h:268
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:270
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:294
std::string myDisplayName
Definition: DtBaseSettingsManager.h:263
bool myUseDefaultSettingsRecordFlag
Definition: DtBaseSettingsManager.h:265
virtual void initializeBackup()
Creates a backup of the settings&#39; current state.
Definition: DtBaseSettingsManager.h:310
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:261
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:301
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:424
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:375
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:335
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:76
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:402
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:223
DtRecordSettingsBackup< DtBaseSettingsManager< RecordType >, RecordType > RecordBackupType
Definition: DtBaseSettingsManager.h:288
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 Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)