Inheritance diagram for PreferenceChunk:
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 |
PreferenceEntry * | pEntries |
Definition at line 165 of file prefs.cpp.
|
Constructs a chunk of memory which can contain preferences.
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 }
|
|
Destroys the PreferenceChunk - it deallocates any memory previously allocated for PreferenceEntry objects by this object.
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 }
|
|
Adds the given preference to this chunk.
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 }
|
|
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.
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 }
|
|
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.
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 }
|
|
Writes out all the preferences contained in this chunk object, using the OIL.
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 }
|
|
|
|
|
|
|
|
|