Класс для чтения INI файлов. Подробнее...
#include <loaders/ini_file.h>
Открытые члены | |
| INIFile (void) | |
| INIFile (const char *thePath) | |
| INIFile (const std::string &thePath) | |
| void | LoadINIFile (const char *thePath) |
| void | LoadINIFile (const std::string &thePath) |
| void | SetPath (const char *thePath) |
| void | SetPath (const std::string &thePath) |
| const char * | GetPath (void) const |
| const char * | GetString (const char *Section, const char *Key, char *Value, const char *Default=NULL) const |
| void | SetString (const char *Section, const char *Key, const char *Value) |
| void | SaveINIFile (const char *thePath=NULL) |
| void | SaveINIFile (std::string &thePath) |
| virtual | ~INIFile () |
Закрытые данные | |
| std::string | Path |
| std::vector< std::string > | FileData |
| bool | NeedSaveFile |
Класс для чтения INI файлов.
См. определение в файле ini_file.h строка 50
| nitro::INIFile::INIFile | ( | void | ) |
Конструктор по-умолчанию.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 11
Перекрестные ссылки nitro::exception::code(), NeedSaveFile, Path и nitro::exception::what().
{
try
{
Path = "";
NeedSaveFile = false;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::INIFile( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::INIFile( void )::An error occured" ) , 1 ) );
}
}

| nitro::INIFile::INIFile | ( | const char * | thePath | ) |
Конструктор.
| thePath | - Путь к загружаемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 28
Перекрестные ссылки nitro::exception::code(), LoadINIFile(), NeedSaveFile и nitro::exception::what().
{
try
{
NeedSaveFile = false;
LoadINIFile( thePath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::INIFile( const char * thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::INIFile( const char * thePath )::An error occured" ) , 1 ) );
}
}

| nitro::INIFile::INIFile | ( | const std::string & | thePath | ) |
Конструктор.
| thePath | - Путь к загружаемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 45
Перекрестные ссылки nitro::exception::code(), LoadINIFile(), NeedSaveFile и nitro::exception::what().
{
try
{
NeedSaveFile = false;
LoadINIFile( thePath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::INIFile( const std::string & thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::INIFile( const std::string & thePath )::An error occured" ) , 1 ) );
}
}

| nitro::INIFile::~INIFile | ( | ) | [virtual] |
Деструктор.
См. определение в файле ini_file.cpp строка 295
{
try
{
}
catch( nitro::exception e )
{
}
catch( ... )
{
}
}
| const char * nitro::INIFile::GetPath | ( | void | ) | const |
Получение пути к файлу.
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 136
Перекрестные ссылки Path.
{
return( Path.c_str() );
}
| const char * nitro::INIFile::GetString | ( | const char * | Section, | |
| const char * | Key, | |||
| char * | Value, | |||
| const char * | Default = NULL | |||
| ) | const |
Получение данных из файла.
| Section | - Секция. | |
| Key | - Ключ. | |
| Value | - Данные из файла. | |
| Default | - Значение по умолчанию если ключь не найден. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 141
Перекрестные ссылки nitro::exception::code(), nitro::Parsers::ExplodeString(), FileData и nitro::exception::what().
{
try
{
bool SectionStarted( false );
for( std::size_t i( 0 ) ; i < FileData.size() ; i++ )
{
if( FileData[ i ] == std::string( "[" ) + Section + "]" )
{
SectionStarted = true;
continue;
}
if( SectionStarted && FileData[ i ][ 0 ] == '[' )
{
break;
}
if( SectionStarted )
{
std::vector< std::string > Segments;
nitro::Parsers::ExplodeString( FileData[ i ] , Segments , '=' );
if( SectionStarted && Segments[ 0 ] == Key )
{
strcpy( Value , Segments[ 1 ].c_str() );
return( Value );
}
}
}
strcpy( Value , Default );
return( Value );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::GetString( const char * Section , const char * Key , const char * Value , const char * Default /* = NULL */ )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::GetString( const char * Section , const char * Key , const char * Value , const char * Default /* = NULL */ )::An error occured" ) , 1 ) );
}
return( NULL );
}

| void nitro::INIFile::LoadINIFile | ( | const char * | thePath | ) |
Загрузка файлов.
| thePath | - Путь к загружаемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 62
Перекрестные ссылки nitro::BinaryData::AppendData(), nitro::exception::code(), nitro::Parsers::ExplodeString(), FileData, nitro::BinaryData::GetBuffer(), nitro::File::LoadBinDataFromFile(), Path, nitro::BinaryData::ReplaceBuffer() и nitro::exception::what().
Используется в INIFile() и LoadINIFile().
{
try
{
FileData.erase( FileData.begin() , FileData.end() );
Path = thePath;
nitro::BinaryData Data;
nitro::File::LoadBinDataFromFile( Data , thePath );
Data.AppendData( "\0" , 1 );
nitro::BinaryData::ReplaceBuffer( Data , "\r\n" , 2 , "\n" , 1 );
nitro::Parsers::ExplodeString( Data.GetBuffer() , FileData , '\n' );
if( FileData.size() == 1 )
{
FileData.clear();
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::LoadINIFile( const char * thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::LoadINIFile( const char * thePath )::An error occured" ) , 1 ) );
}
}

| void nitro::INIFile::LoadINIFile | ( | const std::string & | thePath | ) |
Загрузка файлов.
| thePath | - Путь к загружаемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 88
Перекрестные ссылки nitro::exception::code(), LoadINIFile() и nitro::exception::what().
{
try
{
LoadINIFile( thePath.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::LoadINIFile( const char * thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::LoadINIFile( const char * thePath )::An error occured" ) , 1 ) );
}
}

| void nitro::INIFile::SaveINIFile | ( | const char * | thePath = NULL |
) |
Сохранение файла.
| thePath | - Путь к сохраняемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 244
Перекрестные ссылки nitro::BinaryData::AppendData(), nitro::exception::code(), FileData, Path, nitro::File::SaveBinDataToFile() и nitro::exception::what().
Используется в SaveINIFile().
{
try
{
nitro::BinaryData Data;
for( std::size_t i( 0 ) ; i < FileData.size() ; i++ )
{
Data.AppendData( FileData[ i ] );
if( i + 1 != FileData.size() )
{
Data.AppendData( "\r\n" );
}
}
if( NULL == thePath || std::string( "" ) == thePath )
{
nitro::File::SaveBinDataToFile( Data , Path );
}
else
{
nitro::File::SaveBinDataToFile( Data , thePath );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::SaveINIFile( std::string & thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::SaveINIFile( std::string & thePath )::An error occured" ) , 1 ) );
}
}

| void nitro::INIFile::SaveINIFile | ( | std::string & | thePath | ) |
Сохранение файла.
| thePath | - Путь к сохраняемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 279
Перекрестные ссылки nitro::exception::code(), SaveINIFile() и nitro::exception::what().
{
try
{
SaveINIFile( thePath.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::SaveINIFile( std::string & thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::SaveINIFile( std::string & thePath )::An error occured" ) , 1 ) );
}
}

| void nitro::INIFile::SetPath | ( | const char * | thePath | ) |
Установка нового пути к файлу.
| thePath | - Путь к загружаемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 104
Перекрестные ссылки nitro::exception::code(), Path и nitro::exception::what().
{
try
{
Path = thePath;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::SetPath( const char * thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::SetPath( const char * thePath )::An error occured" ) , 1 ) );
}
}

| void nitro::INIFile::SetPath | ( | const std::string & | thePath | ) |
Установка нового пути к файлу.
| thePath | - Путь к загружаемому файлу. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 120
Перекрестные ссылки nitro::exception::code(), Path и nitro::exception::what().
{
try
{
Path = thePath;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::SetPath( const std::string & thePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::SetPath( const std::string & thePath )::An error occured" ) , 1 ) );
}
}

| void nitro::INIFile::SetString | ( | const char * | Section, | |
| const char * | Key, | |||
| const char * | Value | |||
| ) |
Сохранение значения.
| Section | - Секция. | |
| Key | - Ключ. | |
| Value | - Значение. |
| nitro::exception | Кидает исключение этого типа с описанием ошибки. |
См. определение в файле ini_file.cpp строка 188
Перекрестные ссылки nitro::exception::code(), nitro::Parsers::ExplodeString(), FileData, NeedSaveFile и nitro::exception::what().
{
try
{
bool SectionStarted( false );
std::vector< std::string >::iterator iter( FileData.begin() );
for( ; iter != FileData.end() ; ++iter )
{
if( *iter == std::string( "[" ) + Section + "]" )
{
SectionStarted = true;
continue;
}
if( SectionStarted && ( *iter )[ 0 ] == '[' )
{
break;
}
if( SectionStarted )
{
std::vector< std::string > Segments;
nitro::Parsers::ExplodeString( *iter , Segments , '=' );
if( SectionStarted && Segments[ 0 ] == Key )
{
*iter = std::string( Key ) + "=" + Value;
NeedSaveFile = true;
return;
}
}
}
if( SectionStarted )
{
FileData.insert( iter , std::string( Key ) + "=" + Value );
}
else
{
FileData.push_back( std::string( "[" ) + Section + "]" );
FileData.push_back( std::string( Key ) + "=" + Value );
}
NeedSaveFile = true;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "INIFile::SetString( const char * Section , const char * Key, const char * Value )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "INIFile::SetString( const char * Section , const char * Key, const char * Value )::An error occured" ) , 1 ) );
}
}

std::vector< std::string > nitro::INIFile::FileData [private] |
Данные INI файла.
См. определение в файле ini_file.h строка 350
Используется в GetString(), LoadINIFile(), SaveINIFile() и SetString().
bool nitro::INIFile::NeedSaveFile [private] |
Нужно ли сохранять файл.
См. определение в файле ini_file.h строка 362
Используется в INIFile() и SetString().
std::string nitro::INIFile::Path [private] |
Путь к файлу.
См. определение в файле ini_file.h строка 338
Используется в GetPath(), INIFile(), LoadINIFile(), SaveINIFile() и SetPath().
1.6.1