tree changes
This commit is contained in:
143
libs/main/core/pipropertystorage.cpp
Normal file
143
libs/main/core/pipropertystorage.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Storage of properties for GUI usage
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pipropertystorage.h"
|
||||
|
||||
|
||||
bool PIPropertyStorage::isPropertyExists(const PIString & _name) const {
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == _name)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PIPropertyStorage::addProperty(const PIPropertyStorage::Property & p) {
|
||||
for (uint i = 0; i < props.size(); ++i)
|
||||
if (props[i].name == p.name) {
|
||||
props[i] = p;
|
||||
return;
|
||||
}
|
||||
props << 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) {
|
||||
props.remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PIPropertyStorage::removePropertiesByFlag(int flag) {
|
||||
for (int i = 0; i < props.size_s(); ++i)
|
||||
if ((props[i].flags & flag) == flag) {
|
||||
props.remove(i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PIPropertyStorage::updateProperties(const PIVector<PIPropertyStorage::Property> & properties_, int flag_ignore) {
|
||||
PIMap<PIString, PIVariant> values;
|
||||
piForeachC(Property & p, props)
|
||||
if (((p.flags & flag_ignore) != flag_ignore) || (flag_ignore == 0))
|
||||
values[p.name] = p.value;
|
||||
props = properties_;
|
||||
for (uint i = 0; i < props.size(); ++i) {
|
||||
Property & p(props[i]);
|
||||
if (values.contains(p.name)) {
|
||||
PIVariant pv = values[p.name];
|
||||
if (pv.type() == p.value.type())
|
||||
p.value = pv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIPropertyStorage::Property PIPropertyStorage::propertyByName(const PIString & name) const {
|
||||
piForeachC(Property & p, props)
|
||||
if (p.name == name)
|
||||
return p;
|
||||
return Property();
|
||||
}
|
||||
|
||||
|
||||
PIVariant PIPropertyStorage::propertyValueByName(const PIString & name) const {
|
||||
piForeachC(Property & p, props)
|
||||
if (p.name == name)
|
||||
return p.value;
|
||||
return PIVariant();
|
||||
}
|
||||
|
||||
|
||||
void 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIPropertyStorage::Property & PIPropertyStorage::operator[](const PIString & name) {
|
||||
piForeach (Property & p, props)
|
||||
if (p.name == name)
|
||||
return p;
|
||||
addProperty(name, "");
|
||||
return props.back();
|
||||
}
|
||||
|
||||
|
||||
const PIPropertyStorage::Property PIPropertyStorage::operator[](const PIString & name) const {
|
||||
piForeachC (Property & p, props)
|
||||
if (p.name == name)
|
||||
return p;
|
||||
return Property();
|
||||
}
|
||||
Reference in New Issue
Block a user