PIJSON doc and << operator

This commit is contained in:
2022-09-30 21:09:57 +03:00
parent 0f48c206c3
commit 3c7e117661
3 changed files with 147 additions and 30 deletions

View File

@@ -86,6 +86,122 @@
//! Методы \a toJSON() и \a fromJSON() маскируют и размаскируют строковые поля.
//!
//!
//! \~english \section PIJSON_sec4 Examples
//! \~russian \section PIJSON_sec4 Примеры
//! \~english
//!
//! \~russian
//! Чтение:
//! \~\code
//! PIJSON json = PIJSON::fromJSON(
//! "["
//! " true,"
//! " 10,"
//! " {"
//! " \"num\":1.E-2,"
//! " \"str\":\"text\""
//! " },"
//! "]");
//! piCout << json;
//! piCout << json.toJSON();
//! \endcode
//! \~\code
//! [
//! true,
//! 10,
//! {
//! "num": 1.e-2,
//! "str": "text"
//! }
//! ]
//!
//! [true,10,{"num":1.e-2,"str":"text"}]
//! \endcode
//! Разбор:
//! \~\code
//! PIJSON json = PIJSON::fromJSON(
//! "["
//! " true,"
//! " 10,"
//! " {"
//! " \"num\":1.E-2,"
//! " \"str\":\"text\""
//! " },"
//! "]");
//! piCout << "top-level:";
//! for (const auto & i: json.array())
//! piCout << i.value();
//! piCout << "[2][\"str\"]:";
//! piCout << json[2]["str"].toString();
//! \endcode
//! \~\code
//! top-level:
//! PIVariant(Bool, 1)
//! PIVariant(String, 10)
//! PIVariant(Invalid)
//! [2]["str"]:
//! text
//! \endcode
//!
//! Создание:\n
//! Простой массив
//! \~\code
//! PIJSON json;
//! json[0] = -1;
//! json[1] = "text";
//! json[3] = false;
//! piCout << json.toJSON();
//! \endcode
//! \~\code
//! [-1,"text","",false]
//! \endcode
//!
//! Массив объектов
//! \~\code
//! struct {
//! PIString name;
//! PIString surname;
//! PIString email;
//! } persons[] = {
//! {"Ivan", "Ivanov", "ivan@pip.ru"},
//! {"Igor", "Igorevich", "igor@pip.ru"},
//! {"Andrey", "Andreevich", "andrey@pip.ru"}
//! };
//! PIJSON obj;
//! PIJSON json;
//! int index = 0;
//! for (const auto & p: persons) {
//! obj["index"] = index++;
//! obj["name"] = p.name;
//! obj["surname"] = p.surname;
//! obj["email"] = p.email;
//! json << obj;
//! }
//! piCout << json;
//! \endcode
//! \~\code
//! [
//! {
//! "name": "Ivan",
//! "email": "ivan@pip.ru",
//! "index": 0,
//! "surname": "Ivanov"
//! },
//! {
//! "name": "Igor",
//! "email": "igor@pip.ru",
//! "index": 1,
//! "surname": "Igorevich"
//! },
//! {
//! "name": "Andrey",
//! "email": "andrey@pip.ru",
//! "index": 2,
//! "surname": "Andreevich"
//! }
//! ]
//! \endcode
//!
PIJSON PIJSON::newObject() {
@@ -113,7 +229,7 @@ const PIVector<PIJSON> & PIJSON::array() const {
if (!isArray()) {
return nullEntry().c_array;
} else {
return c_array;
return c_array;
}
}
@@ -202,6 +318,13 @@ PIJSON & PIJSON::operator[](int index) {
}
PIJSON & PIJSON::operator<<(const PIJSON & element) {
c_type = Array;
c_array << element;
return *this;
}
PIJSON & PIJSON::operator=(const PIJSON & v) {
c_type = v.c_type;
c_value = v.c_value;