36 static constexpr size_t npos = EntryVector::npos;
83 IniProfile(
const std::string& section,
const std::string& path);
105 [[nodiscard]]
int getInt(
const std::string& key,
int defaultInt = 0)
const;
110 bool getString(
const std::string& key, std::string& value,
const std::string& defaultString = {})
const;
125 [[nodiscard]] std::string
getString(
const std::string& key,
const std::string& defaultString = {})
const;
130 bool setString(
const std::string& key,
const std::string& st);
135 bool setInt(
const std::string& key,
int value);
141 bool setSection(
const std::string& section,
bool create =
true);
163 [[nodiscard]]
inline size_type getSectionCount()
const;
189 return findSection(section) != npos;
198 [[nodiscard]]
bool keyExists(
const std::string& key)
const
201 return _sections.empty() ? npos : _sections[_sectionIndex]->findEntry(key) != npos;
207 inline bool removeSection(
const std::string& section);
298 _writeOnDirty = enable;
312 virtual std::ostream&
write(std::ostream& os)
const;
341 bool load(
const std::string& path);
356 Entry(
const std::string& key,
const std::string& value);
358 explicit Entry(
const std::string& comment);
362 std::ostream&
write(std::ostream& os);
366 [[nodiscard]]
inline bool isValid()
const;
369 bool _cmtFlag{
false};
407 int setEntry(
const std::string& key,
const std::string& value);
415 std::string
getEntry(
const std::string& key,
const std::string& defValue);
437 std::ostream&
write(std::ostream& os);
486 bool _flagClearOnRead{
true};
490 bool _writeOnDirty{
true};
504 return !_key.empty();
514 return profile.
write(os);
Internal storage class for keys.
Definition IniProfile.h:352
std::ostream & write(std::ostream &os)
bool setLine(const std::string &)
bool read(std::istream &is)
Entry(const std::string &comment)
bool isValid() const
Definition IniProfile.h:502
Entry(const std::string &key, const std::string &value)
Internal storage class for sections.
Definition IniProfile.h:380
bool insertComment(const std::string &key, const std::string &comment)
Adds comment to before entry specified by the key.
bool read(std::istream &is)
Read section from an input stream.
std::string _name
Holds the name of the section.
Definition IniProfile.h:449
bool removeEntry(EntryVector::size_type index)
Removes an entry from an index position.
std::ostream & write(std::ostream &os)
Streams section to an output stream.
IniProfile::EntryVector::size_type findEntry(const std::string &key)
Finds an entry by key value.
Section()
Default constructor.
Definition IniProfile.h:385
EntryVector _entries
Holds the key value pairs.
Definition IniProfile.h:454
int setEntry(const std::string &key, const std::string &value)
Sets sections value by key name.
std::string getEntry(const std::string &key, const std::string &defValue)
Gets an entry string and returns a default when it does not exist.
Class for reading and writing ini-profiles.
Definition IniProfile.h:16
bool setString(const std::string &key, const std::string &st)
Sets a string class value making the Dirty flag true.
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...
size_type findSection(const std::string §ion) const
Finds current or specific section location in list.
Entry * getEntry(EntryVector::size_type p)
Gets nullptr if not exist.
SectionVector _sections
Vector holding all sections.
Definition IniProfile.h:470
bool removeSection(const std::string §ion)
Removes a section by name.
Definition IniProfile.h:507
bool selectSection(const std::string §ion) const
EntryVector::size_type size_type
Type definition for the used size.
Definition IniProfile.h:41
bool removeSection(size_type p)
Removes a section by position.
IniProfile(const std::string_view &data)
Initializing constructor using string. Create by reading from std::istream current position.
IniProfile(const std::string §ion, const std::string &path)
Initializing constructor. If filename is empty the startup path is selected.
IniProfile(const std::string &path)
Initializing constructor.
bool load(std::istream &is)
InitializeBase from stream.
void setWriteOnDirty(bool enable)
Set the write-on-dirty flag so changes are written on destruction. The default is true.
Definition IniProfile.h:296
bool sync()
Syncs the content to file when dirty.
bool load(const std::string &path)
InitializeBase from file path.
IniProfile()
Default constructor for empty instance.
size_type getSectionCount() const
Gets the section count.
Definition IniProfile.h:497
bool setSection(const std::string §ion, bool create=true)
Sets current section, returns true if section exist and creates one if 'create' is true.
KeyValueMap getMap(size_type section=npos) const
Gets the key value map from the current selected section by default or the section provided.
strings getKeys(size_type section=npos) const
Gets the keys of the current section or of the passed section index.
std::string getSection(size_type p=npos) const
Get current or specific section name p is index in section list.
void flush()
Flushes/Removes all sections from this instance.
bool setFilepath(const std::string &path)
Set the path of this instance.
bool insertComment(const std::string &key, const std::string &comment)
Inserts comment before existing key.
size_type findEntry(const std::string &key)
Finds in the current section the key, on failure it returns npos.
bool removeEntry(const std::string &key)
Removes entry by key name.
bool setInt(const std::string &key, int value)
Sets an (int) value and sets the Dirty flag to true.
void setKeyPrefix(const std::string &prefix={})
Prepends prefix to key if prefix not null.
void initialize()
Function called in any constructor.
int getInt(const std::string &key, int defaultInt=0) const
Works the same as TProfile from OWL.
std::string _prefix
olds the prefix for all entered 'key's'.
Definition IniProfile.h:494
strings getSections() const
Get all section names in a std::string vector.
TVector< Section * > SectionVector
Internally used type.
Definition IniProfile.h:460
size_type getEntryCount() const
Returns amount of entries in the current section.
bool isDirty() const
Tells if there write functions are used or not.
Definition IniProfile.h:322
IniProfile(const IniProfile &)=delete
Copying this class is not possible.
IniProfile & operator=(IniProfile &&)=delete
No move operator either.
const std::string & getFilepath() const
IniProfile(std::istream &is)
Initializing constructor. Create by reading from std::istream current position.
IniProfile & operator=(IniProfile &)=delete
No copy operator either.
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 read(std::istream &is)
Add sections from other std::istream.
TVector< Entry * > EntryVector
Internally used type.
Definition IniProfile.h:31
bool removeEntry(size_type p)
Removes entry or comment by position.
bool sectionExists(const std::string §ion) const
Returns whether the passed section exist in the profile.
Definition IniProfile.h:187
virtual std::ostream & write(std::ostream &os) const
read to std::ostream 'os' current position.
bool getString(const std::string &key, std::string &value, const std::string &defaultString={}) const
Works the same as TProfile from OWL.
std::ostream & writeSection(std::ostream &os) const
read current section to an 'ostream'.
bool setSection(size_type index)
Sets current section by index.
bool keyExists(const std::string &key) const
Returns whether the passed key exist in the current selected in the section of the profile.
Definition IniProfile.h:198
std::string getEntryValue(size_type p)
Get entry key in current section, returns key or comment.
IniProfile(const IniProfile &&)=delete
No move constructor either.
std::string _path
Path to file if it was created with one otherwise 'length' is zero.
Definition IniProfile.h:478
std::map< std::string, std::string > KeyValueMap
Type for retrieving key and values.
Definition IniProfile.h:251
virtual ~IniProfile()
Virtual destructor writes to file path when dirty.
std::string getString(const std::string &key, const std::string &defaultString={}) const
Gets a string class value.
Counted vector of strings.
Definition TStrings.h:12
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:25
base_type::size_type size_type
Size type of this template.
Definition TVector.h:34
size_type count() const
Returns the amount of entries in the vector.
Definition TVector.h:625
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.