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_MAJOR 2)
|
||||||
set(_PIP_MINOR 0)
|
set(_PIP_MINOR 0)
|
||||||
set(_PIP_REVISION 0)
|
set(_PIP_REVISION 0)
|
||||||
set(_PIP_SUFFIX _prebeta)
|
set(_PIP_SUFFIX _prealpha)
|
||||||
set(_PIP_COMPANY SHS)
|
set(_PIP_COMPANY SHS)
|
||||||
set(_PIP_DOMAIN org.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) {
|
void PIPropertyStorage::removeProperty(const PIString & _name) {
|
||||||
for (uint i = 0; i < props.size(); ++i)
|
for (uint i = 0; i < props.size(); ++i)
|
||||||
if (props[i].name == _name) {
|
if (props[i].name == _name) {
|
||||||
|
|||||||
@@ -42,13 +42,33 @@ public:
|
|||||||
struct PIP_EXPORT Property {
|
struct PIP_EXPORT Property {
|
||||||
Property(const PIString & n = PIString(), const PIString & c = PIString(), const PIVariant & v = PIVariant(), int f = 0):
|
Property(const PIString & n = PIString(), const PIString & c = PIString(), const PIVariant & v = PIVariant(), int f = 0):
|
||||||
name(n), comment(c), value(v), flags(f) {}
|
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();}
|
bool toBool() const {return value.toBool();}
|
||||||
int toInt() const {return value.toInt();}
|
int toInt() const {return value.toInt();}
|
||||||
float toFloat() const {return value.toFloat();}
|
float toFloat() const {return value.toFloat();}
|
||||||
double toDouble() const {return value.toDouble();}
|
double toDouble() const {return value.toDouble();}
|
||||||
PIString toString() const {return value.toString();}
|
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 */
|
/*! Uniqueue id of property */
|
||||||
PIString name;
|
PIString name;
|
||||||
|
|
||||||
@@ -64,6 +84,8 @@ public:
|
|||||||
|
|
||||||
PIPropertyStorage(const PIVector<Property> & pl) {props = pl;}
|
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>::const_iterator const_iterator;
|
||||||
typedef PIVector<Property>::iterator iterator;
|
typedef PIVector<Property>::iterator iterator;
|
||||||
typedef Property value_type;
|
typedef Property value_type;
|
||||||
@@ -97,6 +119,7 @@ public:
|
|||||||
* @param p to copy in storage
|
* @param p to copy in storage
|
||||||
*/
|
*/
|
||||||
void addProperty(const Property & p);
|
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
|
* @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;
|
_type = v._type;
|
||||||
_content = v._content;
|
_content = v._content;
|
||||||
#ifdef CUSTOM_PIVARIANT
|
#ifdef CUSTOM_PIVARIANT
|
||||||
@@ -68,6 +68,11 @@ PIVariant::PIVariant(const PIVariant &v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PIVariant::PIVariant(PIVariant && v) {
|
||||||
|
swap(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIVariant::setValueFromString(const PIString & v) {
|
void PIVariant::setValueFromString(const PIString & v) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case PIVariant::pivBool: {setValue(v.toBool());} break;
|
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 {
|
bool PIVariant::operator ==(const PIVariant & v) const {
|
||||||
return (_type == v._type) && (_content == v._content);
|
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) {
|
PIString PIVariant::typeName(PIVariant::Type type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PIVariant::pivBool: return "Bool";
|
case PIVariant::pivBool: return "Bool";
|
||||||
|
|||||||
@@ -247,6 +247,8 @@ public:
|
|||||||
|
|
||||||
PIVariant(const PIVariant & v);
|
PIVariant(const PIVariant & v);
|
||||||
|
|
||||||
|
PIVariant(PIVariant && v);
|
||||||
|
|
||||||
//! Constructs variant from string
|
//! Constructs variant from string
|
||||||
PIVariant(const char * v) {initType(PIString(v));}
|
PIVariant(const char * v) {initType(PIString(v));}
|
||||||
|
|
||||||
@@ -467,6 +469,8 @@ public:
|
|||||||
//! Assign operator
|
//! Assign operator
|
||||||
PIVariant & operator =(const PIVariant & v);
|
PIVariant & operator =(const PIVariant & v);
|
||||||
//! Assign operator
|
//! Assign operator
|
||||||
|
PIVariant & operator =(PIVariant && v);
|
||||||
|
//! Assign operator
|
||||||
PIVariant & operator =(const char * v) {setValue(PIString(v)); return *this;}
|
PIVariant & operator =(const char * v) {setValue(PIString(v)); return *this;}
|
||||||
//! Assign operator
|
//! Assign operator
|
||||||
PIVariant & operator =(const bool v) {setValue(v); return *this;}
|
PIVariant & operator =(const bool v) {setValue(v); return *this;}
|
||||||
@@ -544,6 +548,8 @@ public:
|
|||||||
//! Returns \b true if type is not Invalid
|
//! Returns \b true if type is not Invalid
|
||||||
bool isValid() const {return _type != PIVariant::pivInvalid;}
|
bool isValid() const {return _type != PIVariant::pivInvalid;}
|
||||||
|
|
||||||
|
void swap(PIVariant & v);
|
||||||
|
|
||||||
|
|
||||||
/** \brief Returns new variant from custom type
|
/** \brief Returns new variant from custom type
|
||||||
* \details In case of known types this function equivalent \a PIVariant(T) constructors. \n
|
* \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) {
|
PIFile &PIFile::operator <<(double v) {
|
||||||
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v);
|
if (canWrite() && PRIVATE->fd != 0) ret = fprintf(PRIVATE->fd, ("%" + prec_str + "lf").data(), v);
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
@@ -145,6 +145,10 @@ public:
|
|||||||
|
|
||||||
//! Set float numbers write precision to "prec_" digits
|
//! Set float numbers write precision to "prec_" digits
|
||||||
void setPrecision(int prec);
|
void setPrecision(int prec);
|
||||||
|
|
||||||
|
PIFile & put(const PIByteArray & v);
|
||||||
|
|
||||||
|
PIByteArray get();
|
||||||
|
|
||||||
|
|
||||||
//! Write to file binary content of "v"
|
//! Write to file binary content of "v"
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo(bool ignore_cache) {
|
|||||||
if (l_df.size_s() < 2) return ret;
|
if (l_df.size_s() < 2) return ret;
|
||||||
l_df.pop_front();
|
l_df.pop_front();
|
||||||
piForeachC (PIString & s, l_df) {
|
piForeachC (PIString & s, l_df) {
|
||||||
PIStringList ml(s.replaceAll(" ", " ").split(" "));
|
PIStringList ml(s.replacedAll(" ", " ").split(" "));
|
||||||
if (ml.size_s() < 2) continue;
|
if (ml.size_s() < 2) continue;
|
||||||
if (ml.front() == "none") continue;
|
if (ml.front() == "none") continue;
|
||||||
m.space_all = ml[1].toULLong();
|
m.space_all = ml[1].toULLong();
|
||||||
|
|||||||
Reference in New Issue
Block a user