IniFile Class Reference

INI file helper class. More...

#include <IniFile.h>

List of all members.

Classes

struct  key

Public Types

enum  errors { noID = -1 }

Public Member Functions

 IniFile (std::string const iniPath="")
 Class constructor.
void CaseSensitive ()
 Enable INI case sensitivity.
void CaseInsensitive ()
 Disable INI case sensitivity.
void SetPath (std::string const newPath)
 Set INI file path.
std::string GetPath () const
 Get INI file path.
bool ReadFile ()
 Read INI file.
bool WriteFile ()
 Write INI file.
void Reset ()
 Reset the INI file.
long FindKey (std::string const keyname) const
 Find INI key index.
long FindValue (unsigned const keyID, std::string const valuename) const
 Find INI value index.
unsigned GetNumKeys () const
 Get number of keys.
unsigned AddKeyName (std::string const keyname)
 Add INI key.
std::string GetKeyName (unsigned const keyID) const
 Get INI key name.
unsigned GetNumValues (unsigned const keyID)
 Get number of INI values.
unsigned GetNumValues (std::string const keyname)
 Get number of INI values.
std::string GetValueName (unsigned const keyID, unsigned const valueID) const
 Get INI value name.
std::string GetValueName (std::string const keyname, unsigned const valueID) const
 Get INI value name.
std::string GetValue (unsigned const keyID, unsigned const valueID, std::string const defValue="") const
 Get INI value - by index.
std::string GetValue (std::string const keyname, std::string const valuename, std::string const defValue="") const
 Get INI value - generic.
int GetValueI (std::string const keyname, std::string const valuename, int const defValue=0) const
 Get INI value - integer.
bool GetValueB (std::string const keyname, std::string const valuename, bool const defValue=false) const
 Get INI value - boolean.
double GetValueF (std::string const keyname, std::string const valuename, double const defValue=0.0) const
 Get INI value - floating point.
unsigned GetValueV (std::string const keyname, std::string const valuename, char *format,...)
 Get INI value - scanf-style.
bool SetValue (unsigned const keyID, unsigned const valueID, std::string const value)
 Set INI value - by index.
bool SetValue (std::string const keyname, std::string const valuename, std::string const value, bool const create=true)
 Set INI value - generic.
bool SetValueI (std::string const keyname, std::string const valuename, int const value, bool const create=true)
 Set INI value - integer.
bool SetValueB (std::string const keyname, std::string const valuename, bool const value, bool const create=true)
 Set INI value - boolean.
bool SetValueF (std::string const keyname, std::string const valuename, double const value, bool const create=true)
 Set INI value - floating point.
bool SetValueV (std::string const keyname, std::string const valuename, char *format,...)
 Set INI value - printf style.
bool DeleteValue (std::string const keyname, std::string const valuename)
 Delete INI value.
bool DeleteKey (std::string keyname)
 Delete INI key.
unsigned GetNumHeaderComments ()
 Number of header comments.
void AddHeaderComment (std::string const comment)
 Add INI header comment.
std::string GetHeaderComment (unsigned const commentID) const
 Get INI header comment.
bool DeleteHeaderComment (unsigned commentID)
 Delete INI header comment.
void DeleteHeaderComments ()
 Delete all header comments.
unsigned GetNumKeyComments (unsigned const keyID) const
 Get number of key comments.
unsigned GetNumKeyComments (std::string const keyname) const
 Get number of key comments.
bool AddKeyComment (unsigned const keyID, std::string const comment)
 Add INI key comment.
bool AddKeyComment (std::string const keyname, std::string const comment)
 Add INI key comment.
std::string GetKeyComment (unsigned const keyID, unsigned const commentID) const
 Get INI key comment.
std::string GetKeyComment (std::string const keyname, unsigned const commentID) const
 Get INI key comment.
bool DeleteKeyComment (unsigned const keyID, unsigned const commentID)
 Delete INI key comment.
bool DeleteKeyComment (std::string const keyname, unsigned const commentID)
 Delete INI key comment.
bool DeleteKeyComments (unsigned const keyID)
 Delete all INI key comments.
bool DeleteKeyComments (std::string const keyname)
 Delete all INI key comments.

Detailed Description

INI file helper class.

This class is a helper for handling INI files. It provides a number of useful functions for reading and writing INI keys and their values.


Member Enumeration Documentation

List of error codes

Enumerator:
noID 

INI key index not found


Constructor & Destructor Documentation

IniFile::IniFile ( std::string const   iniPath = ""  ) 

Class constructor.

Initializes the INI file object.

Parameters:
iniPath Contains the path to the INI file.

Member Function Documentation

void IniFile::AddHeaderComment ( std::string const   comment  ) 

Add INI header comment.

Adds a comment to the INI file header. Header comments are those comments before the first key.

Parameters:
comment Contains the comment text.
bool IniFile::AddKeyComment ( std::string const   keyname,
std::string const   comment 
)

Add INI key comment.

Adds a comment to the specified key of the INI file.

Parameters:
keyname Specifies the name of the key.
comment Contains the text of the comment.
Returns:
Returns true if the comment was added succesfully.
bool IniFile::AddKeyComment ( unsigned const   keyID,
std::string const   comment 
)

Add INI key comment.

Adds a comment to the specified key of the INI file.

Parameters:
keyID Specifies the key index.
comment Contains the text of the comment.
Returns:
Returns true if the comment was added succesfully.
unsigned IniFile::AddKeyName ( std::string const   keyname  ) 

Add INI key.

Inserts the new key (or section) to the INI file.

Parameters:
keyname Contains the name of the new key.
Returns:
Returns the key index.
void IniFile::CaseInsensitive (  )  [inline]

Disable INI case sensitivity.

Disables the case sensitivity. All operations on INI file keys and values become case insensitive. This is the default behavior.

void IniFile::CaseSensitive (  )  [inline]

Enable INI case sensitivity.

Enables the case sensitivity. All operations on INI file keys and values become case sensitive.

bool IniFile::DeleteHeaderComment ( unsigned  commentID  ) 

Delete INI header comment.

Delete a comment from the INI file header.

Parameters:
commentID Specifies the comment line index.
Returns:
Returns true if the line was deleted successfully.
void IniFile::DeleteHeaderComments (  )  [inline]

Delete all header comments.

Clears all comments from the INI file header.

bool IniFile::DeleteKey ( std::string  keyname  ) 

Delete INI key.

Removes the specified key with all contained values.

Parameters:
keyname Specifies the name of the key to be removed.
Returns:
Returns true if the key was deleted successfully.
bool IniFile::DeleteKeyComment ( std::string const   keyname,
unsigned const   commentID 
)

Delete INI key comment.

Removes the comment related to the specific key of the INI file.

Parameters:
keyname Specifies the name of the key.
commentID Specifies the comment line index.
Returns:
Returns true if the comment was deleted successfully.
bool IniFile::DeleteKeyComment ( unsigned const   keyID,
unsigned const   commentID 
)

Delete INI key comment.

Removes the comment related to the specific key of the INI file.

Parameters:
keyID Specifies the key index.
commentID Specifies the comment line index.
Returns:
Returns true if the comment was deleted successfully.
bool IniFile::DeleteKeyComments ( std::string const   keyname  ) 

Delete all INI key comments.

Removes all comments related to the specific key of the INI file.

Parameters:
keyname Specifies the name of the key.
Returns:
Returns true if all comments were deleted successfully.
bool IniFile::DeleteKeyComments ( unsigned const   keyID  ) 

Delete all INI key comments.

Removes all comments related to the specific key of the INI file.

Parameters:
keyID Specifies the key index.
Returns:
Returns true if all comments were deleted successfully.
bool IniFile::DeleteValue ( std::string const   keyname,
std::string const   valuename 
)

Delete INI value.

Removes the given value assigned to a specified key.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value to be removed.
Returns:
Returns true if the value was deleted successfully.
long IniFile::FindKey ( std::string const   keyname  )  const

Find INI key index.

Finds an index for the given key name.

Parameters:
keyname Contains the name of the key.
Returns:
Returns a valid key index, or noID on failure.
long IniFile::FindValue ( unsigned const   keyID,
std::string const   valuename 
) const

Find INI value index.

Finds an index for the given value under the given key name.

Parameters:
keyID Contains the key index.
valuename Contains the name of the value.
Returns:
Returns a valid value index, or noID on failure.
std::string IniFile::GetHeaderComment ( unsigned const   commentID  )  const

Get INI header comment.

Return a comment from the INI file header.

Parameters:
commentID Specifies the comment line index.
Returns:
Returns the requested comment line.
std::string IniFile::GetKeyComment ( std::string const   keyname,
unsigned const   commentID 
) const

Get INI key comment.

Retrieves the comment related to the specified key of the INI file.

Parameters:
keyname Specifies the name of the key.
commentID Specifies the comment line index.
Returns:
Returns the text of the comment line.
std::string IniFile::GetKeyComment ( unsigned const   keyID,
unsigned const   commentID 
) const

Get INI key comment.

Retrieves the comment related to the specified key of the INI file.

Parameters:
keyID Specifies the key index.
commentID Specifies the comment line index.
Returns:
Returns the text of the comment line.
std::string IniFile::GetKeyName ( unsigned const   keyID  )  const

Get INI key name.

Parameters:
keyID Specifies the key index.
Returns:
Returns the name of the key.
unsigned IniFile::GetNumHeaderComments (  )  [inline]

Number of header comments.

Returns:
Returns the total number of header comments.
unsigned IniFile::GetNumKeyComments ( std::string const   keyname  )  const

Get number of key comments.

Parameters:
keyname Specifies the name of the key.
Returns:
Returns the total number of key comments.
unsigned IniFile::GetNumKeyComments ( unsigned const   keyID  )  const

Get number of key comments.

Parameters:
keyID Specifies the key index.
Returns:
Returns the total number of key comments.
unsigned IniFile::GetNumKeys (  )  const [inline]

Get number of keys.

Returns:
Returns the total number of keys currently in the INI file.
unsigned IniFile::GetNumValues ( std::string const   keyname  ) 

Get number of INI values.

Parameters:
keyname Specifies the name of the key.
Returns:
Returns the number of values associated with the given key.
unsigned IniFile::GetNumValues ( unsigned const   keyID  ) 

Get number of INI values.

Parameters:
keyID Specifies the key index.
Returns:
Returns the number of values associated with the given key.
std::string IniFile::GetPath (  )  const [inline]

Get INI file path.

Returns:
Returns the path of the INI file.
std::string IniFile::GetValue ( std::string const   keyname,
std::string const   valuename,
std::string const   defValue = "" 
) const

Get INI value - generic.

Retrieves the data of the given INI value associated with the specified key.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
defValue Contains the default value data to be returned if the value does not exist.
Returns:
Returns the text data of the requested value.
std::string IniFile::GetValue ( unsigned const   keyID,
unsigned const   valueID,
std::string const   defValue = "" 
) const

Get INI value - by index.

Retrieves the data of the given INI value associated with the specified key.

Parameters:
keyID Specifies the key index that contains the value.
valueID Specifies the value index.
defValue Contains the default value data to be returned if the value does not exist.
Returns:
Returns the text data of the requested value.
bool IniFile::GetValueB ( std::string const   keyname,
std::string const   valuename,
bool const   defValue = false 
) const [inline]

Get INI value - boolean.

Retrieves the boolean data of the given INI value associated with the specified key.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
defValue Contains the default value data to be returned if the value does not exist.
Returns:
Returns the boolean data of the requested value.
double IniFile::GetValueF ( std::string const   keyname,
std::string const   valuename,
double const   defValue = 0.0 
) const

Get INI value - floating point.

Retrieves the floating point data of the given INI value associated with the specified key.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
defValue Contains the default value data to be returned if the value does not exist.
Returns:
Returns the floating point data of the requested value.
int IniFile::GetValueI ( std::string const   keyname,
std::string const   valuename,
int const   defValue = 0 
) const

Get INI value - integer.

Retrieves the integer data of the given INI value associated with the specified key.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
defValue Contains the default value data to be returned if the value does not exist.
Returns:
Returns the integer data of the requested value.
std::string IniFile::GetValueName ( std::string const   keyname,
unsigned const   valueID 
) const

Get INI value name.

Retrieves the name of the value associated with the given key.

Parameters:
keyname Contains the name of the key.
valueID Specifies the value index.
Returns:
Returns the name of the value.
std::string IniFile::GetValueName ( unsigned const   keyID,
unsigned const   valueID 
) const

Get INI value name.

Retrieves the name of the value associated with the given key.

Parameters:
keyID Specifies the key index.
valueID Specifies the value index.
Returns:
Returns the name of the value.
unsigned IniFile::GetValueV ( std::string const   keyname,
std::string const   valuename,
char *  format,
  ... 
)

Get INI value - scanf-style.

Parses the data of the given INI value associated with the specified key. Supports scanf-style formatting fields and a variable number of destinations.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
format Contains the data parsing format with printf-style formatting fields.
... Contains a variable number of destination pointers for parsed fields.
Returns:
Returns the floating point data of the requested value.
bool IniFile::ReadFile (  ) 

Read INI file.

Reads the INI file using the path specified in the constructor.

Returns:
Returns true if successful, false otherwise.
void IniFile::Reset (  ) 

Reset the INI file.

Deletes all stored INI file data.

void IniFile::SetPath ( std::string const   newPath  )  [inline]

Set INI file path.

Sets the path of the INI file for reading and writing.

Parameters:
newPath Contains the INI file name.
bool IniFile::SetValue ( std::string const   keyname,
std::string const   valuename,
std::string const   value,
bool const   create = true 
)

Set INI value - generic.

Sets the given value of the specified key to text data.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
value Contains the value text.
create Indicates if the value should be added if it does not exist.
Returns:
Returns true if the value was set successfully. On error returns false.
bool IniFile::SetValue ( unsigned const   keyID,
unsigned const   valueID,
std::string const   value 
)

Set INI value - by index.

Sets the given value of the specified key to text data.

Parameters:
keyID Specifies the key index that contains the value.
valueID Specifies the value index.
value Contains the value text.
Returns:
Returns true if the value was set successfully. On error returns false.
bool IniFile::SetValueB ( std::string const   keyname,
std::string const   valuename,
bool const   value,
bool const   create = true 
) [inline]

Set INI value - boolean.

Sets the given value of the specified key to boolean data.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
value Contains the boolean value.
create Indicates if the value should be added if it does not exist.
Returns:
Returns true if the value was set successfully. On error returns false.
bool IniFile::SetValueF ( std::string const   keyname,
std::string const   valuename,
double const   value,
bool const   create = true 
)

Set INI value - floating point.

Sets the given value of the specified key to floating point data.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
value Contains the floating point value.
create Indicates if the value should be added if it does not exist.
Returns:
Returns true if the value was set successfully. On error returns false.
bool IniFile::SetValueI ( std::string const   keyname,
std::string const   valuename,
int const   value,
bool const   create = true 
)

Set INI value - integer.

Sets the given value of the specified key to integer data.

Parameters:
keyname Specifies the name of the key that contains the value.
valuename Specifies the name of the value.
value Contains the integer value.
create Indicates if the value should be added if it does not exist.
Returns:
Returns true if the value was set successfully. On error returns false.
bool IniFile::SetValueV ( std::string const   keyname,
std::string const   valuename,
char *  format,
  ... 
)

Set INI value - printf style.

Sets the given value of the specified key to text data with formatting field support.

Parameters:
keyname Specifies the name of the key that contains the value
valuename Specifies the name of the value.
format Contains the value text with printf-style formatting fields.
... Contains a variable number of arguments for formatting fields.
Returns:
Returns true if the value was set successfully. On error returns false.
bool IniFile::WriteFile (  ) 

Write INI file.

Writes the INI file using the path specified in the constructor.

Returns:
Returns true if the file was written successfully.

The documentation for this class was generated from the following files:
Generated on Wed Oct 20 11:13:44 2010 for libspatha by  doxygen 1.6.3