git-svn-id: svn://db.shs.com.ru/pip@806 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -44,10 +44,10 @@
|
||||
# define ADD_NEW_TO_COLLECTION(group, class)
|
||||
|
||||
#else
|
||||
# define ADD_TO_COLLECTION(group, object) static PICollection::CollectionAdder __##group##_##__LINE__##_##adder##__(#group, object);
|
||||
# define ADD_TO_COLLECTION_WITH_NAME(group, object, name) static PICollection::CollectionAdder __##group##_##__LINE__##_##adder##__(#group, object, #name);
|
||||
# define ADD_NEW_TO_COLLECTION(group, class) static PICollection::CollectionAdder __##group##_##class##_##adder##__(#group, new class());
|
||||
# define ADD_NEW_TO_COLLECTION_WITH_NAME(group, class, name) static PICollection::CollectionAdder __##group##_##class##_##adder##__(#group, new class(), #name);
|
||||
# define ADD_TO_COLLECTION(group, object) static PICollection::CollectionAdder __##group##_##__LINE__##_##adder##__(#group, object, false);
|
||||
# define ADD_TO_COLLECTION_WITH_NAME(group, object, name) static PICollection::CollectionAdder __##group##_##__LINE__##_##adder##__(#group, object, #name, false);
|
||||
# define ADD_NEW_TO_COLLECTION(group, class) static PICollection::CollectionAdder __##group##_##class##_##adder##__(#group, new class(), true);
|
||||
# define ADD_NEW_TO_COLLECTION_WITH_NAME(group, class, name) static PICollection::CollectionAdder __##group##_##class##_##adder##__(#group, new class(), #name, true);
|
||||
#endif
|
||||
|
||||
class PIP_EXPORT PICollection
|
||||
@@ -62,11 +62,11 @@ public:
|
||||
//! \brief Returns all elements of group "group"
|
||||
static PIVector<const PIObject * > groupElements(const PIString & group);
|
||||
|
||||
static void addToGroup(const PIString & group, const PIObject * element);
|
||||
static bool addToGroup(const PIString & group, const PIObject * element);
|
||||
|
||||
class CollectionAdder {
|
||||
public:
|
||||
CollectionAdder(const PIString & group, const PIObject * element, const PIString & name = PIString());
|
||||
CollectionAdder(const PIString & group, const PIObject * element, const PIString & name = PIString(), bool own = false);
|
||||
};
|
||||
|
||||
protected:
|
||||
@@ -77,20 +77,8 @@ protected:
|
||||
PIVector<const PIObject * > elements;
|
||||
};
|
||||
|
||||
static PIVector<Group> * _groups;
|
||||
static PIVector<Group> & _groups();
|
||||
|
||||
};
|
||||
|
||||
class PIP_EXPORT __PICollectionInitializer {
|
||||
public:
|
||||
__PICollectionInitializer() {
|
||||
if (_inited_) return;
|
||||
_inited_ = true;
|
||||
PICollection::_groups = new PIVector<PICollection::Group>();
|
||||
}
|
||||
static bool _inited_;
|
||||
};
|
||||
|
||||
static __PICollectionInitializer __picollectioninitializer;
|
||||
|
||||
#endif // PICOLLECTION_H
|
||||
|
||||
Reference in New Issue
Block a user