ComSDK
|
Парсер файлов aini формата Подробнее...
#include <iniparser.h>
Открытые члены | |
INIParser (const std::string &p_projectOrFileName, const std::string &p_hostPath) | |
INIParser (const std::string &p_projectOrFileName) | |
bool | isLoaded () |
std::string | getCurrentINIFilename () const |
std::string | getDefaultINIFilename () const |
void | setINIFilename (const std::string &p_INIFilename) |
void | setDefaultINIFilename () |
ErrorCode | save () |
com::ini::INIParamType | getParamType (const std::string &p_section, const std::string &p_paramName) const |
ErrorCode | getScriptFromFile (const std::string &p_section, std::list< std::string > &o_script, bool p_removeSubcomments=true) const |
void | getSections (std::vector< std::string > &o_sections) const |
ErrorCode | getParamNamesList (const std::string &p_section, std::list< std::string > &o_paramNames) |
bool | sectionExists (const std::string &p_section) const |
ErrorCode | getParamDescription (const std::string &p_section, const std::string &p_paramName, std::string &o_paramDescr) |
ErrorCode | getSectionDescription (const std::string &p_section, std::string &o_sectionDescr) |
ErrorCode | setOptionValueInFile (const std::string &p_section, const std::string &p_paramName, const std::string &p_newValue) |
int | getIntOptionValue (const std::string &p_section, const std::string &p_paramName, ErrorCode *o_error=NULL) const |
std::string | getStrOptionValueRecursive (const std::string &p_section, const std::string &p_paramName, enu_ReadMode rm, ErrorCode *o_error) const |
std::string | getStrOptionValue (const std::string &p_section, const std::string &p_paramName, ErrorCode *o_error=NULL) const |
double | getFloatOptionValue (const std::string &p_section, const std::string &p_paramName, ErrorCode *o_error=NULL) const |
ErrorCode | getDoubleArrayOptionValue (const std::string &p_section, const std::string &p_paramName, std::vector< double > &o_array) const |
ErrorCode | getStrArrayOptionValue (const std::string &p_section, const std::string &p_paramName, std::vector< std::string > &o_array) const |
ErrorCode | getTwoDimensionalArray (const std::string &p_section, const std::string &p_paramName, std::vector< std::vector< double > > &o_list, double &o_currentValue, std::vector< std::string > &o_units) const |
ErrorCode | getTreeNodes (const std::string &p_section, const std::string &p_paramName, std::list< std::string > &o_nodesSids, std::map< std::string, std::map< std::string, std::string > > &o_nodesData, std::set< std::string > &o_nodesDataFields) const |
ErrorCode | getFileParamData (const std::string &p_section, const std::string &p_paramName, std::string &o_filename) const |
ErrorCode | getRangeValue (const std::string &p_section, const std::string &p_paramName, com::ini::INIRange &o_range) const |
bool | getCheckValue (const std::string &p_section, const std::string &p_paramName, INIParser::ErrorCode *o_error=NULL) const |
ErrorCode | getSetValue (const std::string &p_section, const std::string &p_paramName, std::string &o_currentValue, std::list< std::string > &o_valueList) const |
ErrorCode | getCurrentSetValue (const std::string &p_section, const std::string &p_paramName, std::string &o_currentValue) const |
ErrorCode | getUnitValue (const std::string &p_section, const std::string &p_paramName, std::string &o_value, std::string &o_unit) const |
ErrorCode | getDBTableValue (const std::string &p_section, const std::string &p_paramName, std::string &o_defaultValue, std::string &o_sourceTable) const |
INIParser::ErrorCode | splitParamLine (const std::string &p_section, int p_paramIndex, std::string &o_paramName, std::string &o_paramValue, std::string &o_paramDescription) const |
void | loadINIDataToAnyMap (Anymap &o_anyMapData, const std::vector< std::string > &extNames, enu_LoadMode loadMode=lmDefault) |
std::vector < com::ini::ParamAddress > | getParNamesByType (com::ini::INIParamType p_type) const |
Парсер файлов aini формата
Класс реализует парсер файлов aini формата и позволяет получить доступ к файлу как через отдельные методы, так и через выгрузку в Anymap
Коды ошибок парсера
com::ini::INIParser::INIParser | ( | const std::string & | p_projectOrFileName, |
const std::string & | p_hostPath | ||
) |
Конструктор принимает на вход название файла или название проекта, к которому автоматически будет добавлено расширение '.ini'.
[in] | p_projectOrFileName | Имя файла или проекта |
bool com::ini::INIParser::getCheckValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
INIParser::ErrorCode * | o_error = NULL |
||
) | const |
Возвращает значение параметра-флага. Пример: [0]{0|1}
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_error | Указатель на возвращаемый код ошибки (по умолчанию NULL) |
string com::ini::INIParser::getCurrentINIFilename | ( | ) | const |
Возвращает имя ini-файла, в данных момент подгружается информация.
com::ini::INIParser::ErrorCode com::ini::INIParser::getCurrentSetValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::string & | o_currentValue | ||
) | const |
Возвращает установленное значение параметра-множества.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_currentValue | Установленное значение |
com::ini::INIParser::ErrorCode com::ini::INIParser::getDBTableValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::string & | o_defaultValue, | ||
std::string & | o_sourceTable | ||
) | const |
Возвращает значения параметра "значение из таблицы базы данных". Пример: [somepk]$sys.table
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_defaultValue | Значение первичного ключа |
[out] | o_sourceTable | Название таблицы (вместе со схемой) |
com::ini::INIParser::ErrorCode com::ini::INIParser::getDoubleArrayOptionValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::vector< double > & | o_array | ||
) | const |
Возвращает значение параметра как массив вещественных чисел. Пример: (1.2; 1.3; 1.4)
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_array | Значение параметра в виде массива вещественных чисел |
com::ini::INIParser::ErrorCode com::ini::INIParser::getFileParamData | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::string & | o_filename | ||
) | const |
Возвращает значение параметра как имя файла.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_filename | Имя файла |
double com::ini::INIParser::getFloatOptionValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
ErrorCode * | o_error = NULL |
||
) | const |
Возвращает вещественное значение параметра.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_error | Указатель на возвращаемый код ошибки (по умолчанию NULL) |
int com::ini::INIParser::getIntOptionValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
ErrorCode * | o_error = NULL |
||
) | const |
Возвращает целое значение параметра.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_error | Указатель на возвращаемый код ошибки (по умолчанию NULL) |
com::ini::INIParser::ErrorCode com::ini::INIParser::getParamDescription | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::string & | o_paramDescr | ||
) |
Возвращает комментарий к параметру.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_paramDescr | Возвращаемый комментарий |
com::ini::INIParser::ErrorCode com::ini::INIParser::getParamNamesList | ( | const std::string & | p_section, |
std::list< std::string > & | o_paramNames | ||
) |
Возвращает список параметров, находящихся в данной секции.
[in] | p_section | Секция |
[out] | o_paramNames | Возвращаемый список импен параметров |
com::ini::INIParamType com::ini::INIParser::getParamType | ( | const std::string & | p_section, |
const std::string & | p_paramName | ||
) | const |
Возвращает тип параметра.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
vector< com::ini::ParamAddress > com::ini::INIParser::getParNamesByType | ( | com::ini::INIParamType | p_type | ) | const |
Возвращает вектор параметров, имеющих заданный тип.
[in] | p_type | Тип параметров |
com::ini::INIParser::ErrorCode com::ini::INIParser::getRangeValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
com::ini::INIRange & | o_range | ||
) | const |
Возвращает значение параметра-диапазона. Пример: [5; 0:10; 1]
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_range | Структура диапазона |
com::ini::INIParser::ErrorCode com::ini::INIParser::getScriptFromFile | ( | const std::string & | p_section, |
std::list< std::string > & | o_script, | ||
bool | p_removeSubcomments = true |
||
) | const |
Возвращает скрипт секции (т.е. все строки секции).
[in] | p_section | Секция |
[out] | o_script | Скрипт в виде списка строк |
[in] | p_removeSubcomments | Флаг, удалять ли комментарии из строк |
com::ini::INIParser::ErrorCode com::ini::INIParser::getSectionDescription | ( | const std::string & | p_section, |
std::string & | o_sectionDescr | ||
) |
Возвращает комментарий к секции.
[in] | p_section | Секция |
[out] | o_sectionDescr | Возвращаемый комментарий |
void com::ini::INIParser::getSections | ( | std::vector< std::string > & | o_sections | ) | const |
Возвращает список секций.
[out] | o_sections | Список секций |
com::ini::INIParser::ErrorCode com::ini::INIParser::getSetValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::string & | o_currentValue, | ||
std::list< std::string > & | o_valueList | ||
) | const |
Возвращает значение параметра-множества. Пример: [a]{a|b|c|d|e|f}
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_currentValue | Установленное значение |
[out] | o_valueList | Множество всех возможных значений |
com::ini::INIParser::ErrorCode com::ini::INIParser::getStrArrayOptionValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::vector< std::string > & | o_array | ||
) | const |
Возвращает значение параметра как массив строк. Пример: (abc; def; ghi)
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_array | Значение параметра в виде массива строк |
string com::ini::INIParser::getStrOptionValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
ErrorCode * | o_error = NULL |
||
) | const |
Возвращает строковое значение параметра.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_error | Указатель на возвращаемый код ошибки (по умолчанию NULL) |
string com::ini::INIParser::getStrOptionValueRecursive | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
enu_ReadMode | rm, | ||
ErrorCode * | o_error | ||
) | const |
Возвращает строковое значение параметра.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[in] | rm | Вид чтения |
[out] | o_error | Указатель на возвращаемый код ошибки (по умолчанию NULL) |
com::ini::INIParser::ErrorCode com::ini::INIParser::getTreeNodes | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::list< std::string > & | o_nodesSids, | ||
std::map< std::string, std::map< std::string, std::string > > & | o_nodesData, | ||
std::set< std::string > & | o_nodesDataFields | ||
) | const |
Возвращает информацию по параметру типа "Дерево".
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_nodesSids | Список названий субпараметров |
[out] | o_nodesDataFields | Множество идентификаторов субпараметров |
[out] | o_nodesData | Данных субпараметров в виде мапа, где ключ – субпараметр, а значение – мапа данных субпараметра (идентификатор субпараметра -> значение) |
Пример данных для чтения [Section] tree={node1,node2,node3} // Comment node1$data=45 // Comment1 node2$type=[typ1]{typ1|typ2} // Comment node2$data=(12,32,42) // Comment
читаем список узлов параметра ptTree
данные по узлам дерева могут быть в других параметрах этой же секции поэтому читаем всю секцию вместе с субкомментариями в отдельных строках
для каждой найденной строки нужно: осуществить сплиттинг: название/значение/комментарий
определяем грамматику boost::spirit
Формат исходных данных некорректен, если не удалось считать значение параметра!
попытаться разобрать имя параметра
если текущий проверяемый параметр не является субпараметром, то пропускаем этот параметр и переходим к анализу следующего параметра
текущий проверяемый параметр содержится в списке считанных дочерних элементов дерева поэтому необходимо добавить новых узел в данные map<string, map<string,string> >, и в множество полей данных set<string>
com::ini::INIParser::ErrorCode com::ini::INIParser::getTwoDimensionalArray | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::vector< std::vector< double > > & | o_list, | ||
double & | o_currentValue, | ||
std::vector< std::string > & | o_units | ||
) | const |
Возвращает значение параметра как двумерный вектор вещественных чисел. Поддерживается опционально значение по умолчанию (текущее значение) и единицы измерения. Примеры: ((1.2; 1.3; 1.4) ; (1.2; 1.3; 1.4)) 1.2 ; (1.2; 1.3; 1.4)) [[T, N, MPa]]
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_list | Значение параметра в виде двумерного списка вещественных чисел |
[out] | o_currentValue | Значение по умолчанию (текущее значение) |
[out] | o_units | Вектор единиц измерения |
com::ini::INIParser::ErrorCode com::ini::INIParser::getUnitValue | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
std::string & | o_value, | ||
std::string & | o_unit | ||
) | const |
Возвращает значение параметра с размерностью. Пример: 10 [[gpa]]
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[out] | o_value | Значение |
[out] | o_unit | Размерность |
bool com::ini::INIParser::isLoaded | ( | ) |
Проверяет, прошла загрузка файла успешно.
void com::ini::INIParser::loadINIDataToAnyMap | ( | Anymap & | o_anyMapData, |
const std::vector< std::string > & | extNames, | ||
enu_LoadMode | loadMode = lmDefault |
||
) |
Выгружает внутреннее представление ini-файла в Anymap. Он имеет следующую структуру: o_anyMapData[-SECTION_NAME-][SECTION_COMMENT] [SECTION_PARAMS] [-PARAM_NAME-][PARAM_DESCR] [PARAM_TYPE] [PARAM_VALUE]
[out] | o_anyMapData | Anymap |
[in] | loadMode | тип загрузки |
[in] | extNames | список разрешений файлов, допустимых к рекурсивной загрузке |
com::ini::INIParser::ErrorCode com::ini::INIParser::save | ( | ) |
Сохраняет изменения в представлении файла в сам файл.
bool com::ini::INIParser::sectionExists | ( | const std::string & | p_section | ) | const |
Проверяет, существует ли указанная секция в файле.
[in] | p_section | Секция |
void com::ini::INIParser::setINIFilename | ( | const std::string & | p_INIFilename | ) |
Задает новый файл для разбора.
[in] | p_INIFilename | Имя файла |
com::ini::INIParser::ErrorCode com::ini::INIParser::setOptionValueInFile | ( | const std::string & | p_section, |
const std::string & | p_paramName, | ||
const std::string & | p_newValue | ||
) |
Изменяет значение параметра.
[in] | p_section | Секция |
[in] | p_paramName | Параметр |
[in] | p_newValue | Новое значение |
com::ini::INIParser::ErrorCode com::ini::INIParser::splitParamLine | ( | const std::string & | p_section, |
int | p_paramIndex, | ||
std::string & | o_paramName, | ||
std::string & | o_paramValue, | ||
std::string & | o_paramDescription | ||
) | const |
Возвращает данные параметра по его номеру в секции
[in] | p_section | Секция |
[in] | p_paramIndex | Номер строки (начиная с 0) |
[out] | o_paramName | Параметр |
[out] | o_paramValue | Значение |
[out] | o_paramDescription | Комментарий |
Разбиение строки с параметром на: наименование, значение, описание