Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Classes | Public Types | Public Member Functions | List of all members
HFCore::Preferences Class Referenceabstract

Interface for Preferences base class. More...

#include <Preferences.h>

Classes

struct  Child
 Struct representing a Preferences profile child. More...
 
struct  Profile
 Struct representing a Preferences profile. More...
 
struct  SubChild
 Struct representing a Preferences profile child's sub child. More...
 

Public Types

typedef std::map< UString, UStringPrefAttributesMap
 typedef for map holding UString pairs used for holding Preferences attributes name / value pair.
 
typedef std::map< int32_hf, SubChildPrefSubChildsMap
 typedef for map holding int32_hf / SubChild pairs. Used to hold a profiles child's subchildren.
 
typedef std::map< int32_hf, ChildPrefChildsMap
 typedef for map holding int32_hf / Child pairs. Used to hold a profiles children.
 
typedef std::map< int32_hf, ProfilePrefProfilesMap
 typedef for map holding int32_hf / Profile pairs. Used to hold all profiles.
 

Public Member Functions

 Preferences ()
 Constructor.
 
virtual ~Preferences ()
 Destructor.
 
virtual void createDefaultProfile ()=0
 Create a default profile. Calls createProfile() with DefaultProfileName fetched from Environment::getGameConfigMap(). More...
 
virtual int32_hf createProfile (const UString &profileName)=0
 Create a profile. More...
 
virtual void renameProfile (int32_hf profileID, const UString &newProfileName)=0
 Rename a profile. More...
 
virtual void removeProfile (int32_hf profileID)=0
 Remove a profile. More...
 
virtual PrefProfilesMapgetProfilesList ()=0
 Get a map of all Profiles. More...
 
virtual bool existsProfileByName (const UString &profileName)=0
 Checks if there exists a Profile for given profileName. More...
 
virtual bool existsProfileByName (const UString &profileName, const UString &profileNameToExclude)=0
 Checks if there exists a Profile for given profileName but exclude profileNameToExclude. More...
 
virtual bool existsProfile ()=0
 Checks if there exists at least one profile. More...
 
virtual void setCurrentProfile (int32_hf profileID)=0
 Set current Profile to use. More...
 
virtual int32_hf getCurrentProfileID ()=0
 Get the current Profile ID in use. More...
 
virtual const UString getCurrentProfileName ()=0
 Get current Profile name. More...
 
virtual int32_hf getProfileIDByName (const UString &profileName)=0
 Get Profile ID for given profileName. More...
 
virtual const UString getProfileNameByID (int32_hf profileID)=0
 Get Profile name for given Profile ID. More...
 
virtual int32_hf createChild (int32_hf profileID, const UString &childName)=0
 Create a Child for given profileID. More...
 
virtual int32_hf createChild (int32_hf profileID, const UString &childName, const UString &value)=0
 Create a Child for given profileID. More...
 
virtual int32_hf updateChild (int32_hf profileID, const UString &childName, const UString &value)=0
 Update a Child value for a given profileID and childName. More...
 
virtual void removeChild (int32_hf profileID, int32_hf childID)=0
 Remove a Child for given profileID and childID. More...
 
virtual const UString getChildValue (int32_hf profileID, int32_hf childID)=0
 Get Child value for given profileID and childID. More...
 
virtual int32_hf getChildIDByName (int32_hf profileID, const UString &childName)=0
 Get Child ID for given profileID and childName. More...
 
virtual bool existsChildIDByName (int32_hf profileID, const UString &childName)=0
 Check if there exists a Child ID for given profileID and childName. More...
 
virtual PrefChildsMapgetChildListByProfileID (int32_hf profileID)=0
 Get map containing all Child's for given profileID. More...
 
virtual PrefChildsMap getChildListByChildName (int32_hf profileID, const UString &childName)=0
 Get map containing all Child's for given profileID and childName. More...
 
virtual void setAttribute (int32_hf profileID, int32_hf childID, const UString &name, const UString &value)=0
 Set Child attribute for given profileID and childID. More...
 
virtual const UString getAttribute (int32_hf profileID, int32_hf childID, const UString &name)=0
 Get Child attribute value for given profileID and childID. More...
 
virtual void removeAttribute (int32_hf profileID, int32_hf childID, const UString &name)=0
 Remove Child attribute for given profileID and childID. More...
 
virtual int32_hf createSubChild (int32_hf profileID, int32_hf childID, const UString &subChildName)=0
 Create a SubChild for given profileID and childID. More...
 
virtual int32_hf createSubChild (int32_hf profileID, int32_hf childID, const UString &subChildName, const UString &subChildValue)=0
 Create a SubChild for given profileID and childID. More...
 
virtual int32_hf updateSubChild (int32_hf profileID, int32_hf childID, const UString &subChildName, const UString &value)=0
 Update SubChild for given profileID and childID. More...
 
virtual void removeSubChild (int32_hf profileID, int32_hf childID, int32_hf subChildID)=0
 Remove SubChild for given profileID, childID and subChildID. More...
 
virtual const UString getSubChildValue (int32_hf profileID, int32_hf childID, int32_hf subChildID)=0
 Get SubChild value for given profileID, childID and subChildID. More...
 
virtual int32_hf getSubChildIDByName (int32_hf profileID, int32_hf childID, const UString &subChildName)=0
 Get SubChild ID for given profileID, childID and subChildName. More...
 
virtual PrefSubChildsMapgetSubChildListByChildID (int32_hf profileID, int32_hf childID)=0
 Get map containing all SubChild's for given profileID and childID. More...
 
virtual PrefSubChildsMap getSubChildListBySubChildName (int32_hf profileID, int32_hf childID, const UString &subChildName)=0
 Get map containing all SubChild's for given profileID, childID and subChildName. More...
 
virtual void setAttribute (int32_hf profileID, int32_hf childID, int32_hf subChildID, const UString &name, const UString &value)=0
 Set SubChild attribute for given profileID, childID and subChildID. More...
 
virtual const UString getAttribute (int32_hf profileID, int32_hf childID, int32_hf subChildID, const UString &name)=0
 Get SubChild attribute value for given profileID, childID and subChildID. More...
 
virtual void removeAttribute (int32_hf profileID, int32_hf childID, int32_hf subChildID, const UString &name)=0
 Remove SubChild attribute for given profileID, childID and subChildID. More...
 
virtual void save ()=0
 Persist all cached Preferences to disk :)
 

Detailed Description

Interface for Preferences base class.

Preferences is useful for saving game settings and such.

During engine initialization a default profile will be created if none exists. All fields from Environment::getGameConfigMap() are copied over except those in comma separated list: ParamsToNotCopyToNewProfile.

See 'demos/demo1-minimal/data/config.xml' for an example on how a default config.xml should look like. You can add your own custom stuff in there which also will be copied over for each new profile created.

Current default implementation of this base class uses XML and here's how an example file looks like:

<?xml version="1.0" standalone="no" ?>
<GamePreferences>
<CurrentProfile id="1">Player</CurrentProfile>
<Profiles>
<Profile name="Player" id="1">
<AudioBufferSize id="1">1024</AudioBufferSize>
<AudioChannels id="2">2</AudioChannels>
<AudioRate id="3">44100</AudioRate>
<CustomCursor id="4">0</CustomCursor>
<EnableMultiSample id="5">0</EnableMultiSample>
<Fullscreen id="6">0</Fullscreen>
<FullscreenMode id="7">1</FullscreenMode>
<Language id="8">en</Language>
<LogicalScaleMode id="9">0</LogicalScaleMode>
<LogicalScreenHeight id="10">480</LogicalScreenHeight>
<LogicalScreenWidth id="11">640</LogicalScreenWidth>
<MultiSampleSamples id="12">4</MultiSampleSamples>
<MusicVol id="13">750</MusicVol>
<ScreenHeight id="14">480</ScreenHeight>
<ScreenWidth id="15">640</ScreenWidth>
<SoundVol id="16">600</SoundVol>
<WindowBorderless id="17">0</WindowBorderless>
<WindowResizable id="18">0</WindowResizable>
<NewChild id="19">
<NewSubChild_1 id="1">Value1</NewSubChild_1>
<NewSubChild_2 id="2">Value2</NewSubChild_2>
<NewSubChild_3 id="3">Value3</NewSubChild_3>
<NewSubChild_4 id="4">Value4</NewSubChild_4>
<NewSubChild_5 id="5">Value5</NewSubChild_5>
</NewChild>
</Profile>
</Profiles>
</GamePreferences>

C++ example code:

// create a child under default profile:
int32_hf profileID = HFCORE_PREF->getCurrentProfileID();
int32_hf newChildID = HFCORE_PREF->createChild(profileID, "NewChild");
// create a few SubChild's under default profile and newChildID:
int32_hf subChildID_1 = HFCORE_PREF->createSubChild(profileID,
newChildID,
"NewSubChild_1",
"Value1");
int32_hf subChildID_2 = HFCORE_PREF->createSubChild(profileID,
newChildID,
"NewSubChild_2",
"Value2");
int32_hf subChildID_3 = HFCORE_PREF->createSubChild(profileID,
newChildID,
"NewSubChild_3",
"Value3");
int32_hf subChildID_4 = HFCORE_PREF->createSubChild(profileID,
newChildID,
"NewSubChild_4",
"Value4");
int32_hf subChildID_5 = HFCORE_PREF->createSubChild(profileID,
newChildID,
"NewSubChild_5",
"Value5");
// when done make sure to persist cache to disk:
HFCORE_PREF->save();

Definition at line 124 of file Preferences.h.

Member Function Documentation

◆ createChild() [1/2]

virtual int32_hf HFCore::Preferences::createChild ( int32_hf  profileID,
const UString childName 
)
pure virtual

Create a Child for given profileID.

Parameters
profileIDProfile ID.
childNameName of the Child.
Returns
Child ID of the created Child.

◆ createChild() [2/2]

virtual int32_hf HFCore::Preferences::createChild ( int32_hf  profileID,
const UString childName,
const UString value 
)
pure virtual

Create a Child for given profileID.

Parameters
profileIDProfile ID.
childNameName of the Child.
valueValue.
Returns
Child ID of the created Child.

◆ createDefaultProfile()

virtual void HFCore::Preferences::createDefaultProfile ( )
pure virtual

Create a default profile. Calls createProfile() with DefaultProfileName fetched from Environment::getGameConfigMap().

See also
createProfile()

◆ createProfile()

virtual int32_hf HFCore::Preferences::createProfile ( const UString profileName)
pure virtual

Create a profile.

Fields from Environment::getGameConfigMap() are copied over except 'DefaultProfileName' and 'CompressPreferencesFile'.

Parameters
profileNameName of the profile.
Returns
Profile ID of created profile.

◆ createSubChild() [1/2]

virtual int32_hf HFCore::Preferences::createSubChild ( int32_hf  profileID,
int32_hf  childID,
const UString subChildName 
)
pure virtual

Create a SubChild for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildNameSubChild name.
Returns
SubChild ID of the created SubChild.

◆ createSubChild() [2/2]

virtual int32_hf HFCore::Preferences::createSubChild ( int32_hf  profileID,
int32_hf  childID,
const UString subChildName,
const UString subChildValue 
)
pure virtual

Create a SubChild for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildNameSubChild name.
subChildValueSubChild value.
Returns
SubChild ID of the created SubChild.

◆ existsChildIDByName()

virtual bool HFCore::Preferences::existsChildIDByName ( int32_hf  profileID,
const UString childName 
)
pure virtual

Check if there exists a Child ID for given profileID and childName.

Parameters
profileIDProfile ID.
childNameChild name.
Returns
true if there exists Child ID, else false.

◆ existsProfile()

virtual bool HFCore::Preferences::existsProfile ( )
pure virtual

Checks if there exists at least one profile.

Returns
true if at least one profile exists, else false.

◆ existsProfileByName() [1/2]

virtual bool HFCore::Preferences::existsProfileByName ( const UString profileName)
pure virtual

Checks if there exists a Profile for given profileName.

Parameters
profileNameProfile name to check for.
Returns
true if profile exists, else false.

◆ existsProfileByName() [2/2]

virtual bool HFCore::Preferences::existsProfileByName ( const UString profileName,
const UString profileNameToExclude 
)
pure virtual

Checks if there exists a Profile for given profileName but exclude profileNameToExclude.

Parameters
profileNameProfile name to check for.
profileNameToExcludeProfile name to exclude in search.
Returns
true if profile exists, else false.

◆ getAttribute() [1/2]

virtual const UString HFCore::Preferences::getAttribute ( int32_hf  profileID,
int32_hf  childID,
const UString name 
)
pure virtual

Get Child attribute value for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
nameName of attribute.
Returns
Child attribute value for given profileID and childID.

◆ getAttribute() [2/2]

virtual const UString HFCore::Preferences::getAttribute ( int32_hf  profileID,
int32_hf  childID,
int32_hf  subChildID,
const UString name 
)
pure virtual

Get SubChild attribute value for given profileID, childID and subChildID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildIDSubChild ID.
nameName of attribute.
Returns
SubChild attribute value for given profileID, childID and subChildID.

◆ getChildIDByName()

virtual int32_hf HFCore::Preferences::getChildIDByName ( int32_hf  profileID,
const UString childName 
)
pure virtual

Get Child ID for given profileID and childName.

Parameters
profileIDProfile ID.
childNameChild ID.
Returns
Child ID for given profileID and childName.

◆ getChildListByChildName()

virtual PrefChildsMap HFCore::Preferences::getChildListByChildName ( int32_hf  profileID,
const UString childName 
)
pure virtual

Get map containing all Child's for given profileID and childName.

Parameters
profileIDProfile ID.
childNameChild name.
Returns
Preferences::PrefChildsMap containing all Child's for given profileID and childName.

◆ getChildListByProfileID()

virtual PrefChildsMap& HFCore::Preferences::getChildListByProfileID ( int32_hf  profileID)
pure virtual

Get map containing all Child's for given profileID.

Parameters
profileIDProfile ID.
Returns
Preferences::PrefChildsMap containing all Child's for given profileID.

◆ getChildValue()

virtual const UString HFCore::Preferences::getChildValue ( int32_hf  profileID,
int32_hf  childID 
)
pure virtual

Get Child value for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
Returns
Child value for given profileID and childID.

◆ getCurrentProfileID()

virtual int32_hf HFCore::Preferences::getCurrentProfileID ( )
pure virtual

Get the current Profile ID in use.

Returns
Current Profile ID.

◆ getCurrentProfileName()

virtual const UString HFCore::Preferences::getCurrentProfileName ( )
pure virtual

Get current Profile name.

Returns
Current Profile name.

◆ getProfileIDByName()

virtual int32_hf HFCore::Preferences::getProfileIDByName ( const UString profileName)
pure virtual

Get Profile ID for given profileName.

Parameters
profileNameProfile name.
Returns
Profile ID for given profileName.

◆ getProfileNameByID()

virtual const UString HFCore::Preferences::getProfileNameByID ( int32_hf  profileID)
pure virtual

Get Profile name for given Profile ID.

Parameters
profileIDProfile ID.
Returns
Profile name for given Profile ID.

◆ getProfilesList()

virtual PrefProfilesMap& HFCore::Preferences::getProfilesList ( )
pure virtual

Get a map of all Profiles.

Returns
Preferences::PrefProfilesMap containing all profiles.

◆ getSubChildIDByName()

virtual int32_hf HFCore::Preferences::getSubChildIDByName ( int32_hf  profileID,
int32_hf  childID,
const UString subChildName 
)
pure virtual

Get SubChild ID for given profileID, childID and subChildName.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildNameSubChild name.
Returns
SubChild ID for given profileID, childID and subChildName.

◆ getSubChildListByChildID()

virtual PrefSubChildsMap& HFCore::Preferences::getSubChildListByChildID ( int32_hf  profileID,
int32_hf  childID 
)
pure virtual

Get map containing all SubChild's for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
Returns
Preferences::PrefSubChildsMap containing all SubChild's for given profileID and childID.

◆ getSubChildListBySubChildName()

virtual PrefSubChildsMap HFCore::Preferences::getSubChildListBySubChildName ( int32_hf  profileID,
int32_hf  childID,
const UString subChildName 
)
pure virtual

Get map containing all SubChild's for given profileID, childID and subChildName.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildNameSubChild name.
Returns
Preferences::PrefSubChildsMap containing all SubChild's for given profileID, childID and subChildName.

◆ getSubChildValue()

virtual const UString HFCore::Preferences::getSubChildValue ( int32_hf  profileID,
int32_hf  childID,
int32_hf  subChildID 
)
pure virtual

Get SubChild value for given profileID, childID and subChildID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildIDSubChild ID.
Returns
SubChild value for given profileID, childID and subChildID.

◆ removeAttribute() [1/2]

virtual void HFCore::Preferences::removeAttribute ( int32_hf  profileID,
int32_hf  childID,
const UString name 
)
pure virtual

Remove Child attribute for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
nameName of attribute.

◆ removeAttribute() [2/2]

virtual void HFCore::Preferences::removeAttribute ( int32_hf  profileID,
int32_hf  childID,
int32_hf  subChildID,
const UString name 
)
pure virtual

Remove SubChild attribute for given profileID, childID and subChildID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildIDSubChild ID.
nameName of attribute.

◆ removeChild()

virtual void HFCore::Preferences::removeChild ( int32_hf  profileID,
int32_hf  childID 
)
pure virtual

Remove a Child for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.

◆ removeProfile()

virtual void HFCore::Preferences::removeProfile ( int32_hf  profileID)
pure virtual

Remove a profile.

Parameters
profileIDID of the profile to remove.

◆ removeSubChild()

virtual void HFCore::Preferences::removeSubChild ( int32_hf  profileID,
int32_hf  childID,
int32_hf  subChildID 
)
pure virtual

Remove SubChild for given profileID, childID and subChildID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildIDSubChild ID.

◆ renameProfile()

virtual void HFCore::Preferences::renameProfile ( int32_hf  profileID,
const UString newProfileName 
)
pure virtual

Rename a profile.

Parameters
profileIDProfile ID.
newProfileNameNew name for the Profile.

◆ setAttribute() [1/2]

virtual void HFCore::Preferences::setAttribute ( int32_hf  profileID,
int32_hf  childID,
const UString name,
const UString value 
)
pure virtual

Set Child attribute for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
nameName of attribute.
valueValue of attribute.

◆ setAttribute() [2/2]

virtual void HFCore::Preferences::setAttribute ( int32_hf  profileID,
int32_hf  childID,
int32_hf  subChildID,
const UString name,
const UString value 
)
pure virtual

Set SubChild attribute for given profileID, childID and subChildID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildIDSubChild ID.
nameName of attribute.
valueValue of attribute.

◆ setCurrentProfile()

virtual void HFCore::Preferences::setCurrentProfile ( int32_hf  profileID)
pure virtual

Set current Profile to use.

Parameters
profileIDProfile ID.

◆ updateChild()

virtual int32_hf HFCore::Preferences::updateChild ( int32_hf  profileID,
const UString childName,
const UString value 
)
pure virtual

Update a Child value for a given profileID and childName.

Parameters
profileIDProfile ID.
childNameChild name.
valueNew value.
Returns
Child ID of the updated Child.

◆ updateSubChild()

virtual int32_hf HFCore::Preferences::updateSubChild ( int32_hf  profileID,
int32_hf  childID,
const UString subChildName,
const UString value 
)
pure virtual

Update SubChild for given profileID and childID.

Parameters
profileIDProfile ID.
childIDChild ID.
subChildNameSubChild name.
valueSubChild value to update.
Returns
SubChild ID of the updated SubChild.

The documentation for this class was generated from the following file: