Public Member Functions | List of all members
ime::PrefContainer Class Reference

Container for Preference instances. More...

#include <PrefContainer.h>

Public Member Functions

void load (const std::string &filename)
 Load preferences from the disk. More...
 
bool addPref (const Preference &pref)
 Add a preference to the container. More...
 
bool addPref (Preference &&)
 
PreferencegetPref (const std::string &key)
 Get a preference. More...
 
const PreferencegetPref (const std::string &key) const
 
bool hasPref (const std::string &key)
 Check if the container has a preference or not. More...
 
void removePref (const std::string &key)
 Remove a preference from the container. More...
 
void clear ()
 Remove all preferences from the container. More...
 
std::size_t getCount () const
 Get the number of preferences in the container. More...
 
PropertyContainer asPropertyContainer () const
 Convert preference to properties. More...
 
void save (const std::string &filename="sameAsLoadFile")
 Save preferences to the disk. More...
 

Detailed Description

Container for Preference instances.

A PrefContainer is very similar to a PropertyContainer. What sets them apart is that a PrefContainer can load/save its contents from/to a file on the disk. In addition, a PrefContainer is convertible to a PropertyContainer

Definition at line 42 of file PrefContainer.h.

Member Function Documentation

◆ addPref()

bool ime::PrefContainer::addPref ( const Preference pref)

Add a preference to the container.

Parameters
prefThe preference to be added
Returns
True if the preference was added or false if a preference with the same key already exits in the container

◆ asPropertyContainer()

PropertyContainer ime::PrefContainer::asPropertyContainer ( ) const

Convert preference to properties.

Returns
Preferences as properties
Attention
This function was released in IME v2.1.0 and is intended for compatibility with previous release (IME v2.0.0). In IME v2.1.0, ime::utility::ConfigFileParser is deprecated and replaced by ime::PrefContainer, thus you can load configs with ime::PrefContainer and use this function to convert ime::PrefContainer into ime::PropertyContainer which was returned by ime::utility::ConfigFileParser without the need to change your code to work with ime::PrefContainer instances.

◆ clear()

void ime::PrefContainer::clear ( )

Remove all preferences from the container.

◆ getCount()

std::size_t ime::PrefContainer::getCount ( ) const

Get the number of preferences in the container.

Returns
The number of preferences in the container

◆ getPref()

Preference & ime::PrefContainer::getPref ( const std::string &  key)

Get a preference.

Parameters
keyThe key of the preference to retrieve
Returns
A preference with the specified key

◆ hasPref()

bool ime::PrefContainer::hasPref ( const std::string &  key)

Check if the container has a preference or not.

Parameters
keyThe key of the preference to be checked
Returns
True if the preference exist, otherwise false

◆ load()

void ime::PrefContainer::load ( const std::string &  filename)

Load preferences from the disk.

Parameters
filenameThe name of the file to load the preferences from
Exceptions
FileNotFoundExceptionIf filename cannot be opened for reading
InvalidParseExceptionIf the contents of filename cannot be successfully parsed
Note
All current data is destroyed on subsequent function calls
See also
save

◆ removePref()

void ime::PrefContainer::removePref ( const std::string &  key)

Remove a preference from the container.

Parameters
keyThe key of the preference to be removed

◆ save()

void ime::PrefContainer::save ( const std::string &  filename = "sameAsLoadFile")

Save preferences to the disk.

Parameters
filenameThe name of the file to save the preferences to
Exceptions
FileNotFoundExceptionIf filename cannot be opened for writing

If filename is left unspecified, the engine will attempt to write the data to the same file as the load file.

Warning
This function will overwrite the file
See also
load

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