Classes | Public Types | Public Member Functions | Protected Member Functions

PropertiesFile Class Reference

Wrapper on a file that stores a list of key/value data pairs. More...

Inherits PropertySet, ChangeBroadcaster, and Timer.

List of all members.

Classes

struct  Options

Public Types

enum  StorageFormat { storeAsBinary, storeAsCompressedBinary, storeAsXML }

Public Member Functions

 PropertiesFile (const Options &options)
 Creates a PropertiesFile object.
 PropertiesFile (const File &file, const Options &options)
 Creates a PropertiesFile object.
 ~PropertiesFile ()
 Destructor.
bool isValidFile () const noexcept
 Returns true if this file was created from a valid (or non-existent) file.
bool saveIfNeeded ()
 This will flush all the values to disk if they've changed since the last time they were saved.
bool save ()
 This will force a write-to-disk of the current values, regardless of whether anything has changed since the last save.
bool needsToBeSaved () const
 Returns true if the properties have been altered since the last time they were saved.
void setNeedsToBeSaved (bool needsToBeSaved)
 Explicitly sets the flag to indicate whether the file needs saving or not.
File getFile () const
 Returns the file that's being used.

Protected Member Functions

virtual void propertyChanged ()
 Subclasses can override this to be told when one of the properies has been changed.

Detailed Description

Wrapper on a file that stores a list of key/value data pairs.

Useful for storing application settings, etc. See the PropertySet class for the interfaces that read and write values.

Not designed for very large amounts of data, as it keeps all the values in memory and writes them out to disk lazily when they are changed.

Because this class derives from ChangeBroadcaster, ChangeListeners can be registered with it, and these will be signalled when a value changes.

See also:
PropertySet

Member Enumeration Documentation

Enumerator:
storeAsBinary 
storeAsCompressedBinary 
storeAsXML 

Constructor & Destructor Documentation

PropertiesFile::PropertiesFile ( const Options options ) [explicit]

Creates a PropertiesFile object.

The file used will be chosen by calling PropertiesFile::Options::getDefaultFile() for the options provided. To set the file explicitly, use the other constructor.

PropertiesFile::PropertiesFile ( const File file,
const Options options 
)

Creates a PropertiesFile object.

Unlike the other constructor, this one allows you to explicitly set the file that you want to be used, rather than using the default one.

PropertiesFile::~PropertiesFile (  )

Destructor.

When deleted, the file will first call saveIfNeeded() to flush any changes to disk.


Member Function Documentation

bool PropertiesFile::isValidFile (  ) const

Returns true if this file was created from a valid (or non-existent) file.

If the file failed to load correctly because it was corrupt or had insufficient access, this will be false.

bool PropertiesFile::saveIfNeeded (  )

This will flush all the values to disk if they've changed since the last time they were saved.

Returns false if it fails to write to the file for some reason (maybe because it's read-only or the directory doesn't exist or something).

See also:
save
bool PropertiesFile::save (  )

This will force a write-to-disk of the current values, regardless of whether anything has changed since the last save.

Returns false if it fails to write to the file for some reason (maybe because it's read-only or the directory doesn't exist or something).

See also:
saveIfNeeded
bool PropertiesFile::needsToBeSaved (  ) const

Returns true if the properties have been altered since the last time they were saved.

The file is flagged as needing to be saved when you change a value, but you can explicitly set this flag with setNeedsToBeSaved().

void PropertiesFile::setNeedsToBeSaved ( bool  needsToBeSaved )

Explicitly sets the flag to indicate whether the file needs saving or not.

See also:
needsToBeSaved
File PropertiesFile::getFile (  ) const

Returns the file that's being used.

virtual void PropertiesFile::propertyChanged (  ) [protected, virtual]

Subclasses can override this to be told when one of the properies has been changed.

Reimplemented from PropertySet.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines