IniParser
This class parses an ini file in an array and provides methods to get int, strings and longs, plus other helper methods.
It speeds up the retrieving of values since it parses one time the file instead of reparsing it each time.
The zip file contains also some converting utilities (StringConversions.cpp/h).
Parser methods
IniParser::FromFile
This function reads and parses an ini file.
Prototype
void IniParser::FromFile(const tstring& iniFile);
Parameters
iniFile
Path to the file to be parsed..
Return values
No return value
Remarks
No notes
IniParser::FromString
This function reads and parses a string that contains ini content.
Prototype
void IniParser::FromFile(const tstring& buffer);
Parameters
buffer
[IN] String to be parsed..
Return values
No return value
Remarks
No notes
IniParser::ToFile
This function writes the ini content to file.
Prototype
void IniParser::ToFile(const tstring& iniFile);
Parameters
iniFile
[IN] Path to the file where the contents are to be written..
Return values
No return value
Remarks
No notes
Setter methods
IniParser::SetInt
This function set the integer under the specified group along with the specified key.
Prototype
void IniParser::SetInt(LPCTSTR group, LPCTSTR key, int value);
Parameters
group
[IN] The name of the group to which the integer will be copied. If the section does not exist, it is created.
key
[IN] The name of the key to be associated with a integer. If the key does not exist in the specified section, it is created.
value
[IN] The integer to be written to the ini file.
Return values
No return value
Remarks
No notes
IniParser::SetLong
This function set the long integer under the specified group along with the specified key.
Prototype
void IniParser::SetLong(LPCTSTR group, LPCTSTR key, int value);
Parameters
group
[IN] The name of the group to which the long integer will be copied. If the section does not exist, it is created.
key
[IN] The name of the key to be associated with a long integer. If the key does not exist in the specified section, it is created.
value
[IN] The long integer to be written to the ini file.
Return values
No return value
Remarks
No notes
IniParser::SetString
This function set the string under the specified group along with the specified key.
Prototype
void IniParser::SetString(LPCTSTR group, LPCTSTR key, int value);
Parameters
group
[IN] The name of the group to which the string will be copied. If the section does not exist, it is created.
key
[IN] The name of the key to be associated with a string. If the key does not exist in the specified section, it is created.
value
[IN] The string to be written to the ini file.
Return values
No return value
Remarks
No notes
Getter methods
IniParser::GetInt
This function get the integer in the specified group under with the specified key.
Prototype
int IniParser::GetInt(LPCTSTR group, LPCTSTR key, int defaultValue);
Parameters
group
[IN] The name of the group to which the integer will be copied.
key
[IN] The name of the key to be associated with a integer.
defaultValue
[IN] The integer value to return if the key doesn't exist.
Return values
The integer that corresponds to that key, or the defaultValue if the key doesn't exists
Remarks
No notes
IniParser::GetLong
This function set the long integer in the specified group under with the specified key.
Prototype
long IniParser::GetLong(LPCTSTR group, LPCTSTR key, long defaultValue);
Parameters
group
[IN] The name of the group to which the long integer will be copied.
key
[IN] The name of the key to be associated with a long integer.
defaultValue
[IN] The long integer value to return if the key doesn't exist.
Return values
The long integer that corresponds to that key, or the defaultValue if the key doesn't exists
Remarks
No notes
IniParser::GetString
This function set the string in the specified group along under the specified key.
Prototype
tstring IniParser::GetString(LPCTSTR group, LPCTSTR key, tstring defaultValue);
Parameters
group
[IN] The name of the group to which the string will be copied.
key
[IN] The name of the key to be associated with a string.
defaultValue
[IN] The string value to return if the key doesn't exist.
Return values
The string that corresponds to that key, or the defaultValue if the key doesn't exists
Remarks
No notes
Helper methods
IniParser::CountMatchingGroups
This function returns the count of the groups that contain the substring specified.
Prototype
int IniParser::CountMatchingGroups(LPCTSTR group);
Parameters
group
[IN] The substring that the groups should contain.
Return values
The number of the groups that contain the substring
Remarks
No notes
IniParser::EraseMatchingGroups
This function erases the groups that contain the substring specified.
Prototype
void IniParser::EraseMatchingGroups(LPCTSTR group);
Parameters
group
[IN] The substring that the groups should contain.
Return values
No return value
Remarks
No notes
IniParser::EraseGroup
This function set the string in the specified group along under the specified key.
Prototype
void IniParser::EraseGroup(LPCTSTR group);
Parameters
group
[IN] The name of the group be deleted along with all its keys and values.
Return values
No return value
Remarks
No notes
IniParser::MoveGroup
This function move the specified group to .
Prototype
void IniParser::MoveGroup(LPCTSTR group, int index);
Parameters
group
[IN] The name of the group to be moved.
index
[IN] The index where to move the group.
Return values
No return value
Remarks
No notes
IniParser::IsGroup
This function check if the specified group exists.
Prototype
BOOL IniParser::IsGroup(LPCTSTR group);
Parameters
group
[IN] The name of the group.
Return values
Returns TRUE if the group exists, or FALSE instead
Remarks
No notes
Example
IniParser ini;
ini.FromFile( "settings.ini" ) ;
BOOL boolOption = ini.GetInt( "group1", "booloption" , FALSE ) ;
BOOL boolOption2 = ini.GetInt( "group1", "booloption2" , TRUE ) ;
tstring strOption = ini.GetString( "group2", "stroption", "default value!" ) ;
boolOption = TRUE ;
boolOption2 = FALSE ;
strOption = "value not default!" ;
ini.SetInt( "group1", "booloption" , boolOption) ;
ini.SetInt( "group1", "booloption2" , boolOption2) ;
ini.SetInt( "group2", "stroption" , strOption) ;
ini.ToFile( "settings.ini" ) ;
Changelog
1.0
Comments No comments yet.
Script by Alex
This page was last modified
33 months, 4 weeks and 7 minutes ago