diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c16f052..dd573d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(pip) set(_PIP_MAJOR 2) set(_PIP_MINOR 0) set(_PIP_REVISION 0) -set(_PIP_SUFFIX _prebeta) +set(_PIP_SUFFIX _prealpha) set(_PIP_COMPANY SHS) set(_PIP_DOMAIN org.SHS) diff --git a/lib/main/core/pipropertystorage.cpp b/lib/main/core/pipropertystorage.cpp index e68d7238..679d374b 100644 --- a/lib/main/core/pipropertystorage.cpp +++ b/lib/main/core/pipropertystorage.cpp @@ -38,6 +38,16 @@ void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) { } +void PIPropertyStorage::addProperty(PIPropertyStorage::Property && p) { + for (uint i = 0; i < props.size(); ++i) + if (props[i].name == p.name) { + props[i] = std::move(p); + return; + } + props << std::move(p); +} + + void PIPropertyStorage::removeProperty(const PIString & _name) { for (uint i = 0; i < props.size(); ++i) if (props[i].name == _name) { diff --git a/lib/main/core/pipropertystorage.h b/lib/main/core/pipropertystorage.h index a4a8ad15..c338b968 100644 --- a/lib/main/core/pipropertystorage.h +++ b/lib/main/core/pipropertystorage.h @@ -42,13 +42,33 @@ public: struct PIP_EXPORT Property { Property(const PIString & n = PIString(), const PIString & c = PIString(), const PIVariant & v = PIVariant(), int f = 0): name(n), comment(c), value(v), flags(f) {} - + Property(const Property & o): + name(o.name), comment(o.comment), value(o.value), flags(o.flags) {} + Property(Property && o) {swap(o);} + + Property & operator =(const Property & v) { + name = v.name; + comment = v.comment; + value = v.value; + flags = v.flags; + return *this; + } + Property & operator =(Property && v) {swap(v); return *this;} + + bool toBool() const {return value.toBool();} int toInt() const {return value.toInt();} float toFloat() const {return value.toFloat();} double toDouble() const {return value.toDouble();} PIString toString() const {return value.toString();} - + + void swap(Property & o) { + name.swap(o.name); + comment.swap(o.comment); + value.swap(o.value); + piSwap(flags, o.flags); + } + /*! Uniqueue id of property */ PIString name; @@ -64,6 +84,8 @@ public: PIPropertyStorage(const PIVector & pl) {props = pl;} + PIPropertyStorage(PIVector && pl): props(std::move(pl)) {} + typedef PIVector::const_iterator const_iterator; typedef PIVector::iterator iterator; typedef Property value_type; @@ -97,6 +119,7 @@ public: * @param p to copy in storage */ void addProperty(const Property & p); + void addProperty(Property && p); /** * @brief First of all construct Property with method params. After then add property if name isn't present diff --git a/lib/main/core/pivariant.cpp b/lib/main/core/pivariant.cpp index 2281ce11..9e9da078 100644 --- a/lib/main/core/pivariant.cpp +++ b/lib/main/core/pivariant.cpp @@ -59,7 +59,7 @@ PIVariant::PIVariant() { } -PIVariant::PIVariant(const PIVariant &v) { +PIVariant::PIVariant(const PIVariant & v) { _type = v._type; _content = v._content; #ifdef CUSTOM_PIVARIANT @@ -68,6 +68,11 @@ PIVariant::PIVariant(const PIVariant &v) { } +PIVariant::PIVariant(PIVariant && v) { + swap(v); +} + + void PIVariant::setValueFromString(const PIString & v) { switch (_type) { case PIVariant::pivBool: {setValue(v.toBool());} break; @@ -108,6 +113,12 @@ PIVariant & PIVariant::operator =(const PIVariant & v) { } +PIVariant & PIVariant::operator =(PIVariant && v) { + swap(v); + return *this; +} + + bool PIVariant::operator ==(const PIVariant & v) const { return (_type == v._type) && (_content == v._content); } @@ -161,6 +172,15 @@ PIString PIVariant::typeName() const { } +void PIVariant::swap(PIVariant & v) { + piSwap(_type, v._type); + _content.swap(v._content); +#ifdef CUSTOM_PIVARIANT + piSwap(_info, v._info); +#endif +} + + PIString PIVariant::typeName(PIVariant::Type type) { switch (type) { case PIVariant::pivBool: return "Bool"; diff --git a/lib/main/core/pivariant.h b/lib/main/core/pivariant.h index f5da7ce1..bea37f17 100644 --- a/lib/main/core/pivariant.h +++ b/lib/main/core/pivariant.h @@ -247,6 +247,8 @@ public: PIVariant(const PIVariant & v); + PIVariant(PIVariant && v); + //! Constructs variant from string PIVariant(const char * v) {initType(PIString(v));} @@ -467,6 +469,8 @@ public: //! Assign operator PIVariant & operator =(const PIVariant & v); //! Assign operator + PIVariant & operator =(PIVariant && v); + //! Assign operator PIVariant & operator =(const char * v) {setValue(PIString(v)); return *this;} //! Assign operator PIVariant & operator =(const bool v) {setValue(v); return *this;} @@ -544,6 +548,8 @@ public: //! Returns \b true if type is not Invalid bool isValid() const {return _type != PIVariant::pivInvalid;} + void swap(PIVariant & v); + /** \brief Returns new variant from custom type * \details In case of known types this function equivalent \a PIVariant(T) constructors. \n diff --git a/lib/main/io_devices/pifile.cpp b/lib/main/io_devices/pifile.cpp index e0e78ec6..efbcb521 100644 --- a/lib/main/io_devices/pifile.cpp +++ b/lib/main/io_devices/pifile.cpp @@ -394,6 +394,25 @@ void PIFile::setPrecision(int prec) { } +PIFile & PIFile::put(const PIByteArray & v) { + writeBinary((int)v.size_s()); + write(v); + return *this; +} + + +PIByteArray PIFile::get() { + PIByteArray ret; + int sz(0); + read(&sz, sizeof(sz)); + if (sz > 0) { + ret.resize(sz); + read(ret.data(), sz); + } + return ret; +} + + PIFile &PIFile::operator <<(double v) { if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v); return *this; diff --git a/lib/main/io_devices/pifile.h b/lib/main/io_devices/pifile.h index 1f94625b..ca6d0e6b 100644 --- a/lib/main/io_devices/pifile.h +++ b/lib/main/io_devices/pifile.h @@ -145,6 +145,10 @@ public: //! Set float numbers write precision to "prec_" digits void setPrecision(int prec); + + PIFile & put(const PIByteArray & v); + + PIByteArray get(); //! Write to file binary content of "v" diff --git a/lib/main/system/pisysteminfo.cpp b/lib/main/system/pisysteminfo.cpp index bcea0873..aec6aeb2 100644 --- a/lib/main/system/pisysteminfo.cpp +++ b/lib/main/system/pisysteminfo.cpp @@ -178,7 +178,7 @@ PIVector PISystemInfo::mountInfo(bool ignore_cache) { if (l_df.size_s() < 2) return ret; l_df.pop_front(); piForeachC (PIString & s, l_df) { - PIStringList ml(s.replaceAll(" ", " ").split(" ")); + PIStringList ml(s.replacedAll(" ", " ").split(" ")); if (ml.size_s() < 2) continue; if (ml.front() == "none") continue; m.space_all = ml[1].toULLong();