PIPropertyStorage: add return values and documentation in some functions

This commit is contained in:
2020-11-25 12:39:15 +03:00
parent 65d2f6b6e4
commit e0e8266b59
3 changed files with 76 additions and 29 deletions

View File

@@ -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)
if (props[i].name == p.name) {
props[i] = p;
return;
return false;
}
props << p;
return true;
}
void PIPropertyStorage::addProperty(PIPropertyStorage::Property && p) {
bool 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;
return false;
}
props << std::move(p);
return true;
}
void PIPropertyStorage::removeProperty(const PIString & _name) {
for (uint i = 0; i < props.size(); ++i)
bool PIPropertyStorage::addProperty(const PIString & _name, const PIVariant & _def_value, const PIString & _comment, int _flags) {
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) {
props.remove(i);
return;
return true;
}
}
return false;
}
void PIPropertyStorage::removePropertiesByFlag(int flag) {
for (int i = 0; i < props.size_s(); ++i)
int PIPropertyStorage::removePropertiesByFlag(int flag) {
int ret = 0;
for (int i = 0; i < props.size_s(); ++i) {
if ((props[i].flags & flag) == flag) {
props.remove(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) {
for (uint i = 0; i < props.size(); ++i)
bool PIPropertyStorage::setPropertyValue(const PIString & name, const PIVariant & value) {
for (uint i = 0; i < props.size(); ++i) {
if (props[i].name == name) {
props[i].value = value;
return;
return true;
}
}
return false;
}
void PIPropertyStorage::setPropertyComment(const PIString & name, const PIString & comment) {
for (uint i = 0; i < props.size(); ++i)
bool PIPropertyStorage::setPropertyComment(const PIString & name, const PIString & comment) {
for (uint i = 0; i < props.size(); ++i) {
if (props[i].name == name) {
props[i].comment = comment;
return;
return true;
}
}
return false;
}
void PIPropertyStorage::setPropertyFlags(const PIString & name, int flags) {
for (uint i = 0; i < props.size(); ++i)
bool PIPropertyStorage::setPropertyFlags(const PIString & name, int flags) {
for (uint i = 0; i < props.size(); ++i) {
if (props[i].name == name) {
props[i].flags = flags;
return;
return true;
}
}
return false;
}

View File

@@ -110,24 +110,49 @@ public:
PIVector<Property> & properties() {return props;}
const PIVector<Property> & properties() const {return props;}
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;
/**
* @brief Remove all properties
*/
void clearProperties() {props.clear();}
/**
* @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
*/
void addProperty(const Property & p);
void addProperty(Property && p);
bool addProperty(const Property & p);
bool addProperty(Property && p);
/**
* @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.
* @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);
/**
@@ -151,24 +176,27 @@ public:
*
* @param name of property to set value
* @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.
*
* @param name of property to set comment
* @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.
*
* @param name of property to set flags
* @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 PIVector<Property> & p) {props << p; return *this;}