version 2.0.0_prealpha
PIFile::put() and get()
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -42,6 +42,19 @@ 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();}
|
||||
@@ -49,6 +62,13 @@ public:
|
||||
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<Property> & pl) {props = pl;}
|
||||
|
||||
PIPropertyStorage(PIVector<Property> && pl): props(std::move(pl)) {}
|
||||
|
||||
typedef PIVector<Property>::const_iterator const_iterator;
|
||||
typedef PIVector<Property>::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
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -146,6 +146,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"
|
||||
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
|
||||
|
||||
@@ -178,7 +178,7 @@ PIVector<PISystemInfo::MountInfo> 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();
|
||||
|
||||
Reference in New Issue
Block a user