FileINI Class Reference

This class, which is composed completely of static methods, can be used to read and parse INI files. More...

#include <FileINI.h>

List of all members.

Public Member Functions

 FileINI ()
 Default constructor.
 FileINI (LPCTSTR lpFilename)
 Load INI data from file.
 FileINI (char *pData, DWORD dwSize, bool bOwn=true)
 Load INI data from memory buffer.
 FileINI (bool bUnicode, char *pData, DWORD dwSize, bool bOwn=true)
 Load memory data from buffer (unicode flag).
 ~FileINI ()
 Destructor.
bool HasData () const
 Checks if there's any data in the buffer.
bool LoadINIFile (LPCTSTR lpFilename)
 Loads a file.
bool GetLines (LPCTSTR pSection, TCHARSTRLIST &listLines, UINT uFlags=0)
 Retrieves all lines in the specified section of the INI file.
bool GetKeys (LPCTSTR pSection, TCHARSTR2STR &mapKeys, UINT uFlags=0)
 Retrieves all key names and values in all of the lines in the specified section of the INI file.
bool GetKeys (LPCTSTR pSection, INILINELIST &listLines, UINT uFlags=0)
 Retrieves all key names and values in all of the lines in the specified section of the INI file.
bool GetAllSections (TCHARSTRLIST &lSections)
 Retrieves the list of sections inside the INI file.

Static Public Member Functions

static bool GetLines (LPCTSTR pFilename, LPCTSTR pSection, TCHARSTRLIST &list, UINT uFlags=0)
 Retrieves all lines in the specified section of the INI file.
static bool GetKeys (LPCTSTR pFilename, LPCTSTR pSection, TCHARSTR2STR &mapKeys, UINT uFlags=0)
 Retrieves all key names and values in all of the lines in the specified section of the INI file.
static bool GetKeys (LPCTSTR pFilename, LPCTSTR pSection, INILINELIST &list, UINT uFlags=0)
 Retrieves all key names and values in all of the lines in the specified section of the INI file.
static bool GetVarValues (LPCTSTR pVarValue, TCHARSTRLIST &lValues)
 Parses a comma separated list of values, and returns their parsed list. Supports quotes.
static bool ReplaceVariables (LPCTSTR pValue, const TCHARSTR2STRLIST &lVariables, TCHARSTRLIST &lResults)
 Performs previously defined string replacements on a string.
static bool GetAllSections (LPCTSTR pFilename, TCHARSTRLIST &lSections)
 Retrieves the list of sections inside the INI file.

Protected Member Functions

bool TestUnicode ()
 Check to see if file INI file is in unicode.

Static Protected Member Functions

static bool CheckLineForSection (const WCHAR *pLine, std::tstring::size_type nLineLen, LPCTSTR pSection, std::tstring::size_type nSectionLen, bool bUnicode, bool &bFoundSection)
 Check if the line is the specified section header.
static void DoInitLine (const WCHAR *pLine, std::tstring::size_type nLineLen, INILINELIST &list, UINT uFlags, bool bUnicode)
 Parses a (non-section) line and adds the contents into the values pair list.
static bool TestUnicode (FILE *pFile)
 Check to see if the file is a unicode INI file; tested at the opened location (doesn't seek to the start!).

Protected Attributes

char * m_pData
 Buffer data.
bool m_bOwn
 Buffer ownership flag (true means the buffer should be deleted with the object).
bool m_bUnicode
 true if this is a unicode buffer
int m_nOffset
 Current offset in the buffer.

Detailed Description

This class, which is composed completely of static methods, can be used to read and parse INI files.

Definition at line 99 of file FileINI.h.


Constructor & Destructor Documentation

FileINI::FileINI ( LPCTSTR  lpFilename  ) 

Load INI data from file.

Parameters:
lpFilename Name of file to load

Definition at line 264 of file FileINI.cpp.

References LoadINIFile().

FileINI::FileINI ( char *  pData,
DWORD  dwSize,
bool  bOwn = true 
)

Load INI data from memory buffer.

Parameters:
pData Pointer to a data buffer
dwSize Size of the data buffer
bOwn true if the buffer should be released by this object, false if not

Definition at line 189 of file FileINI.cpp.

References m_bOwn, m_bUnicode, m_nOffset, m_pData, and TestUnicode().

FileINI::FileINI ( bool  bUnicode,
char *  pData,
DWORD  dwSize,
bool  bOwn = true 
)

Load memory data from buffer (unicode flag).

Parameters:
bUnicode true for Unicode data, false of ASCII
pData The data
dwSize The length of the data
bOwn true if the buffer should be released by this object, false if not

Definition at line 230 of file FileINI.cpp.

References m_bOwn, and m_pData.


Member Function Documentation

bool FileINI::CheckLineForSection ( const WCHAR *  pLine,
std::tstring::size_type  nLineLen,
LPCTSTR  pSection,
std::tstring::size_type  nSectionLen,
bool  bUnicode,
bool &  bFoundSection 
) [static, protected]

Check if the line is the specified section header.

Parameters:
pLine The line of data
nLineLen Length of line (either chars or WCHARS according to the unicode flag)
pSection The section header to look for
nSectionLen Length of section header name
bUnicode true if the data is in Unicode, false if in ASCII
[out] bFoundSection Flag updated to indicate if the line is in the section
Returns:
true if this line starts the section, false otherwise

Definition at line 512 of file FileINI.cpp.

References MakeTString(), and tstring.

Referenced by GetKeys(), and GetLines().

void FileINI::DoInitLine ( const WCHAR *  pLine,
std::tstring::size_type  nLineLen,
INILINELIST listLines,
UINT  uFlags,
bool  bUnicode 
) [static, protected]

Parses a (non-section) line and adds the contents into the values pair list.

Parameters:
pLine The line to parse
nLineLen Length of line (in chars or wide chars according to the bUnicode flag)
[out] listLines List of pairs to update
uFlags Parsing flags (combination of FileINI Flags)
bUnicode true if the data is in Unicode, false if in ASCII

Definition at line 542 of file FileINI.cpp.

References FILEINI_IGNORE_COMMENTS, FILEINI_TRIM, IsComment(), MakeTString(), Trim(), and tstring.

Referenced by GetKeys().

bool FileINI::GetAllSections ( LPCTSTR  pFilename,
TCHARSTRLIST lSections 
) [static]

Retrieves the list of sections inside the INI file.

Parameters:
pFilename The full filename of the INI file to read
[out] lSections List of available sections
Returns:
true if all went well, false if something failed

Definition at line 748 of file FileINI.cpp.

References MakeTString(), TestUnicode(), and TrimLen().

bool FileINI::GetAllSections ( TCHARSTRLIST lSections  ) 

Retrieves the list of sections inside the INI file.

Parameters:
[out] lSections List of available sections
Returns:
true if all went well, false if something failed

Definition at line 817 of file FileINI.cpp.

References FindNextLine(), m_bUnicode, m_nOffset, m_pData, MakeTString(), TrimLen(), and tstring.

bool FileINI::GetKeys ( LPCTSTR  pFilename,
LPCTSTR  pSection,
INILINELIST listLines,
UINT  uFlags = 0 
) [static]

Retrieves all key names and values in all of the lines in the specified section of the INI file.

Parameters:
pFilename The full filename of the INI file to read
pSection The section from which to get the list of keys and values
[out] listLines Returns a list of INILine objects with all the keys and values found in the specified section of the INI file
uFlags Any combination of FileINI Flags, which modify the behaviour of this method.
Returns:
true if successful, false if error

NOTE: If the requested section is not found in the file, an empty list is returned, and no error is indicated

Definition at line 447 of file FileINI.cpp.

References CheckLineForSection(), DoInitLine(), FILEINI_TRIM, TestUnicode(), and TrimLen().

bool FileINI::GetKeys ( LPCTSTR  pFilename,
LPCTSTR  pSection,
TCHARSTR2STR mapKeys,
UINT  uFlags = 0 
) [static]

Retrieves all key names and values in all of the lines in the specified section of the INI file.

Parameters:
pFilename The full filename of the INI file to read
pSection The section header to look for
mapKeys Map of name/value pairs
uFlags Parsing flags (combination of FileINI Flags)
Returns:
true if all went well, false if something failed

Definition at line 588 of file FileINI.cpp.

References GetKeys().

bool FileINI::GetKeys ( LPCTSTR  pSection,
INILINELIST listLines,
UINT  uFlags = 0 
)

Retrieves all key names and values in all of the lines in the specified section of the INI file.

Parameters:
pSection The section header to look for
[out] listLines Returns a list of INILine objects with all the keys and values found in the specified section of the INI file
uFlags Any combination of FileINI Flags, which modify the behaviour of this method.
Returns:
true if successful, false if error

Definition at line 889 of file FileINI.cpp.

References CheckLineForSection(), DoInitLine(), FILEINI_TRIM, FindNextLine(), m_bUnicode, m_nOffset, m_pData, and TrimLen().

bool FileINI::GetKeys ( LPCTSTR  pSection,
TCHARSTR2STR mapKeys,
UINT  uFlags = 0 
)

Retrieves all key names and values in all of the lines in the specified section of the INI file.

Parameters:
pSection The section header to look for
mapKeys Map of name/value pairs
uFlags Parsing flags (combination of FileINI Flags)
Returns:
true if all went well, false if something failed

Definition at line 869 of file FileINI.cpp.

Referenced by CCPrintData::PageData::FromFile(), GetKeys(), and CCPrintData::ReadFromFile().

bool FileINI::GetLines ( LPCTSTR  pFilename,
LPCTSTR  pSection,
TCHARSTRLIST listLines,
UINT  uFlags = 0 
) [static]

Retrieves all lines in the specified section of the INI file.

Parameters:
pFilename The full path to the INI file
pSection The name of the section, from which to return lines, without the brackets []
[out] listLines Returns the list of lines. Each line will be added as a string in this list.
uFlags Any combination of FileINI Flags, which modify the behaviour of this method.
Returns:
true if successful, false if error

NOTE: If the requested section is not found in the file, an empty list is returned, and no error is indicated

Definition at line 363 of file FileINI.cpp.

References CheckLineForSection(), FILEINI_IGNORE_COMMENTS, FILEINI_TRIM, IsComment(), MakeTString(), TestUnicode(), Trim(), TrimLen(), and tstring.

bool FileINI::GetLines ( LPCTSTR  pSection,
TCHARSTRLIST listLines,
UINT  uFlags = 0 
)

Retrieves all lines in the specified section of the INI file.

Parameters:
pSection The name of the section, from which to return lines, without the brackets []
[out] listLines Returns the list of lines. Each line will be added as a string in this list.
uFlags Any combination of FileINI Flags, which modify the behaviour of this method.
Returns:
true if successful, false if error

NOTE: If the requested section is not found in the file, an empty list is returned, and no error is indicated

Definition at line 941 of file FileINI.cpp.

References CheckLineForSection(), FILEINI_IGNORE_COMMENTS, FILEINI_TRIM, FindNextLine(), IsComment(), m_bUnicode, m_nOffset, m_pData, MakeTString(), Trim(), TrimLen(), and tstring.

bool FileINI::GetVarValues ( LPCTSTR  pVarValue,
TCHARSTRLIST lValues 
) [static]

Parses a comma separated list of values, and returns their parsed list. Supports quotes.

Parameters:
pVarValue String of comma separated values
[out] lValues List of values
Returns:
true if all went well, false if failed

Supports values separated by commas. If a value should include a comma, it MUST be wrapped in a quote before and after, like so: a,b,"c,d",e ==> 4 values ['a', 'b', 'c,d', 'e'] a,b,"c,d"e,f --> Error (quote not closed correctly!) a,b,c"d,e"f ==> 4 values ['a', 'b', 'c"d', 'e"f']

Definition at line 612 of file FileINI.cpp.

References Trim(), and tstring.

bool FileINI::HasData (  )  const [inline]

Checks if there's any data in the buffer.

Returns:
true if there's a loaded buffer, false if there's none

Definition at line 134 of file FileINI.h.

References m_pData.

bool FileINI::LoadINIFile ( LPCTSTR  lpFilename  ) 

Loads a file.

Parameters:
lpFilename The file to load
Returns:
true if loaded successfully, false if failed

Definition at line 274 of file FileINI.cpp.

References m_bOwn, m_bUnicode, m_nOffset, m_pData, and TestUnicode().

Referenced by FileINI(), and CCPrintData::ReadFromFile().

bool FileINI::ReplaceVariables ( LPCTSTR  pValue,
const TCHARSTR2STRLIST lVariables,
TCHARSTRLIST lResults 
) [static]

Performs previously defined string replacements on a string.

Parameters:
pValue The string to start with
lVariables Map of variables to replace in the string; each variable can have multiple values
lResults List to add the result to
Returns:
true if all went well, false if something went wrong

Definition at line 738 of file FileINI.cpp.

bool FileINI::TestUnicode (  )  [protected]

Check to see if file INI file is in unicode.

Returns:
true if the data is Unicode, false otherwise

Definition at line 347 of file FileINI.cpp.

References m_pData.

Referenced by FileINI(), GetAllSections(), GetKeys(), GetLines(), and LoadINIFile().

bool FileINI::TestUnicode ( FILE *  pFile  )  [static, protected]

Check to see if the file is a unicode INI file; tested at the opened location (doesn't seek to the start!).

Parameters:
pFile Pointer to file to test
Returns:
true if the file is unicode

Definition at line 318 of file FileINI.cpp.


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

Generated on Mon Jun 18 12:40:44 2012 for CC PDF Converter by doxygen 1.6.1