diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ebfa3fb..63499225 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(pip) set(pip_MAJOR 2) -set(pip_MINOR 14) -set(pip_REVISION 2) +set(pip_MINOR 15) +set(pip_REVISION 0) set(pip_SUFFIX ) set(pip_COMPANY SHS) set(pip_DOMAIN org.SHS) diff --git a/libs/main/core/pipropertystorage.cpp b/libs/main/core/pipropertystorage.cpp index 679d374b..246ba6c9 100644 --- a/libs/main/core/pipropertystorage.cpp +++ b/libs/main/core/pipropertystorage.cpp @@ -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; } diff --git a/libs/main/core/pipropertystorage.h b/libs/main/core/pipropertystorage.h index 9dc4098c..31f01cd3 100644 --- a/libs/main/core/pipropertystorage.h +++ b/libs/main/core/pipropertystorage.h @@ -110,24 +110,49 @@ public: PIVector & properties() {return props;} const PIVector & 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 & 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 & p) {props << p; return *this;}