Axmol Engine 2.4.0-258ceca
Loading...
Searching...
No Matches
UserDefault Class Reference

UserDefault acts as a tiny database. More...

#include <UserDefault.h>

Public Member Functions

bool getBoolForKey (const char *key)
 Get bool value by key, if the key doesn't exist, will return false.
 
virtual bool getBoolForKey (const char *key, bool defaultValue)
 Get bool value by key, if the key doesn't exist, will return passed default value.
 
int getIntegerForKey (const char *key)
 Get integer value by key, if the key doesn't exist, will return 0.
 
virtual int getIntegerForKey (const char *key, int defaultValue)
 Get integer value by key, if the key doesn't exist, will return passed default value.
 
int64_t getLargeIntForKey (const char *key)
 Get large integer value by key, if the key doesn't exist, will return 0.
 
virtual int64_t getLargeIntForKey (const char *key, int64_t defaultValue)
 Get large integer value by key, if the key doesn't exist, will return passed default value.
 
float getFloatForKey (const char *key)
 Get float value by key, if the key doesn't exist, will return 0.0.
 
virtual float getFloatForKey (const char *key, float defaultValue)
 Get float value by key, if the key doesn't exist, will return passed default value.
 
double getDoubleForKey (const char *key)
 Get double value by key, if the key doesn't exist, will return 0.0.
 
virtual double getDoubleForKey (const char *key, double defaultValue)
 Get double value by key, if the key doesn't exist, will return passed default value.
 
std::string_view getStringForKey (const char *key)
 Get string value by key, if the key doesn't exist, will return an empty string.
 
virtual std::string_view getStringForKey (const char *key, std::string_view defaultValue)
 Get string value by key, if the key doesn't exist, will return passed default value.
 
virtual void setBoolForKey (const char *key, bool value)
 Set bool value by key.
 
virtual void setIntegerForKey (const char *key, int value)
 Set integer value by key.
 
virtual void setLargeIntForKey (const char *key, int64_t value)
 Set large integer value by key.
 
virtual void setFloatForKey (const char *key, float value)
 Set float value by key.
 
virtual void setDoubleForKey (const char *key, double value)
 Set double value by key.
 
virtual void setStringForKey (const char *key, std::string_view value)
 Set string value by key.
 
virtual void flush ()
 Since we reimplement UserDefault with file mapping io, you don't needs call this function manually @js NA.
 
virtual void deleteValueForKey (const char *key)
 delete any value by key,
 

Static Public Member Functions

static UserDefaultgetInstance ()
 Returns the singleton.
 
static void destroyInstance ()
 @js NA
 
static void setDelegate (UserDefault *delegate)
 You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation.
 

Detailed Description

UserDefault acts as a tiny database.

You can save and get base type values by it. For example, setBoolForKey("played", true) will add a bool value true into the database. Its key is "played". You can get the value of the key by getBoolForKey("played").

It supports the following base types: bool, int, float, double, string

Warning
: On windows, linux, use XML to store data, which means there are some limitations of the key string, for example, / is not valid.

Member Function Documentation

◆ getBoolForKey() [1/2]

bool getBoolForKey ( const char * key)

Get bool value by key, if the key doesn't exist, will return false.

You can set the default value, or it is false.

Parameters
keyThe key to get value.
Returns
Bool value by key. @js NA

◆ getBoolForKey() [2/2]

virtual bool getBoolForKey ( const char * key,
bool defaultValue )
virtual

Get bool value by key, if the key doesn't exist, will return passed default value.

Parameters
keyThe key to get value.
defaultValueThe default value to return if the key doesn't exist. @js NA

◆ getIntegerForKey() [1/2]

int getIntegerForKey ( const char * key)

Get integer value by key, if the key doesn't exist, will return 0.

You can set the default value, or it is 0.

Parameters
keyThe key to get value.
Returns
Integer value of the key. @js NA

◆ getIntegerForKey() [2/2]

virtual int getIntegerForKey ( const char * key,
int defaultValue )
virtual

Get integer value by key, if the key doesn't exist, will return passed default value.

Parameters
keyThe key to get value.
defaultValueThe default value to return if the key doesn't exist.
Returns
Integer value of the key. @js NA

◆ getLargeIntForKey() [1/2]

int64_t getLargeIntForKey ( const char * key)

Get large integer value by key, if the key doesn't exist, will return 0.

You can set the default value, or it is 0.

Parameters
keyThe key to get value.
Returns
Integer value of the key. @js NA

◆ getLargeIntForKey() [2/2]

virtual int64_t getLargeIntForKey ( const char * key,
int64_t defaultValue )
virtual

Get large integer value by key, if the key doesn't exist, will return passed default value.

Parameters
keyThe key to get value.
defaultValueThe default value to return if the key doesn't exist.
Returns
Integer value of the key. @js NA

◆ getFloatForKey() [1/2]

float getFloatForKey ( const char * key)

Get float value by key, if the key doesn't exist, will return 0.0.

Parameters
keyThe key to get value.
Returns
Float value of the key. @js NA

◆ getFloatForKey() [2/2]

virtual float getFloatForKey ( const char * key,
float defaultValue )
virtual

Get float value by key, if the key doesn't exist, will return passed default value.

Parameters
keyThe key to get value.
defaultValueThe default value to return if the key doesn't exist.
Returns
Float value of the key. @js NA

◆ getDoubleForKey() [1/2]

double getDoubleForKey ( const char * key)

Get double value by key, if the key doesn't exist, will return 0.0.

Parameters
keyThe key to get value.
Returns
Double value of the key. @js NA

◆ getDoubleForKey() [2/2]

virtual double getDoubleForKey ( const char * key,
double defaultValue )
virtual

Get double value by key, if the key doesn't exist, will return passed default value.

Parameters
keyThe key to get value.
defaultValueThe default value to return if the key doesn't exist.
Returns
Double value of the key. @js NA

◆ getStringForKey() [1/2]

std::string_view getStringForKey ( const char * key)

Get string value by key, if the key doesn't exist, will return an empty string.

Parameters
keyThe key to get value.
Returns
String value of the key. @js NA

◆ getStringForKey() [2/2]

virtual std::string_view getStringForKey ( const char * key,
std::string_view defaultValue )
virtual

Get string value by key, if the key doesn't exist, will return passed default value.

Parameters
keyThe key to get value.
defaultValueThe default value to return if the key doesn't exist.
Returns
String value of the key. @js NA

◆ setBoolForKey()

virtual void setBoolForKey ( const char * key,
bool value )
virtual

Set bool value by key.

Parameters
keyThe key to set.
valueA bool value to set to the key. @js NA

◆ setIntegerForKey()

virtual void setIntegerForKey ( const char * key,
int value )
virtual

Set integer value by key.

Parameters
keyThe key to set.
valueA integer value to set to the key. @js NA

◆ setLargeIntForKey()

virtual void setLargeIntForKey ( const char * key,
int64_t value )
virtual

Set large integer value by key.

Parameters
keyThe key to set.
valueA integer value to set to the key. @js NA

◆ setFloatForKey()

virtual void setFloatForKey ( const char * key,
float value )
virtual

Set float value by key.

Parameters
keyThe key to set.
valueA float value to set to the key. @js NA

◆ setDoubleForKey()

virtual void setDoubleForKey ( const char * key,
double value )
virtual

Set double value by key.

Parameters
keyThe key to set.
valueA double value to set to the key. @js NA

◆ setStringForKey()

virtual void setStringForKey ( const char * key,
std::string_view value )
virtual

Set string value by key.

Parameters
keyThe key to set.
valueA string value to set to the key. @js NA

◆ deleteValueForKey()

virtual void deleteValueForKey ( const char * key)
virtual

delete any value by key,

Parameters
keyThe key to delete value. @js NA

◆ getInstance()

static UserDefault * getInstance ( )
static

Returns the singleton.

@js NA @lua NA

◆ setDelegate()

static void setDelegate ( UserDefault * delegate)
static

You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation.

For example, your store native data base or other format store.

If you don't want to system default implementation after setting delegate, you can just pass nullptr to this function.

Warning
It will delete previous delegate

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