LMMS
Loading...
Searching...
No Matches
juce::PropertiesFile Class Reference

#include <juce_PropertiesFile.h>

Inheritance diagram for juce::PropertiesFile:
juce::PropertySet juce::ChangeBroadcaster juce::Timer

Classes

struct  Options

Public Types

enum  StorageFormat { storeAsBinary , storeAsCompressedBinary , storeAsXML }

Public Member Functions

 PropertiesFile (const Options &options)
 PropertiesFile (const File &file, const Options &options)
 ~PropertiesFile () override
bool isValidFile () const noexcept
bool saveIfNeeded ()
bool save ()
bool needsToBeSaved () const
void setNeedsToBeSaved (bool needsToBeSaved)
bool reload ()
const FilegetFile () const noexcept
Public Member Functions inherited from juce::PropertySet
 PropertySet (bool ignoreCaseOfKeyNames=false)
 PropertySet (const PropertySet &other)
PropertySetoperator= (const PropertySet &other)
virtual ~PropertySet ()
String getValue (StringRef keyName, const String &defaultReturnValue=String()) const noexcept
int getIntValue (StringRef keyName, int defaultReturnValue=0) const noexcept
double getDoubleValue (StringRef keyName, double defaultReturnValue=0.0) const noexcept
bool getBoolValue (StringRef keyName, bool defaultReturnValue=false) const noexcept
std::unique_ptr< XmlElementgetXmlValue (StringRef keyName) const
void setValue (StringRef keyName, const var &value)
void setValue (StringRef keyName, const XmlElement *xml)
void addAllPropertiesFrom (const PropertySet &source)
void removeValue (StringRef keyName)
bool containsKey (StringRef keyName) const noexcept
void clear ()
StringPairArraygetAllProperties () noexcept
const CriticalSectiongetLock () const noexcept
std::unique_ptr< XmlElementcreateXml (const String &nodeName) const
void restoreFromXml (const XmlElement &xml)
void setFallbackPropertySet (PropertySet *fallbackProperties) noexcept
PropertySetgetFallbackPropertySet () const noexcept
Public Member Functions inherited from juce::ChangeBroadcaster
 ChangeBroadcaster () noexcept
virtual ~ChangeBroadcaster ()
void addChangeListener (ChangeListener *listener)
void removeChangeListener (ChangeListener *listener)
void removeAllChangeListeners ()
void sendChangeMessage ()
void sendSynchronousChangeMessage ()
void dispatchPendingMessages ()

Protected Member Functions

void propertyChanged () override

Private Types

using ProcessScopedLock = const std::unique_ptr<InterProcessLock::ScopedLockType>

Private Member Functions

InterProcessLock::ScopedLockTypecreateProcessLock () const
void timerCallback () override
bool saveAsXml ()
bool saveAsBinary ()
bool loadAsXml ()
bool loadAsBinary ()
bool loadAsBinary (InputStream &)
bool writeToStream (OutputStream &)
Private Member Functions inherited from juce::Timer
virtual ~Timer ()
void startTimer (int intervalInMilliseconds) noexcept
void startTimerHz (int timerFrequencyHz) noexcept
void stopTimer () noexcept
bool isTimerRunning () const noexcept
int getTimerInterval () const noexcept
 Timer () noexcept
 Timer (const Timer &) noexcept

Private Attributes

File file
Options options
bool loadedOk = false
bool needsWriting = false

Additional Inherited Members

Static Private Member Functions inherited from juce::Timer
static void JUCE_CALLTYPE callAfterDelay (int milliseconds, std::function< void()> functionToCall)
static void JUCE_CALLTYPE callPendingTimersSynchronously ()

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

@tags{DataStructures}

Member Typedef Documentation

◆ ProcessScopedLock

using juce::PropertiesFile::ProcessScopedLock = const std::unique_ptr<InterProcessLock::ScopedLockType>
private

Member Enumeration Documentation

◆ StorageFormat

enum juce::PropertiesFile::StorageFormat
Enumerator
storeAsBinary 
storeAsCompressedBinary 
storeAsXML 

Constructor & Destructor Documentation

◆ PropertiesFile() [1/2]

juce::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() [2/2]

juce::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()

juce::PropertiesFile::~PropertiesFile ( )
override

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

Member Function Documentation

◆ createProcessLock()

InterProcessLock::ScopedLockType * juce::PropertiesFile::createProcessLock ( ) const
private

◆ getFile()

const File & juce::PropertiesFile::getFile ( ) const
inlinenoexcept

Returns the file that's being used.

◆ isValidFile()

bool juce::PropertiesFile::isValidFile ( ) const
inlinenoexcept

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.

◆ loadAsBinary() [1/2]

bool juce::PropertiesFile::loadAsBinary ( )
private

◆ loadAsBinary() [2/2]

bool juce::PropertiesFile::loadAsBinary ( InputStream & input)
private

◆ loadAsXml()

bool juce::PropertiesFile::loadAsXml ( )
private

◆ needsToBeSaved()

bool juce::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().

◆ propertyChanged()

void juce::PropertiesFile::propertyChanged ( )
overrideprotectedvirtual

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

Reimplemented from juce::PropertySet.

◆ reload()

bool juce::PropertiesFile::reload ( )

Attempts to reload the settings from the file.

◆ save()

bool juce::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

◆ saveAsBinary()

bool juce::PropertiesFile::saveAsBinary ( )
private

◆ saveAsXml()

bool juce::PropertiesFile::saveAsXml ( )
private

◆ saveIfNeeded()

bool juce::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

◆ setNeedsToBeSaved()

void juce::PropertiesFile::setNeedsToBeSaved ( bool needsToBeSaved)

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

See also
needsToBeSaved

◆ timerCallback()

void juce::PropertiesFile::timerCallback ( )
overrideprivatevirtual

The user-defined callback routine that actually gets called periodically.

It's perfectly ok to call startTimer() or stopTimer() from within this callback to change the subsequent intervals.

Implements juce::Timer.

◆ writeToStream()

bool juce::PropertiesFile::writeToStream ( OutputStream & out)
private

Member Data Documentation

◆ file

File juce::PropertiesFile::file
private

◆ loadedOk

bool juce::PropertiesFile::loadedOk = false
private

◆ needsWriting

bool juce::PropertiesFile::needsWriting = false
private

◆ options

Options juce::PropertiesFile::options
private

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