Jameo Core Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
jm::Preferences Class Reference

The Preferences class abstracts the reading and writing of properties in a preferences file. The file should have the extension .properties. More...

Inheritance diagram for jm::Preferences:
jm::Hashtable jm::Object jm::I18nBundle

Public Member Functions

 Preferences ()
 Constructor.
 
 ~Preferences () override
 Destructor. Deletes all entries in the hashtable.
 
void load (File file)
 This method reads the data from the file.
 
void save (File file)
 This method writes the preferences to the file.
 
bool hasValue (const String &key) const
 Check if the property is present.
 
void setValue (const String &key, const String &value)
 Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.
 
void setValue (const String &key, int64 value)
 Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.
 
void setValue (const String &key, double value)
 Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.
 
void setValue (const String &key, bool value)
 Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.
 
String value (const String &key) const
 Returns the desired property.
 
String value (const String &key, const String &defaultValue) const
 Returns the desired property.
 
int64 valueInt (const String &key, int64 defaultValue) const
 Returns the desired property.
 
double valueDouble (const String &key, double defaultValue) const
 Returns the desired property.
 
bool valueBool (const String &key, bool defaultValue) const
 Returns the desired property.
 
- Public Member Functions inherited from jm::Hashtable
 Hashtable () noexcept
 Default constructor for the Hashtable class.
 
 ~Hashtable () noexcept override
 Destructor for the Hashtable class.
 
void * put (String key, void *value) noexcept
 This method inserts a new element into the hash table.
 
void * get (const String &key) const noexcept
 This method returns the object associated with the specified key.
 
void * remove (const String &key) noexcept
 This method removes the object associated with the specified key.
 
size_t size () const noexcept
 Returns the number of entries in this hash table.
 
bool isEmpty () const noexcept
 This method returns true if the hashtable is empty.
 
bool containsKey (const String &key) const noexcept
 This method returns true if an object is associated with the specified key.
 
bool containsValue (void *value) const noexcept
 This method returns true if the hashtable contains an object associated with the specified value.
 
Iteratorkeys () noexcept
 This method returns an object of the "Iterator" class that iterates through the keys of this table.
 
Iteratorvalues () noexcept
 This method returns an object of the "Iterator" class that iterates through the values of this table.
 
void clear () noexcept
 This method removes all elements from the Hashtable.
 
- Public Member Functions inherited from jm::Object
 Object () noexcept
 Constructor.
 
virtual ~Object () noexcept
 Destructor.
 
void release () noexcept
 Decreases the reference counter and releases the object immediately when the reference counter becomes 0.
 
Objectretain () noexcept
 Increases the reference counter of this object by 1.
 
Objectautorelease () noexcept
 Same function as release(), but releases the object with a delay if the reference counter is 0. AutoreleasePool::drain() must be called in the to release the object.
 
int32 referenceCount () const noexcept
 Returns the value of the reference counter.
 
virtual bool equals (const Object *other) const
 Comparison of objects.
 
virtual String displayName () const
 Returns the display name of the object intended to present to a user.
 
virtual void printDiffInfo (DiffOperation operation, Object *other) const
 Output method for outputting the diff results for the diff algorithm.
 
void setHighBit (bool status) noexcept
 
bool highBit () const noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from jm::Hashtable
void rehash () noexcept
 This method increases the capacity of the Hashtable.
 

Detailed Description

The Preferences class abstracts the reading and writing of properties in a preferences file. The file should have the extension .properties.

Constructor & Destructor Documentation

◆ Preferences()

jm::Preferences::Preferences ( )

Constructor.

◆ ~Preferences()

jm::Preferences::~Preferences ( )
override

Destructor. Deletes all entries in the hashtable.

Member Function Documentation

◆ hasValue()

bool jm::Preferences::hasValue ( const String key) const

Check if the property is present.

Parameters
keyThe key of the property to check.
Returns
true if the property is present, false otherwise.

◆ load()

void jm::Preferences::load ( File  file)

This method reads the data from the file.

Parameters
fileThe file containing the properties.
Exceptions
Exceptionif the file is not found or is corrupted.

◆ save()

void jm::Preferences::save ( File  file)

This method writes the preferences to the file.

Parameters
fileThe name of the file where the properties will be saved.
Exceptions
Exceptionif the file cannot be written.

◆ setValue() [1/4]

void jm::Preferences::setValue ( const String key,
bool  value 
)

Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.

Parameters
keyThe property key.
valueThe value.

◆ setValue() [2/4]

void jm::Preferences::setValue ( const String key,
const String value 
)

Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.

Parameters
keyThe property key.
valueThe value.

◆ setValue() [3/4]

void jm::Preferences::setValue ( const String key,
double  value 
)

Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.

Parameters
keyThe property key.
valueThe value.

◆ setValue() [4/4]

void jm::Preferences::setValue ( const String key,
int64  value 
)

Sets the property. Essentially calls the Put() method of Hashtable, but ensures that strings are used.

Parameters
keyThe property key.
valueThe value.

◆ value() [1/2]

String jm::Preferences::value ( const String key) const

Returns the desired property.

Parameters
keyThe property key.
Returns
The value of the property.

◆ value() [2/2]

String jm::Preferences::value ( const String key,
const String defaultValue 
) const

Returns the desired property.

Parameters
keyThe property key.
defaultValueThe value of the property if it is not found.
Returns
The value of the property.

◆ valueBool()

bool jm::Preferences::valueBool ( const String key,
bool  defaultValue 
) const

Returns the desired property.

Parameters
keyThe property key.
defaultValueThe value of the property if it is not found.
Returns
The value of the property.

◆ valueDouble()

double jm::Preferences::valueDouble ( const String key,
double  defaultValue 
) const

Returns the desired property.

Parameters
keyThe property key.
defaultValueThe value of the property if it is not found.
Returns
The value of the property.

◆ valueInt()

int64 jm::Preferences::valueInt ( const String key,
int64  defaultValue 
) const

Returns the desired property.

Parameters
keyThe property key.
defaultValueThe value of the property if it is not found.
Returns
The value of the property.