![]() |
Scanframe Modular Application 0.1.0
|
Class for reading and writing ini-profiles. More...
#include <IniProfile.h>
Classes | |
class | Entry |
Internal storage class for keys. More... | |
class | Section |
Internal storage class for sections. More... | |
Public Types | |
typedef TVector< Entry * > | EntryVector |
Internally used type. | |
typedef EntryVector::size_type | size_type |
Type definition for the used size. | |
typedef std::map< std::string, std::string > | KeyValueMap |
Type for retrieving key and values. | |
Public Member Functions | |
IniProfile () | |
Default constructor for empty instance. | |
IniProfile (const std::string &path) | |
Initializing constructor. | |
IniProfile (const IniProfile &)=delete | |
Copying this class is not possible. | |
IniProfile (const IniProfile &&)=delete | |
No move constructor either. | |
IniProfile & | operator= (IniProfile &)=delete |
No copy operator either. | |
IniProfile & | operator= (IniProfile &&)=delete |
No move operator either. | |
IniProfile (const std::string §ion, const std::string &path) | |
Initializing constructor. If filename is empty the startup path is selected. | |
IniProfile (const std::string_view &data) | |
Initializing constructor using string. Create by reading from std::istream current position. | |
IniProfile (std::istream &is) | |
Initializing constructor. Create by reading from std::istream current position. | |
virtual | ~IniProfile () |
Virtual destructor writes to file path when dirty. | |
int | getInt (const std::string &key, int defaultInt=0) const |
Works the same as TProfile from OWL. | |
bool | getString (const std::string &key, std::string &value, const std::string &defaultString={}) const |
Works the same as TProfile from OWL. | |
void | flush () |
Flushes/Removes all sections from this instance. | |
void | setKeyPrefix (const std::string &prefix={}) |
Prepends prefix to key if prefix not null. | |
std::string | getString (const std::string &key, const std::string &defaultString={}) const |
Gets a string class value. | |
bool | setString (const std::string &key, const std::string &st) |
Sets a string class value making the Dirty flag true. | |
bool | setInt (const std::string &key, int value) |
Sets an (int) value and sets the Dirty flag to true. | |
bool | setSection (const std::string §ion, bool create=true) |
Sets current section, returns true if section exist and creates one if 'create' is true. | |
bool | selectSection (const std::string §ion) const |
bool | setSection (size_type index) |
Sets current section by index. | |
size_type | getSectionCount () const |
Gets the section count. | |
std::string | getSection (size_type p=npos) const |
Get current or specific section name p is index in section list. | |
strings | getSections () const |
Get all section names in a std::string vector. | |
size_type | findSection (const std::string §ion) const |
Finds current or specific section location in list. | |
bool | sectionExists (const std::string §ion) const |
Returns whether the passed section exist in the profile. | |
bool | keyExists (const std::string &key) const |
Returns whether the passed key exist in the current selected in the section of the profile. | |
bool | removeSection (const std::string §ion) |
Removes a section by name. | |
bool | removeSection (size_type p) |
Removes a section by position. | |
bool | removeKeys (size_type section=npos) |
Removes all keys from a section by position or the current selected one if none has been passed. | |
bool | insertComment (const std::string &key, const std::string &comment) |
Inserts comment before existing key. | |
size_type | getEntryCount () const |
Returns amount of entries in the current section. | |
size_type | findEntry (const std::string &key) |
Finds in the current section the key, on failure it returns npos. | |
std::string | getEntryKey (size_type p) |
Returns the entry value in current section, returns key in case of a comment line it returns a string of zero length p is index in entry (key) list (includes comments !!) | |
strings | getKeys (size_type section=npos) const |
Gets the keys of the current section or of the passed section index. | |
KeyValueMap | getMap (size_type section=npos) const |
Gets the key value map from the current selected section by default or the section provided. | |
std::string | getEntryValue (size_type p) |
Get entry key in current section, returns key or comment. | |
bool | removeEntry (const std::string &key) |
Removes entry by key name. | |
bool | removeEntry (size_type p) |
Removes entry or comment by position. | |
bool | setFilepath (const std::string &path) |
Set the path of this instance. | |
const std::string & | getFilepath () const |
void | setWriteOnDirty (bool enable) |
Set the write-on-dirty flag so changes are written on destruction. The default is true. | |
bool | sync () |
Syncs the content to file when dirty. | |
virtual std::ostream & | write (std::ostream &os) const |
read to std::ostream 'os' current position. | |
std::ostream & | writeSection (std::ostream &os) const |
read current section to an 'ostream'. | |
bool | isDirty () const |
Tells if there write functions are used or not. | |
bool | read (std::istream &is) |
Add sections from other std::istream. | |
Static Public Attributes | |
static constexpr size_t | npos = EntryVector::npos |
Index not found return value. | |
Protected Types | |
typedef TVector< Section * > | SectionVector |
Internally used type. | |
Protected Member Functions | |
void | initialize () |
Function called in any constructor. | |
bool | load (const std::string &path) |
InitializeBase from file path. | |
bool | load (std::istream &is) |
InitializeBase from stream. | |
Entry * | getEntry (EntryVector::size_type p) |
Gets nullptr if not exist. | |
Protected Attributes | |
class _MISC_CLASS | Entry |
Forward declaration and also having export attributes. | |
class _MISC_CLASS | Section |
Forward declaration and also having export attributes. | |
SectionVector | _sections |
Vector holding all sections. | |
SectionVector::size_type | _sectionIndex {npos} |
Current index to section. | |
std::string | _path |
Path to file if it was created with one otherwise 'length' is zero. | |
bool | _dirty {false} |
Is Set to true if an entry has been changed. | |
bool | _flagClearOnRead {true} |
If this flag is Set all fields read with 'ReadType' will be cleared. | |
bool | _writeOnDirty {true} |
When true the profile is written to the file path that was used to read it. | |
std::string | _prefix |
olds the prefix for all entered 'key's'. | |
Class for reading and writing ini-profiles.
typedef TVector<Entry*> sf::IniProfile::EntryVector |
Internally used type.
typedef std::map<std::string, std::string> sf::IniProfile::KeyValueMap |
Type for retrieving key and values.
|
protected |
Internally used type.
Type definition for the used size.
sf::IniProfile::IniProfile | ( | ) |
Default constructor for empty instance.
|
explicit |
Initializing constructor.
path | Filepath to the ini-file. |
|
delete |
Copying this class is not possible.
|
delete |
No move constructor either.
sf::IniProfile::IniProfile | ( | const std::string & | section, |
const std::string & | path | ||
) |
Initializing constructor. If filename is empty the startup path is selected.
|
explicit |
Initializing constructor using string. Create by reading from std::istream current position.
|
explicit |
Initializing constructor. Create by reading from std::istream current position.
|
virtual |
Virtual destructor writes to file path when dirty.
size_type sf::IniProfile::findEntry | ( | const std::string & | key | ) |
Finds in the current section the key, on failure it returns npos.
size_type sf::IniProfile::findSection | ( | const std::string & | section | ) | const |
Finds current or specific section location in list.
void sf::IniProfile::flush | ( | ) |
Flushes/Removes all sections from this instance.
|
protected |
Gets nullptr if not exist.
size_type sf::IniProfile::getEntryCount | ( | ) | const |
Returns amount of entries in the current section.
std::string sf::IniProfile::getEntryKey | ( | size_type | p | ) |
Returns the entry value in current section, returns key in case of a comment line it returns a string of zero length p is index in entry (key) list (includes comments !!)
std::string sf::IniProfile::getEntryValue | ( | size_type | p | ) |
Get entry key in current section, returns key or comment.
const std::string & sf::IniProfile::getFilepath | ( | ) | const |
Gets the file path when it is set.
int sf::IniProfile::getInt | ( | const std::string & | key, |
int | defaultInt = 0 |
||
) | const |
Works the same as TProfile from OWL.
KeyValueMap sf::IniProfile::getMap | ( | size_type | section = npos | ) | const |
Gets the key value map from the current selected section by default or the section provided.
section | Index of the section (default 'npos' = current) |
Get current or specific section name p is index in section list.
|
inline |
Gets the section count.
strings sf::IniProfile::getSections | ( | ) | const |
Get all section names in a std::string vector.
std::string sf::IniProfile::getString | ( | const std::string & | key, |
const std::string & | defaultString = {} |
||
) | const |
Gets a string class value.
bool sf::IniProfile::getString | ( | const std::string & | key, |
std::string & | value, | ||
const std::string & | defaultString = {} |
||
) | const |
Works the same as TProfile from OWL.
|
protected |
Function called in any constructor.
bool sf::IniProfile::insertComment | ( | const std::string & | key, |
const std::string & | comment | ||
) |
Inserts comment before existing key.
|
inline |
Tells if there write functions are used or not.
|
inline |
Returns whether the passed key exist in the current selected in the section of the profile.
key | Key name. |
|
protected |
InitializeBase from file path.
|
protected |
InitializeBase from stream.
|
delete |
No move operator either.
|
delete |
No copy operator either.
bool sf::IniProfile::read | ( | std::istream & | is | ) |
Add sections from other std::istream.
bool sf::IniProfile::removeEntry | ( | const std::string & | key | ) |
Removes entry by key name.
bool sf::IniProfile::removeEntry | ( | size_type | p | ) |
Removes entry or comment by position.
Removes all keys from a section by position or the current selected one if none has been passed.
|
inline |
Removes a section by name.
bool sf::IniProfile::removeSection | ( | size_type | p | ) |
Removes a section by position.
|
inline |
Returns whether the passed section exist in the profile.
section | Section name. |
bool sf::IniProfile::selectSection | ( | const std::string & | section | ) | const |
Selects section without creating.
section |
bool sf::IniProfile::setFilepath | ( | const std::string & | path | ) |
Set the path of this instance.
When the current file is dirty it is first written to disk.
path | Filepath to the ini-file. |
bool sf::IniProfile::setInt | ( | const std::string & | key, |
int | value | ||
) |
Sets an (int) value and sets the Dirty flag to true.
void sf::IniProfile::setKeyPrefix | ( | const std::string & | prefix = {} | ) |
Prepends prefix to key if prefix not null.
bool sf::IniProfile::setSection | ( | const std::string & | section, |
bool | create = true |
||
) |
Sets current section, returns true if section exist and creates one if 'create' is true.
bool sf::IniProfile::setSection | ( | size_type | index | ) |
bool sf::IniProfile::setString | ( | const std::string & | key, |
const std::string & | st | ||
) |
Sets a string class value making the Dirty flag true.
|
inline |
Set the write-on-dirty flag so changes are written on destruction. The default is true.
enable |
bool sf::IniProfile::sync | ( | ) |
Syncs the content to file when dirty.
If the instance was created using a filepath the content is written when the dirty flag was set.
|
virtual |
read to std::ostream 'os' current position.
std::ostream & sf::IniProfile::writeSection | ( | std::ostream & | os | ) | const |
read current section to an 'ostream'.
|
protected |
Is Set to true if an entry has been changed.
|
protected |
If this flag is Set all fields read with 'ReadType' will be cleared.
|
protected |
Path to file if it was created with one otherwise 'length' is zero.
|
protected |
olds the prefix for all entered 'key's'.
H
|
protected |
Current index to section.
|
protected |
Vector holding all sections.
|
protected |
When true the profile is written to the file path that was used to read it.
|
protected |
Forward declaration and also having export attributes.
|
staticconstexpr |
Index not found return value.
|
protected |
Forward declaration and also having export attributes.