Merge pull request 'PIPropertyStorage: add return values and documentation in some functions' (#52) from propertystorage_imp into master
Reviewed-on: https://git.shs.tools/SHS/pip/pulls/52
This commit was merged in pull request #52.
This commit is contained in:
@@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 14)
|
set(pip_MINOR 15)
|
||||||
set(pip_REVISION 2)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
set(pip_DOMAIN org.SHS)
|
set(pip_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -28,41 +28,54 @@ bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) {
|
bool PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) {
|
||||||
for (uint i = 0; i < props.size(); ++i)
|
for (uint i = 0; i < props.size(); ++i)
|
||||||
if (props[i].name == p.name) {
|
if (props[i].name == p.name) {
|
||||||
props[i] = p;
|
props[i] = p;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
props << p;
|
props << p;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::addProperty(PIPropertyStorage::Property && p) {
|
bool PIPropertyStorage::addProperty(PIPropertyStorage::Property && p) {
|
||||||
for (uint i = 0; i < props.size(); ++i)
|
for (uint i = 0; i < props.size(); ++i)
|
||||||
if (props[i].name == p.name) {
|
if (props[i].name == p.name) {
|
||||||
props[i] = std::move(p);
|
props[i] = std::move(p);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
props << std::move(p);
|
props << std::move(p);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::removeProperty(const PIString & _name) {
|
bool PIPropertyStorage::addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment, int _flags) {
|
||||||
for (uint i = 0; i < props.size(); ++i)
|
return addProperty(Property(_name, _comment, _def_value, _flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIPropertyStorage::removeProperty(const PIString & _name) {
|
||||||
|
for (uint i = 0; i < props.size(); ++i) {
|
||||||
if (props[i].name == _name) {
|
if (props[i].name == _name) {
|
||||||
props.remove(i);
|
props.remove(i);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::removePropertiesByFlag(int flag) {
|
int PIPropertyStorage::removePropertiesByFlag(int flag) {
|
||||||
for (int i = 0; i < props.size_s(); ++i)
|
int ret = 0;
|
||||||
|
for (int i = 0; i < props.size_s(); ++i) {
|
||||||
if ((props[i].flags & flag) == flag) {
|
if ((props[i].flags & flag) == flag) {
|
||||||
props.remove(i);
|
props.remove(i);
|
||||||
--i;
|
--i;
|
||||||
|
ret++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -99,30 +112,36 @@ PIVariant PIPropertyStorage::propertyValueByName(const PIString & name) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::setPropertyValue(const PIString & name, const PIVariant & value) {
|
bool PIPropertyStorage::setPropertyValue(const PIString & name, const PIVariant & value) {
|
||||||
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) {
|
||||||
props[i].value = value;
|
props[i].value = value;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::setPropertyComment(const PIString & name, const PIString & comment) {
|
bool PIPropertyStorage::setPropertyComment(const PIString & name, const PIString & comment) {
|
||||||
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) {
|
||||||
props[i].comment = comment;
|
props[i].comment = comment;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIPropertyStorage::setPropertyFlags(const PIString & name, int flags) {
|
bool PIPropertyStorage::setPropertyFlags(const PIString & name, int flags) {
|
||||||
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) {
|
||||||
props[i].flags = flags;
|
props[i].flags = flags;
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -110,24 +110,49 @@ public:
|
|||||||
PIVector<Property> & properties() {return props;}
|
PIVector<Property> & properties() {return props;}
|
||||||
const PIVector<Property> & properties() const {return props;}
|
const PIVector<Property> & properties() const {return props;}
|
||||||
const PIPropertyStorage & propertyStorage() const {return *this;}
|
const PIPropertyStorage & propertyStorage() const {return *this;}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if property with \a name exists
|
||||||
|
* @return "true" if property exists
|
||||||
|
*/
|
||||||
bool isPropertyExists(const PIString & _name) const;
|
bool isPropertyExists(const PIString & _name) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove all properties
|
||||||
|
*/
|
||||||
void clearProperties() {props.clear();}
|
void clearProperties() {props.clear();}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add property if name isn't present in storage, otherwrise update existing property with same name.
|
* @brief Add property if name isn't present in storage, otherwrise update existing property with same name.
|
||||||
*
|
* @return "true" if new property added, else if update existing property return "false"
|
||||||
* @param p to copy in storage
|
* @param p to copy in storage
|
||||||
*/
|
*/
|
||||||
void addProperty(const Property & p);
|
bool addProperty(const Property & p);
|
||||||
void addProperty(Property && p);
|
bool 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
|
||||||
* in storage, otherwrise update existing property with same name.
|
* in storage, otherwrise update existing property with same name.
|
||||||
|
* @return "true" if new property added, else if update existing property return "false"
|
||||||
|
*/
|
||||||
|
bool addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment = PIString(), int _flags = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove property with \a name
|
||||||
|
* @return "true" if property exists and removed
|
||||||
|
*/
|
||||||
|
bool removeProperty(const PIString & _name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove properties wich has \a flag set
|
||||||
|
* @return removed properties count
|
||||||
|
*/
|
||||||
|
int removePropertiesByFlag(int flag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Merge other \a properties_ into this
|
||||||
|
* @param flag_ignore - properties wich has this flag set will be ignored in merge
|
||||||
*/
|
*/
|
||||||
void addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment = PIString(), int _flags = 0) {addProperty(Property(_name, _comment, _def_value, _flags));}
|
|
||||||
void removeProperty(const PIString & _name);
|
|
||||||
void removePropertiesByFlag(int flag);
|
|
||||||
void updateProperties(const PIVector<Property> & properties_, int flag_ignore = 0);
|
void updateProperties(const PIVector<Property> & properties_, int flag_ignore = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,24 +176,27 @@ public:
|
|||||||
*
|
*
|
||||||
* @param name of property to set value
|
* @param name of property to set value
|
||||||
* @param value to set
|
* @param value to set
|
||||||
|
* @return "true" if property exists and updated
|
||||||
*/
|
*/
|
||||||
void setPropertyValue(const PIString & name, const PIVariant & value);
|
bool setPropertyValue(const PIString & name, const PIVariant & value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set comment of property with specific name if name is present in storage.
|
* @brief Set comment of property with specific name if name is present in storage.
|
||||||
*
|
*
|
||||||
* @param name of property to set comment
|
* @param name of property to set comment
|
||||||
* @param comment to set
|
* @param comment to set
|
||||||
|
* @return "true" if property exists and updated
|
||||||
*/
|
*/
|
||||||
void setPropertyComment(const PIString & name, const PIString & comment);
|
bool setPropertyComment(const PIString & name, const PIString & comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set flags of property with specific name if name is present in storage.
|
* @brief Set flags of property with specific name if name is present in storage.
|
||||||
*
|
*
|
||||||
* @param name of property to set flags
|
* @param name of property to set flags
|
||||||
* @param flags to set
|
* @param flags to set
|
||||||
|
* @return "true" if property exists and updated
|
||||||
*/
|
*/
|
||||||
void setPropertyFlags(const PIString & name, int flags);
|
bool setPropertyFlags(const PIString & name, int flags);
|
||||||
|
|
||||||
PIPropertyStorage & operator <<(const PIPropertyStorage::Property & p) {props << p; return *this;}
|
PIPropertyStorage & operator <<(const PIPropertyStorage::Property & p) {props << p; return *this;}
|
||||||
PIPropertyStorage & operator <<(const PIVector<Property> & p) {props << p; return *this;}
|
PIPropertyStorage & operator <<(const PIVector<Property> & p) {props << p; return *this;}
|
||||||
|
|||||||
Reference in New Issue
Block a user