code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -3,24 +3,24 @@
* \brief
* \~english JSON class
* \~russian Класс JSON
*/
*/
/*
PIP - Platform Independent Primitives
JSON class
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
JSON class
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIJSON_H
@@ -34,21 +34,21 @@
//! \~english JSON class.
//! \~russian Класс JSON.
class PIP_EXPORT PIJSON {
friend PICout operator <<(PICout s, const PIJSON & v);
public:
friend PICout operator<<(PICout s, const PIJSON & v);
public:
//! \~english
//! Type of JSON tree element
//! \~russian
//! Тип элемента дерева JSON
enum Type {
Invalid /*! \~english Invalid type \~russian Недействительный тип */,
Null /*! \~english Without value, null \~russian Без значения, null */,
Null /*! \~english Without value, null \~russian Без значения, null */,
Boolean /*! \~english Boolean, /b true or /b false \~russian Логическое, /b true или /b false */,
Number /*! \~english Integer or floating-point number \~russian Целое либо число с плавающей точкой */,
String /*! \~english Text \~russian Текст */,
Object /*! \~english Object, {} \~russian Объект, {} */,
Array /*! \~english Array, [] \~russian Массив, [] */
Number /*! \~english Integer or floating-point number \~russian Целое либо число с плавающей точкой */,
String /*! \~english Text \~russian Текст */,
Object /*! \~english Object, {} \~russian Объект, {} */,
Array /*! \~english Array, [] \~russian Массив, [] */
};
//! \~english
@@ -57,7 +57,7 @@ public:
//! Вариант генерации JSON
enum PrintType {
Compact /*! \~english Without spaces, minimum size \~russian Без пробелов, минимальный размер */,
Tree /*! \~english With spaces and new-lines, human-readable \~russian С пробелами и новыми строками, читаемый человеком */
Tree /*! \~english With spaces and new-lines, human-readable \~russian С пробелами и новыми строками, читаемый человеком */
};
//! \~english Contructs invalid %PIJSON.
@@ -67,7 +67,7 @@ public:
//! \~english Returns name of element, or empty string if it doesn`t have name.
//! \~russian Возвращает имя элемента, либо пустую строку, если имени нет.
const PIString & name() const {return c_name;}
const PIString & name() const { return c_name; }
//! \~english Returns elements array of this element, or empty array if element is not \a PIJSON::Array.
//! \~russian Возвращает массив элементов этого элемента, либо пустой массив, если тип элемента не \a PIJSON::Array.
@@ -79,40 +79,40 @@ public:
//! \~english Returns element value.
//! \~russian Возвращает значение элемента.
const PIVariant & value() const {return c_value;}
const PIVariant & value() const { return c_value; }
//! \~english Returns element value as bool.
//! \~russian Возвращает значение элемента как логическое.
bool toBool() const {return c_value.toBool();}
bool toBool() const { return c_value.toBool(); }
//! \~english Returns element value as integer number.
//! \~russian Возвращает значение элемента как целое число.
int toInt() const {return c_value.toInt();}
int toInt() const { return c_value.toInt(); }
//! \~english Returns element value as floating-point number.
//! \~russian Возвращает значение элемента как число с плавающей точкой.
double toDouble() const {return c_value.toDouble();}
double toDouble() const { return c_value.toDouble(); }
//! \~english Returns element value as string, valid for all types.
//! \~russian Возвращает значение элемента как строка, действительно для всех типов.
PIString toString() const {return c_value.toString();}
PIString toString() const { return c_value.toString(); }
//! \~english Returns element type.
//! \~russian Возвращает тип элемента.
Type type() const {return c_type;}
Type type() const { return c_type; }
//! \~english Returns if element is valid.
//! \~russian Возвращает действителен ли элемент.
bool isValid() const {return c_type != Invalid;}
bool isValid() const { return c_type != Invalid; }
//! \~english Returns if element is \a PIJSON::Object.
//! \~russian Возвращает является ли элемент \a PIJSON::Object.
bool isObject() const {return c_type == Object;}
bool isObject() const { return c_type == Object; }
//! \~english Returns if element is \a PIJSON::Array.
//! \~russian Возвращает является ли элемент \a PIJSON::Array.
bool isArray() const {return c_type == Array;}
bool isArray() const { return c_type == Array; }
//! \~english Set value and type of element from "v".
//! \~russian Устанавливает значение и тип элемента из "v".
@@ -122,8 +122,10 @@ public:
//! \~russian Очищает элемент и устанавливает его в \a PIJSON::Invalid.
void clear();
//! \~english Returns size of elements array if type is \a PIJSON::Array, size of elements map if type is \a PIJSON::Object, otherwise returns 0.
//! \~russian Возвращает размер массива элементов если тип \a PIJSON::Array, размер словаря элементов если тип \a PIJSON::Object, иначе возвращает 0.
//! \~english Returns size of elements array if type is \a PIJSON::Array, size of elements map if type is \a PIJSON::Object, otherwise
//! returns 0.
//! \~russian Возвращает размер массива элементов если тип \a PIJSON::Array, размер словаря элементов если тип \a PIJSON::Object, иначе
//! возвращает 0.
int size() const;
//! \~english Returns if elements map contains key "key" if type is \a PIJSON::Object, otherwise returns \b false.
@@ -137,7 +139,10 @@ public:
//! \~english Synonim of \a setValue().
//! \~russian Аналог \a setValue().
PIJSON & operator=(const PIVariant & v) {setValue(v); return *this;}
PIJSON & operator=(const PIVariant & v) {
setValue(v);
return *this;
}
PIJSON & operator=(const PIJSON & v);
@@ -147,24 +152,27 @@ public:
const PIJSON & operator[](int index) const;
//! \~english Set element type to \a PIJSON::Array, resize if necessary and returns element from array with index "index".
//! \~russian Устанавливает тип элемента в \a PIJSON::Array, изменяет размер массива при неоходимости и возвращает элемент из массива по индексу "index".
//! \~russian Устанавливает тип элемента в \a PIJSON::Array, изменяет размер массива при неоходимости и возвращает элемент из массива по
//! индексу "index".
PIJSON & operator[](int index);
//! \~english Set element type to \a PIJSON::Array and add element to the end of array.
//! \~russian Устанавливает тип элемента в \a PIJSON::Array и добавляет элемент в массив.
PIJSON & operator <<(const PIJSON & element);
PIJSON & operator<<(const PIJSON & element);
//! \~english Returns element from map with key "key" if type is \a PIJSON::Object, otherwise returns invalid %PIJSON.
//! \~russian Возвращает элемент из словаря по ключу "key" если тип \a PIJSON::Object, иначе возвращает недействительный %PIJSON.
PIJSON operator[](const PIString & key) const;
//! \~english Set element type to \a PIJSON::Object and returns element from map with key "key". If element with this key doesn`t exists, it will be created.
//! \~russian Устанавливает тип элемента в \a PIJSON::Object и возвращает элемент из словаря по ключу "key". Если элемента с таким ключом не существует, он будет создан.
//! \~english Set element type to \a PIJSON::Object and returns element from map with key "key". If element with this key doesn`t
//! exists, it will be created.
//! \~russian Устанавливает тип элемента в \a PIJSON::Object и возвращает элемент из словаря по ключу "key". Если элемента с таким
//! ключом не существует, он будет создан.
PIJSON & operator[](const PIString & key);
PIJSON operator[](const char * key) const {return (*this)[PIString::fromUTF8(key)];}
PIJSON & operator[](const char * key) {return (*this)[PIString::fromUTF8(key)];}
PIJSON operator[](const char * key) const { return (*this)[PIString::fromUTF8(key)]; }
PIJSON & operator[](const char * key) { return (*this)[PIString::fromUTF8(key)]; }
//! \~english Returns text representation of JSON tree.
@@ -187,7 +195,8 @@ private:
static PIJSON parseArray(PIString s);
static PIString stringMask(const PIString & s, bool mask_unicode);
static PIString stringUnmask(const PIString & s);
static void print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bool transform = false, bool comma = false, bool mask_unicode = true);
static void
print(PIString & s, const PIJSON & v, PIString tab, bool spaces, bool transform = false, bool comma = false, bool mask_unicode = true);
PIString c_name;
PIVariant c_value;
@@ -197,11 +206,10 @@ private:
};
//! \relatesalso PICout
//! \~english Output operator to \a PICout.
//! \~russian Оператор вывода в \a PICout.
inline PICout operator <<(PICout s, const PIJSON & v) {
inline PICout operator<<(PICout s, const PIJSON & v) {
s.space();
s.saveAndSetControls(0);
PIString str;