git-svn-id: svn://db.shs.com.ru/pip@806 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-06-23 11:21:46 +00:00
parent 3e36e6af8f
commit 8a2a9e1684
2 changed files with 31 additions and 35 deletions

View File

@@ -14,44 +14,52 @@
PIStringList PICollection::groups() {
PIStringList sl;
piForeachC (Group & g, *_groups)
PIVector<PICollection::Group> & cg(_groups());
piForeachC (Group & g, cg)
sl << g.name;
return sl;
}
PIVector<const PIObject * > PICollection::groupElements(const PIString & group) {
piForeachC (Group & g, *_groups)
PIVector<PICollection::Group> & cg(_groups());
piForeachC (Group & g, cg)
if (g.name == group)
return g.elements;
return PIVector<const PIObject * >();
}
void PICollection::addToGroup(const PIString & group, const PIObject * element) {
bool PICollection::addToGroup(const PIString & group, const PIObject * element) {
//piCout << "add to" << group << element;
PIString n = element->className();
piForeach (Group & g, *_groups)
PIString n = PIStringAscii(element->className());
PIVector<PICollection::Group> & cg(_groups());
piForeach (Group & g, cg)
if (g.name == group) {
for (int i = 0; i < g.elements.size_s(); ++i)
if (PIString(g.elements[i]->className()) == n)
return;
return false;
g.elements << element;
//piCout << "new group" << group << ", ok";
return;
return true;
}
*_groups << Group(group);
_groups->back().elements << element;
_groups() << Group(group);
_groups().back().elements << element;
//piCout << "new group" << group << ", ok";
return true;
}
PICollection::CollectionAdder::CollectionAdder(const PIString & group, const PIObject * element, const PIString & name) {
if (element == 0) return;
PIVector<PICollection::Group> & PICollection::_groups() {
static PIVector<PICollection::Group> ret;
return ret;
}
PICollection::CollectionAdder::CollectionAdder(const PIString & group, const PIObject * element, const PIString & name, bool own) {
if (!element) return;
const_cast<PIObject * >(element)->setName(name);
PICollection::addToGroup(group, element);
bool added = PICollection::addToGroup(group, element);
if (!added && own)
delete element;
}
bool __PICollectionInitializer::_inited_(false);
PIVector<PICollection::Group> * PICollection::_groups;