Preferences Class Reference

Maintains a list of PreferenceSection objects, and allows clients to declare new sections, and add new preferences to the sections. More...

#include <prefs.h>

Inheritance diagram for Preferences:

List CCObject SimpleCCObject List of all members.

Public Member Functions

 Preferences ()
 Initialises the section caching system.
 ~Preferences ()
 Deletes all PreferenceSection objects used by this object.
BOOL Init ()
 This initialises the Preferences object. This includes setting up a link to the OIL and opening the preference file for reading.
void Deinit ()
 This de-initialises the Preferences object. This includes closing down whatever OIL mechanisms were set up by Init().
void Write ()
 This writes out all Camelot preferences to the application's preference file, using the OIL.
void WipePreferenceFile ()
 Used to remove an old (possibly incompatible) preference file. It assumes that the preference system has been initialised and that it is still active (i.e. Deinit() has not been called).
void WipeDangerousPrefs ()
 Used to remove any dangerous sections from the registry, when upgrading from an old version.
BOOL DeclareSection (TCHAR *Section, UINT32 InitialSize)
BOOL DeclarePref (TCHAR *Section, TCHAR *Pref, INT32 *PrefVar, INT32 Min=INT_MIN, INT32 Max=INT_MAX)
BOOL DeclarePref (TCHAR *Section, TCHAR *Pref, UINT32 *PrefVar, UINT32 Min=0, UINT32 Max=UINT_MAX)
BOOL DeclarePref (TCHAR *Section, TCHAR *Pref, double *PrefVar, double Min=DBL_MIN, double Max=DBL_MAX)
BOOL DeclarePref (TCHAR *Section, TCHAR *Pref, StringBase *PrefVar)
BOOL GetPrefValue (TCHAR *Section, TCHAR *Pref, INT32 *PrefVar)
BOOL GetPrefValue (TCHAR *Section, TCHAR *Pref, UINT32 *PrefVar)
BOOL GetPrefValue (TCHAR *Section, TCHAR *Pref, double *PrefVar)
BOOL SetPrefValue (TCHAR *Section, TCHAR *Pref, INT32 *PrefVar)
BOOL SetPrefValue (TCHAR *Section, TCHAR *Pref, UINT32 *PrefVar)
BOOL SetPrefValue (TCHAR *Section, TCHAR *Pref, double *PrefVar)
BOOL SetPrefDirect (TCHAR *Section, TCHAR *Pref, const TCHAR *pValue, BOOL Force=FALSE)
BOOL SetPrefDirect (TCHAR *Section, TCHAR *Pref, PreferenceType Type, PrefData Data)
BOOL SetPrefDirect (TCHAR *Section, TCHAR *Pref, INT32 *pValue)
BOOL SetPrefDirect (TCHAR *Section, TCHAR *Pref, UINT32 *pValue)
BOOL SetPrefDirect (TCHAR *Section, TCHAR *Pref, double *pValue)
BOOL GetPrefDirect (TCHAR *Section, TCHAR *Pref, StringBase *pValue)
BOOL GetPrefDirect (TCHAR *Section, TCHAR *Pref, PreferenceType Type, PrefData Data)
BOOL GetPrefDirect (TCHAR *Section, TCHAR *Pref, INT32 *pValue)
BOOL GetPrefDirect (TCHAR *Section, TCHAR *Pref, UINT32 *pValue)
BOOL GetPrefDirect (TCHAR *Section, TCHAR *Pref, double *pValue)

Private Member Functions

PreferenceSectionGetSection (TCHAR *SectionName)

Private Attributes

PreferenceSectionCurrentSection
OILPreferencesOILPrefs

Detailed Description

Maintains a list of PreferenceSection objects, and allows clients to declare new sections, and add new preferences to the sections.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
For details of how to declare/use preferences, see the Application class.

When the application wants to save the preferences, the Write() function of this class should be used.

See also:
-

Definition at line 151 of file prefs.h.


Constructor & Destructor Documentation

Preferences::Preferences  ) 
 

Initialises the section caching system.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 880 of file prefs.cpp.

00881 {
00882     CurrentSection = NULL;
00883     OILPrefs       = NULL;
00884 }

Preferences::~Preferences  ) 
 

Deletes all PreferenceSection objects used by this object.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 901 of file prefs.cpp.

00902 {
00903 #if !defined(EXCLUDE_FROM_RALPH)
00904     // Close the preferences file
00905     if (OILPrefs != NULL)
00906     {
00907         OILPrefs->CloseInput();
00908         delete OILPrefs;
00909     }
00910         
00911     PreferenceSection *pSection;
00912     
00913     // Delete all the sections for this preferences object
00914     do
00915     {
00916         // Unlink the first item from the list
00917         pSection = (PreferenceSection *) this->RemoveHead();
00918 
00919         // It doesn't matter if pSection is NULL - delete handles it
00920         delete pSection;
00921         
00922     } while (pSection != NULL);
00923 #endif
00924 }


Member Function Documentation

BOOL Preferences::DeclarePref TCHAR Section,
TCHAR Pref,
StringBase PrefVar
 

BOOL Preferences::DeclarePref TCHAR Section,
TCHAR Pref,
double *  PrefVar,
double  Min = DBL_MIN,
double  Max = DBL_MAX
 

BOOL Preferences::DeclarePref TCHAR Section,
TCHAR Pref,
UINT32 PrefVar,
UINT32  Min = 0,
UINT32  Max = UINT_MAX
 

BOOL Preferences::DeclarePref TCHAR Section,
TCHAR Pref,
INT32 *  PrefVar,
INT32  Min = INT_MIN,
INT32  Max = INT_MAX
 

BOOL Preferences::DeclareSection TCHAR Section,
UINT32  InitialSize
 

void Preferences::Deinit void   ) 
 

This de-initialises the Preferences object. This includes closing down whatever OIL mechanisms were set up by Init().

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if ok, FALSE if an error occured.

Errors: -

See also:
Preferences::Init; OILPreferences

Definition at line 1025 of file prefs.cpp.

01026 {
01027 #if !defined(EXCLUDE_FROM_RALPH)
01028     // Close the preferences file
01029     if (OILPrefs != NULL)
01030         OILPrefs->CloseInput();
01031 #endif
01032 }

BOOL Preferences::GetPrefDirect TCHAR Section,
TCHAR Pref,
double *  pValue
 

BOOL Preferences::GetPrefDirect TCHAR Section,
TCHAR Pref,
UINT32 pValue
 

BOOL Preferences::GetPrefDirect TCHAR Section,
TCHAR Pref,
INT32 *  pValue
 

BOOL Preferences::GetPrefDirect TCHAR Section,
TCHAR Pref,
PreferenceType  Type,
PrefData  Data
 

BOOL Preferences::GetPrefDirect TCHAR Section,
TCHAR Pref,
StringBase pValue
 

BOOL Preferences::GetPrefValue TCHAR Section,
TCHAR Pref,
double *  PrefVar
 

BOOL Preferences::GetPrefValue TCHAR Section,
TCHAR Pref,
UINT32 PrefVar
 

BOOL Preferences::GetPrefValue TCHAR Section,
TCHAR Pref,
INT32 *  PrefVar
 

PreferenceSection* Preferences::GetSection TCHAR SectionName  )  [private]
 

BOOL Preferences::Init void   ) 
 

This initialises the Preferences object. This includes setting up a link to the OIL and opening the preference file for reading.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if ok, FALSE if an error occured.

Errors: -

See also:
Preferences::Deinit; OILPreferences

Reimplemented from SimpleCCObject.

Definition at line 986 of file prefs.cpp.

00987 {
00988 #if !defined(EXCLUDE_FROM_RALPH)
00989     // Create a link to the OIL
00990     OILPrefs = OILPreferences::Init();
00991     
00992     // Flag error if it failed
00993     if (OILPrefs == NULL)
00994         return FALSE;
00995 
00996     PrefsInitedOk = TRUE;
00997 
00998     // Initialise the preference file for reading
00999     return OILPrefs->OpenInput();
01000 
01001 #else //EXCLUDE_FROM_RALPH
01002     // Be gone you pesky prefs system :-)
01003     OILPrefs = NULL;
01004     PrefsInitedOk = FALSE;
01005     return TRUE;
01006 #endif //EXCLUDE_FROM_RALPH
01007 }

BOOL Preferences::SetPrefDirect TCHAR Section,
TCHAR Pref,
double *  pValue
 

BOOL Preferences::SetPrefDirect TCHAR Section,
TCHAR Pref,
UINT32 pValue
 

BOOL Preferences::SetPrefDirect TCHAR Section,
TCHAR Pref,
INT32 *  pValue
 

BOOL Preferences::SetPrefDirect TCHAR Section,
TCHAR Pref,
PreferenceType  Type,
PrefData  Data
 

BOOL Preferences::SetPrefDirect TCHAR Section,
TCHAR Pref,
const TCHAR pValue,
BOOL  Force = FALSE
 

BOOL Preferences::SetPrefValue TCHAR Section,
TCHAR Pref,
double *  PrefVar
 

BOOL Preferences::SetPrefValue TCHAR Section,
TCHAR Pref,
UINT32 PrefVar
 

BOOL Preferences::SetPrefValue TCHAR Section,
TCHAR Pref,
INT32 *  PrefVar
 

void Preferences::WipeDangerousPrefs  ) 
 

Used to remove any dangerous sections from the registry, when upgrading from an old version.

Author:
Chris_Gallimore (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/2001
See also:
Application::WipeDangerousPrefs

Definition at line 1072 of file prefs.cpp.

01073 {
01074 #if !defined(EXCLUDE_FROM_RALPH)
01075     ENSURE(OILPrefs != NULL, "OILPreferences system not initialised");
01076 
01077     OILPrefs->WipeDangerousPrefs();
01078 #endif
01079 }

void Preferences::WipePreferenceFile  ) 
 

Used to remove an old (possibly incompatible) preference file. It assumes that the preference system has been initialised and that it is still active (i.e. Deinit() has not been called).

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/11/93
Returns:
Errors: -
See also:
-

Definition at line 1048 of file prefs.cpp.

01049 {
01050 #if !defined(EXCLUDE_FROM_RALPH)
01051     ENSURE(OILPrefs != NULL, "OILPreferences system not initialised");
01052 
01053     // Close the file, clear it, and re-open it
01054     OILPrefs->CloseInput();
01055     OILPrefs->WipePreferenceFile();
01056     OILPrefs->OpenInput();
01057 #endif
01058 }

void Preferences::Write  ) 
 

This writes out all Camelot preferences to the application's preference file, using the OIL.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 943 of file prefs.cpp.

00944 {
00945 #if !defined(EXCLUDE_FROM_RALPH)
00946     // First check if there is a valid OILPrefs, as if there was a problem on start up such as
00947     // the MSCVRTn.DLL failing to load then the preferences may have been not fully set up.
00948     // Static variable used as the class may not have been created!
00949     if (PrefsInitedOk && (OILPrefs != NULL))
00950     {
00951         // Perform any preparation necessary to start writing preferences
00952         OILPrefs->OpenOutput();
00953 
00954         // Write out all the sections for this preferences object
00955         PreferenceSection *pSection = (PreferenceSection *) this->GetHead();
00956     
00957         while (pSection != NULL)
00958         {
00959             // Write out this section and move on to the next
00960             pSection->Write(OILPrefs);
00961             pSection = (PreferenceSection *) this->GetNext(pSection);   
00962         }
00963 
00964         // Perform any platform-deppy clean-up required after writing the preferences
00965         OILPrefs->CloseOutput();
00966     }
00967 #endif
00968 }


Member Data Documentation

PreferenceSection* Preferences::CurrentSection [private]
 

Definition at line 205 of file prefs.h.

OILPreferences* Preferences::OILPrefs [private]
 

Definition at line 209 of file prefs.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:59:53 2007 for Camelot by  doxygen 1.4.4