more ai generated doc with human review
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
/*! \file piconfig.h
|
||||
* \ingroup IO
|
||||
* \~\brief
|
||||
* \~english Configuration files parser and writer
|
||||
* \~russian Разбор и запись конфигурационных файлов
|
||||
*/
|
||||
//! \addtogroup IO
|
||||
//! \{
|
||||
//! \file piconfig.h
|
||||
//! \brief Configuration files parser and writer
|
||||
//! \~english Parser and writer for configuration files with tree structure support
|
||||
//! \~russian Разбор и запись конфигурационных файлов с поддержкой древовидной структуры
|
||||
//! \details
|
||||
//! \~english PIConfig provides functionality to read, write and manipulate configuration files in a tree-like structure.
|
||||
//! \~russian PIConfig предоставляет функциональность для чтения, записи и управления конфигурационными файлами в древовидной структуре.
|
||||
//! \}
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Configuration parser and writer
|
||||
@@ -58,6 +62,8 @@
|
||||
Entry & getValue(const PIString & vname, const double def, bool * exists = 0) const {return getValue(vname, PIString::fromNumber(def), exists);}
|
||||
// clang-format on
|
||||
|
||||
//! \~english Main configuration parser and writer class
|
||||
//! \~russian Главный класс для разбора и записи конфигурационных файлов
|
||||
class PIP_EXPORT PIConfig {
|
||||
friend class Entry;
|
||||
friend class Branch;
|
||||
@@ -79,6 +85,8 @@ public:
|
||||
class Entry;
|
||||
|
||||
|
||||
//! \~english Branch class - container for Entry objects
|
||||
//! \~russian Класс Branch - контейнер для объектов Entry
|
||||
class PIP_EXPORT Branch: public PIVector<Entry *> {
|
||||
friend class PIConfig;
|
||||
friend class Entry;
|
||||
@@ -90,22 +98,44 @@ public:
|
||||
public:
|
||||
Branch() { ; }
|
||||
|
||||
//! \~english Get value from branch by name with default value
|
||||
//! \~russian Получить значение из ветки по имени со значением по умолчанию
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {
|
||||
return const_cast<Branch *>(this)->getValue(vname, def, exists);
|
||||
}
|
||||
PICONFIG_GET_VALUE
|
||||
|
||||
//! \~english Get all leaf entries from the entire tree
|
||||
//! \~russian Получить все листовые записи из всего дерева
|
||||
Branch allLeaves();
|
||||
|
||||
//! \~english Get all entries with name containing specified substring
|
||||
//! \~russian Получить все записи с именем, содержащим указанную подстроку
|
||||
Branch getValues(const PIString & name);
|
||||
|
||||
//! \~english Get all leaf entries (entries without children)
|
||||
//! \~russian Получить все листовые записи (записи без детей)
|
||||
Branch getLeaves();
|
||||
|
||||
//! \~english Get all branch entries (entries with children)
|
||||
//! \~russian Получить все ветвящиеся записи (записи с детьми)
|
||||
Branch getBranches();
|
||||
|
||||
//! \~english Filter branch by filter string
|
||||
//! \~russian Фильтровать ветку по строке фильтра
|
||||
Branch & filter(const PIString & f);
|
||||
|
||||
//! \~english Check if entry with specified name exists
|
||||
//! \~russian Проверить, существует ли запись с указанным именем
|
||||
bool isEntryExists(const PIString & name) const {
|
||||
for (const auto * i: *this)
|
||||
if (entryExists(i, name)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//! \~english Get index of entry in branch
|
||||
//! \~russian Получить индекс записи в ветке
|
||||
int indexOf(const Entry * e) {
|
||||
for (int i = 0; i < size_s(); ++i)
|
||||
if (at(i) == e) return i;
|
||||
@@ -138,6 +168,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//! \~english Entry class - represents a single configuration entry
|
||||
//! \~russian Класс Entry - представляет отдельную запись конфигурации
|
||||
class PIP_EXPORT Entry {
|
||||
friend class PIConfig;
|
||||
friend class Branch;
|
||||
@@ -446,18 +478,24 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//! Read configuration from file at path "path" in mode "mode"
|
||||
//! \~english Open configuration from file at path in specified mode
|
||||
//! \~russian Открыть конфигурацию из файла по указанному пути в указанном режиме
|
||||
bool open(const PIString & path, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
|
||||
//! Read configuration from string "string" in mode "mode"
|
||||
//! \~english Open configuration from string in specified mode
|
||||
//! \~russian Открыть конфигурацию из строки в указанном режиме
|
||||
bool open(PIString * string, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
|
||||
//! Read configuration from custom device "device" in mode "mode"
|
||||
//! \~english Open configuration from custom I/O device in specified mode
|
||||
//! \~russian Открыть конфигурацию из пользовательского устройства ввода-вывода в указанном режиме
|
||||
bool open(PIIODevice * device, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
|
||||
//! \~english Check if configuration is opened
|
||||
//! \~russian Проверить, открыта ли конфигурация
|
||||
bool isOpened() const;
|
||||
|
||||
//! Returns top-level entry with name "vname", if doesn`t exists return entry with value "def" and set *exist to false
|
||||
//! \~english Get top-level entry by name with default value
|
||||
//! \~russian Получить запись верхнего уровня по имени со значением по умолчанию
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0);
|
||||
Entry & getValue(const PIString & vname, const PIString & def = PIString(), bool * exists = 0) const {
|
||||
return const_cast<PIConfig *>(this)->getValue(vname, def, exists);
|
||||
@@ -504,13 +542,16 @@ public:
|
||||
//! \fn Entry & getValue(const PIString & vname, const double def, bool * exists = 0)
|
||||
//! \brief Returns top-level entry with name "vname" and default value "def"
|
||||
|
||||
|
||||
//! Returns top-level entries with names with substrings "vname"
|
||||
//! \~english Get all top-level entries with name containing substring
|
||||
//! \~russian Получить все записи верхнего уровня с именем, содержащим подстроку
|
||||
Branch getValues(const PIString & vname);
|
||||
|
||||
|
||||
//! Set top-level entry with name "name" value to "value", type to "type" and if "write" immediate write to file. Add new entry if there
|
||||
//! is no suitable exists
|
||||
//! \~english Set value for top-level entry with name
|
||||
//! \~russian Установить значение для записи верхнего уровня с именем
|
||||
//! \details
|
||||
//! \~english Set top-level entry with name "name" value to "value", type to "type" and if "write" immediate write to file.
|
||||
//! Add new entry if there is no suitable exists
|
||||
void setValue(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
||||
|
||||
//! Set top-level entry with name "name" value to "value", type to "l" and if "write" immediate write to file. Add new entry if there is
|
||||
@@ -561,16 +602,20 @@ public:
|
||||
//! no suitable exists
|
||||
void setValue(const PIString & name, const double value, bool write = true) { setValue(name, PIString::fromNumber(value), "f", write); }
|
||||
|
||||
//! Returns root entry
|
||||
//! \~english Get root entry of configuration tree
|
||||
//! \~russian Получить корневую запись дерева конфигурации
|
||||
Entry & rootEntry() { return root; }
|
||||
|
||||
//! Returns top-level entries count
|
||||
//! \~english Get count of top-level entries
|
||||
//! \~russian Получить количество записей верхнего уровня
|
||||
int entriesCount() const { return childCount(&root); }
|
||||
|
||||
//! Returns if top-level entry with name "name" exists
|
||||
//! \~english Check if top-level entry with name exists
|
||||
//! \~russian Проверить, существует ли запись верхнего уровня с указанным именем
|
||||
bool isEntryExists(const PIString & name) const { return entryExists(&root, name); }
|
||||
|
||||
//! Returns all top-level entries
|
||||
//! \~english Get all top-level entries
|
||||
//! \~russian Получить все записи верхнего уровня
|
||||
Branch allTree() {
|
||||
Branch b;
|
||||
for (auto * i: root._children)
|
||||
@@ -579,7 +624,8 @@ public:
|
||||
return b;
|
||||
}
|
||||
|
||||
//! Returns all entries without children
|
||||
//! \~english Get all entries without children (leaves)
|
||||
//! \~russian Получить все записи без детей (листья)
|
||||
Branch allLeaves() {
|
||||
Branch b;
|
||||
allLeaves(b, &root);
|
||||
@@ -588,35 +634,71 @@ public:
|
||||
return b;
|
||||
}
|
||||
|
||||
//! \~english Get index of entry by name
|
||||
//! \~russian Получить индекс записи по имени
|
||||
int entryIndex(const PIString & name);
|
||||
|
||||
//! \~english Get entry name by index
|
||||
//! \~russian Получить имя записи по индексу
|
||||
PIString getName(uint number) { return entryByIndex(number)._name; }
|
||||
|
||||
//! \~english Get entry value by index
|
||||
//! \~russian Получить значение записи по индексу
|
||||
PIString getValueByIndex(uint number) { return entryByIndex(number)._value; }
|
||||
|
||||
//! \~english Get entry type by index
|
||||
//! \~russian Получить тип записи по индексу
|
||||
PIChar getType(uint number) { return entryByIndex(number)._type[0]; }
|
||||
|
||||
//! \~english Get entry comment by index
|
||||
//! \~russian Получить комментарий записи по индексу
|
||||
PIString getComment(uint number) { return entryByIndex(number)._comment; }
|
||||
|
||||
//! \~english Add new entry with name, value and type
|
||||
//! \~russian Добавить новую запись с именем, значением и типом
|
||||
void addEntry(const PIString & name, const PIString & value, const PIString & type = "s", bool write = true);
|
||||
|
||||
//! \~english Set name of entry by index
|
||||
//! \~russian Установить имя записи по индексу
|
||||
void setName(uint number, const PIString & name, bool write = true);
|
||||
|
||||
//! \~english Set value of entry by index
|
||||
//! \~russian Установить значение записи по индексу
|
||||
void setValue(uint number, const PIString & value, bool write = true);
|
||||
|
||||
//! \~english Set type of entry by index
|
||||
//! \~russian Установить тип записи по индексу
|
||||
void setType(uint number, const PIString & type, bool write = true);
|
||||
|
||||
//! \~english Set comment of entry by index
|
||||
//! \~russian Установить комментарий записи по индексу
|
||||
void setComment(uint number, const PIString & comment, bool write = true);
|
||||
|
||||
//! \~english Remove entry by name
|
||||
//! \~russian Удалить запись по имени
|
||||
void removeEntry(const PIString & name, bool write = true);
|
||||
|
||||
//! \~english Remove entry by index
|
||||
//! \~russian Удалить запись по индексу
|
||||
void removeEntry(uint number, bool write = true);
|
||||
|
||||
//! Remove all tree and device content
|
||||
void clear();
|
||||
|
||||
//! Parse device and build internal tree
|
||||
//! \~english Parse device and build internal tree
|
||||
//! \~russian Прочитать устройство и построить внутреннее дерево
|
||||
void readAll();
|
||||
|
||||
//! Write all internal tree to device
|
||||
//! \~english Write all internal tree to device
|
||||
//! \~russian Записать всё внутреннее дерево в устройство
|
||||
void writeAll();
|
||||
|
||||
//! Returns current tree delimiter, default "."
|
||||
//! \~english Get current tree delimiter
|
||||
//! \~russian Получить текущий разделитель дерева
|
||||
const PIString & delimiter() const { return delim; }
|
||||
|
||||
//! Set current tree delimiter
|
||||
//! \~english Set tree delimiter
|
||||
//! \~russian Установить разделитель дерева
|
||||
void setDelimiter(const PIString & d) {
|
||||
delim = d;
|
||||
setEntryDelim(&root, d);
|
||||
@@ -708,14 +790,18 @@ inline PICout operator<<(PICout s, const PIConfig::Entry & v) {
|
||||
}
|
||||
|
||||
|
||||
/** \relatesalso PIConfig \relatesalso PIIODevice
|
||||
* \brief Service function. useful for configuring devices
|
||||
* \details Function takes entry name "name", default value "def" and two
|
||||
* \a PIConfig::Entry sections: "em" and their parent "ep". If there is no
|
||||
* parent ep = 0. If "ep" is not null and entry "name" exists in "ep" function
|
||||
* returns this value. Else returns value of entry "name" in section "em" or
|
||||
* "def" if entry doesn`t exists. \n This function useful to read settings
|
||||
* from configuration file in implementation \a PIIODevice::configureDevice() function */
|
||||
//! \~english Service function for reading device settings from configuration
|
||||
//! \~russian Сервисная функция для чтения настроек устройства из конфигурации
|
||||
//! \note
|
||||
//! \~english Useful for implementing PIIODevice::configureDevice()
|
||||
//! \~russian Полезно для реализации PIIODevice::configureDevice()
|
||||
//! \~\details Function takes entry name "name", default value "def" and two
|
||||
//! \a PIConfig::Entry sections: "em" and their parent "ep". If there is no
|
||||
//! parent ep = 0. If "ep" is not null and entry "name" exists in "ep" function
|
||||
//! returns this value. Else returns value of entry "name" in section "em" or
|
||||
//! "def" if entry doesn`t exists. \n This function useful to read settings
|
||||
//! from configuration file in implementation \a PIIODevice::configureDevice() function
|
||||
//! \relatesalso PIConfig \relatesalso PIIODevice
|
||||
template<typename T>
|
||||
T readDeviceSetting(const PIString & name, const T & def, const PIConfig::Entry * em, const PIConfig::Entry * ep) {
|
||||
PIVariant v = PIVariant::fromValue<T>(def);
|
||||
|
||||
Reference in New Issue
Block a user