PreferenceChunk Class Reference

Objects of this class hold a chunk of preferences for a particular section of the preferences. There may be more than one chunk for a given section, depending on how accurate the initial declaration of the section's size was. More...

Inheritance diagram for PreferenceChunk:

ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 PreferenceChunk (UINT32 InitialSize)
 Constructs a chunk of memory which can contain preferences.
 ~PreferenceChunk ()
 Destroys the PreferenceChunk - it deallocates any memory previously allocated for PreferenceEntry objects by this object.
void Write (OILPreferences *OILPrefs, LPTCHAR Section)
 Writes out all the preferences contained in this chunk object, using the OIL.
BOOL AddPref (LPTCHAR Name, PrefData EntryData, PreferenceType Type)
 Adds the given preference to this chunk.
BOOL GetPrefValue (LPTCHAR Pref, PrefData EntryData, PreferenceType Type)
 Checks to see if the given preference exists in this chunk and if so returns the value currently assigned to that preference value by placing it in the variable pointed to by the PrefData structure passed in. This means one routine can be used as opposed to one per preference type.
BOOL SetPrefValue (LPTCHAR Pref, PrefData EntryData, PreferenceType Type)
 Checks to see if the given preference exists in this chunk and if so sets the value stored in the preference user's variable to be the specified new value.

Public Attributes

BOOL Valid

Private Attributes

UINT32 NumEntries
UINT32 NumEntriesUsed
PreferenceEntrypEntries

Detailed Description

Objects of this class hold a chunk of preferences for a particular section of the preferences. There may be more than one chunk for a given section, depending on how accurate the initial declaration of the section's size was.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
See also:
-

Definition at line 165 of file prefs.cpp.


Constructor & Destructor Documentation

PreferenceChunk::PreferenceChunk UINT32  InitialSize  ) 
 

Constructs a chunk of memory which can contain preferences.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
InitialSize - the number of preferences this chunk should be able to hold. [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: The member variable 'Valid' is FALSE if the required memory was not allocated.

See also:
-

Definition at line 260 of file prefs.cpp.

00261 {
00262     Valid = FALSE;
00263     
00264     // Sanity check
00265     ENSURE(InitialSize > 0, "Attempt to create a PreferenceChunk object of zero size");
00266 
00267     // Allocate the memory for this chunk.
00268     pEntries = new PreferenceEntry[InitialSize];
00269     
00270     if (pEntries == NULL)
00271     {
00272         // Not enough memory
00273         NumEntries = 0;
00274         NumEntriesUsed = 0;
00275     }
00276     
00277     // Set the entries fields correctly and tell the caller it worked
00278     NumEntries = InitialSize;
00279     NumEntriesUsed = 0;
00280     Valid = TRUE;
00281 }

PreferenceChunk::~PreferenceChunk  ) 
 

Destroys the PreferenceChunk - it deallocates any memory previously allocated for PreferenceEntry objects 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 299 of file prefs.cpp.

00300 {
00301     PreferenceEntry *pEntry = pEntries;
00302     
00303     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00304     {
00305         if (pEntry->Name)
00306         {
00307             CCFree(pEntry->Name);
00308             pEntry->Name=NULL;
00309         }
00310         pEntry++;
00311     }   
00312     
00313     if (pEntries != NULL)
00314         delete [] pEntries;
00315 }


Member Function Documentation

BOOL PreferenceChunk::AddPref LPTCHAR  Name,
PrefData  EntryData,
PreferenceType  Type
 

Adds the given preference to this chunk.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
Name - the name of the section to add this preference to. [INPUTS] EntryData - pointer to the memory that will hold the value of this preference. Type - the type of this preference - i.e., the type of data pointed to by the EntryData argument.
- [OUTPUTS]
Returns:
TRUE if the preference could be added to this chunk - FALSE if the chunk is full and the preference could not be added.

Errors: -

See also:
-

Definition at line 338 of file prefs.cpp.

00339 {
00340     // Is there enough space left to do this?
00341     if ((!Valid) || (NumEntriesUsed >= NumEntries))
00342         return FALSE;
00343     
00344     // Fill in the entry (NB. obscure pointer arithmetic)
00345     PreferenceEntry *pEntry = pEntries + NumEntriesUsed;
00346     
00347     // Alex put in something to make a copy of the name
00348     UINT32 memsize = (camStrlen(Name) + 1) * sizeof(TCHAR);
00349     pEntry->Name = (LPTCHAR) CCMalloc( memsize );
00350     if (!pEntry->Name) return FALSE; // error already set
00351     camStrcpy(pEntry->Name, Name);
00352 //  pEntry->Name    = Name;
00353 
00354     pEntry->Data    = EntryData;
00355     pEntry->Type    = Type;
00356     
00357     // Update chunk information
00358     NumEntriesUsed++;
00359     
00360     // Return success
00361     return TRUE;
00362 }

BOOL PreferenceChunk::GetPrefValue LPTCHAR  Pref,
PrefData  EntryData,
PreferenceType  Type
 

Checks to see if the given preference exists in this chunk and if so returns the value currently assigned to that preference value by placing it in the variable pointed to by the PrefData structure passed in. This means one routine can be used as opposed to one per preference type.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/10/94
Parameters:
Pref - name of preference to look for. [INPUTS] EntryData - pointer to the variable that will be used to pass the preference value back in. Type - the type of this preference - i.e., the type of data pointed to by the EntryData argument.
EntryData - pointer to the variable that should now be set up to echo the [OUTPUTS] value of the specified preference.
Returns:
TRUE if the preference exists, FALSE otherwise.

Errors: -

See also:
PreferenceChunk::SetPrefValue

Definition at line 421 of file prefs.cpp.

00422 {
00423     PreferenceEntry *pEntry = pEntries;
00424     
00425     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00426     {
00427         if (camStricmp(Pref, pEntry->Name) == 0)
00428         {
00429             // Found it so it does exist
00430             // Check that the type corresponds to the correct one
00431             if (pEntry->Type == Type)
00432             {
00433                 // Preference exits and is of the correct type so return it by writing 
00434                 // the value pointed to by the preference into the value pointed to by
00435                 // the preference structure passed in.
00436                 switch (Type)
00437                 {
00438                     case    PREF_INT:
00439                         // integer supplied so use the pointer to integer
00440                         *EntryData.pInt = *pEntry->Data.pInt;
00441                     break;
00442                     case    PREF_UINT:
00443                         *EntryData.pUInt = *pEntry->Data.pUInt;
00444                     break;
00445                     case    PREF_DOUBLE:
00446                         *EntryData.pDouble = *pEntry->Data.pDouble;
00447                     break;
00448                     case    PREF_STRING:
00449                         // Shouldn't be required so disable
00450                         //*EntryData.pString = *pEntry->Data.pString;
00451                         return FALSE;
00452                     break;
00453                 }
00454                 return TRUE;
00455             }
00456             else
00457             {
00458                 return FALSE;
00459             }
00460         }
00461         // Move on to the next preference
00462         pEntry++;
00463     }
00464     
00465     // Not found
00466     return FALSE;
00467 }

BOOL PreferenceChunk::SetPrefValue LPTCHAR  Pref,
PrefData  EntryData,
PreferenceType  Type
 

Checks to see if the given preference exists in this chunk and if so sets the value stored in the preference user's variable to be the specified new value.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/10/94
Parameters:
Pref - name of preference to look for. [INPUTS] EntryData - pointer to the memory that is holding the value of this preference that we wish to set. Type - the type of this preference - i.e., the type of data pointed to by the EntryData argument.
- [OUTPUTS]
Returns:
TRUE if the preference exists, FALSE otherwise.

Errors: -

See also:
PreferenceChunk::GetPrefValue

Definition at line 489 of file prefs.cpp.

00490 {
00491     PreferenceEntry *pEntry = pEntries;
00492     
00493     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00494     {
00495         if (camStricmp(Pref, pEntry->Name) == 0)
00496         {
00497             // Found it so it does exist
00498             // Check that the type corresponds to the correct one
00499             if (pEntry->Type == Type)
00500             {
00501                 // Preference exits and is of the correct type so return it by writing 
00502                 // the value pointed to by the preference into the value pointed to by
00503                 // the preference structure passed in.
00504                 switch (Type)
00505                 {
00506                     case    PREF_INT:
00507                         // integer supplied so use the pointer to integer
00508                         *pEntry->Data.pInt = *EntryData.pInt;
00509                     break;
00510                     case    PREF_UINT:
00511                         *pEntry->Data.pUInt = *EntryData.pUInt;
00512                     break;
00513                     case    PREF_DOUBLE:
00514                         *pEntry->Data.pDouble = *EntryData.pDouble;
00515                     break;
00516                     case    PREF_STRING:
00517                         // Shouldn't be required so disable
00518                         //*EntryData.pString = *pEntry->Data.pString;
00519                         return FALSE;
00520                     break;
00521                 }
00522                 return TRUE;
00523             }
00524             else
00525             {
00526                 return FALSE;
00527             }
00528         }
00529         // Move on to the next preference
00530         pEntry++;
00531     }
00532     
00533     // Not found
00534     return FALSE;
00535 }

void PreferenceChunk::Write OILPreferences OILPrefs,
LPTCHAR  Section
 

Writes out all the preferences contained in this chunk object, using the OIL.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/93
Parameters:
OILPrefs - The OIL object to use to write the preferences out with. [INPUTS] Section - the name of the section that this chunk is a part of.
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 380 of file prefs.cpp.

00381 {
00382     // Write out each preference in this chunk
00383 
00384     PreferenceEntry *pEntry = pEntries;
00385     
00386     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00387     {
00388         // Write this preference
00389         OILPrefs->Write(Section, pEntry->Name, pEntry->Type, pEntry->Data);
00390 
00391         // Move on to the next preference
00392         pEntry++;
00393     }
00394 }


Member Data Documentation

UINT32 PreferenceChunk::NumEntries [private]
 

Definition at line 180 of file prefs.cpp.

UINT32 PreferenceChunk::NumEntriesUsed [private]
 

Definition at line 181 of file prefs.cpp.

PreferenceEntry* PreferenceChunk::pEntries [private]
 

Definition at line 183 of file prefs.cpp.

BOOL PreferenceChunk::Valid
 

Definition at line 186 of file prefs.cpp.


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