PIJSON::new* now accept optional initial fields
This commit is contained in:
@@ -325,10 +325,10 @@ public:
|
||||
//! Network interface descriptor
|
||||
struct PIP_EXPORT Interface {
|
||||
//! System index
|
||||
int index;
|
||||
int index = -1;
|
||||
|
||||
//! MTU
|
||||
int mtu;
|
||||
int mtu = 0;
|
||||
|
||||
//! System name
|
||||
PIString name;
|
||||
@@ -351,6 +351,9 @@ public:
|
||||
//! Flags of interface
|
||||
InterfaceFlags flags;
|
||||
|
||||
//! Returns if interface is active
|
||||
bool isValid() const { return name.isNotEmpty(); }
|
||||
|
||||
//! Returns if interface is active
|
||||
bool isActive() const { return flags[PIEthernet::ifActive]; }
|
||||
|
||||
|
||||
@@ -204,16 +204,21 @@
|
||||
//!
|
||||
|
||||
|
||||
PIJSON PIJSON::newObject() {
|
||||
PIJSON PIJSON::newObject(const PIVariantMap & fields) {
|
||||
PIJSON ret;
|
||||
ret.c_type = Object;
|
||||
auto it = fields.makeIterator();
|
||||
while (it.next())
|
||||
ret[it.key()] = it.value();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIJSON PIJSON::newArray() {
|
||||
PIJSON PIJSON::newArray(const PIVariantVector & fields) {
|
||||
PIJSON ret;
|
||||
ret.c_type = Array;
|
||||
for (const auto & i: fields)
|
||||
ret << i;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -325,6 +330,15 @@ PIJSON & PIJSON::operator<<(const PIJSON & element) {
|
||||
}
|
||||
|
||||
|
||||
PIJSON & PIJSON::operator<<(const PIVariant & element) {
|
||||
c_type = Array;
|
||||
PIJSON e;
|
||||
e = element;
|
||||
c_array << e;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
PIJSON & PIJSON::operator=(const PIJSON & v) {
|
||||
c_type = v.c_type;
|
||||
c_value = v.c_value;
|
||||
|
||||
@@ -160,6 +160,10 @@ public:
|
||||
//! \~russian Устанавливает тип элемента в \a PIJSON::Array и добавляет элемент в массив.
|
||||
PIJSON & operator<<(const PIJSON & element);
|
||||
|
||||
//! \~english Set element type to \a PIJSON::Array and add element to the end of array.
|
||||
//! \~russian Устанавливает тип элемента в \a PIJSON::Array и добавляет элемент в массив.
|
||||
PIJSON & operator<<(const PIVariant & value);
|
||||
|
||||
|
||||
//! \~english Returns element from map with key "key" if type is \a PIJSON::Object, otherwise returns invalid %PIJSON.
|
||||
//! \~russian Возвращает элемент из словаря по ключу "key" если тип \a PIJSON::Object, иначе возвращает недействительный %PIJSON.
|
||||
@@ -183,8 +187,8 @@ public:
|
||||
//! \~russian Разбирает текстовое представление JSON "str" и возвращает его корневой элемент.
|
||||
static PIJSON fromJSON(PIString str);
|
||||
|
||||
static PIJSON newObject();
|
||||
static PIJSON newArray();
|
||||
static PIJSON newObject(const PIVariantMap & fields = {});
|
||||
static PIJSON newArray(const PIVariantVector & fields = {});
|
||||
static PIJSON newString(const PIString & v = PIString());
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user