/*! \file picollection.h
* \ingroup Core
* \~\brief
* \~english Unique classes collection
* \~russian Коллекция уникальных классов
*/
/*
PIP - Platform Independent Primitives
Peer - named I/O ethernet node, forming self-organized peering network
Ivan Pelipenko peri4ko@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 .
*/
#ifndef PICOLLECTION_H
#define PICOLLECTION_H
#include "piobject.h"
#ifdef DOXYGEN
//! \~\relatesalso PICollection
//! \~\brief
//! \~english Add existing element "object" in group with name "group"
//! \~russian Добавляет существующий элемент "object" в группу с именем "group"
//! \~\details
//! \~english
//! If this is no group with name "group" it will be created.
//! Only one element of the class "object" can be in group. If
//! this is already exists nothing be happens. \n "object" should to
//! be pointer to object based on \a PIObject.
//! \~russian
//! Если такой группы нет, она создается. В каждой группе может присутствовать
//! только один элемент класса объекта "object". Если такой элемент уже есть,
//! то ничего не изменится. \n "object" должен быть наследником \a PIObject.
# define ADD_TO_COLLECTION(group, object)
//! \~\relatesalso PICollection
//! \~\brief
//! \~english Add existing element "object" in group with name "group" and set its name to "name"
//! \~russian Добавляет существующий элемент "object" в группу с именем "group" и присваивает объекту имя "name"
//! \~\details
//! \~english
//! Similar to \a ADD_TO_COLLECTION(group, object) but set object name to "name"
//! \~russian
//! Аналогично \a ADD_TO_COLLECTION(group, object), но присваивает имя объекту "name"
# define ADD_TO_COLLECTION_WITH_NAME(group, object, name)
//! \~\relatesalso PICollection
//! \~\brief
//! \~english Add new element of class "class" in group with name "group"
//! \~russian Добавляет новый элемент класса "class" в группу с именем "group"
//! \~\details
//! \~english
//! If this is no group with name "group" it will be created.
//! Only one element of the class "class" can be in group. If
//! this is already exists nothing be happens. \n "class" should to
//! be name of the any class based on PIObject.
//! \~russian
//! Если такой группы нет, она создается. В каждой группе может присутствовать
//! только один элемент класса "class". Если такой элемент уже есть,
//! то ничего не изменится. \n "class" должен быть любым классом, наследным от \a PIObject.
# define ADD_NEW_TO_COLLECTION(group, class)
//! \~\relatesalso PICollection
//! \~\brief
//! \~english Add new element of class "class" in group with name "group" and set its name to "name"
//! \~russian Добавляет новый элемент класса "class" в группу с именем "group" и присваивает объекту имя "name"
//! \~\details
//! \~english
//! Similar to \a ADD_NEW_TO_COLLECTION(group, class) but set object name to "name"
//! \~russian
//! Аналогично \a ADD_NEW_TO_COLLECTION(group, class), но присваивает имя объекту "name"
# define ADD_NEW_TO_COLLECTION_WITH_NAME(group, class, name)
#else
# define ADD_TO_COLLECTION(group, object) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, object, "", false);
# define ADD_TO_COLLECTION_WITH_NAME(group, object, name) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, object, #name, false);
# define ADD_NEW_TO_COLLECTION(group, class) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, new class(), "", true);
# define ADD_NEW_TO_COLLECTION_WITH_NAME(group, class, name) \
static PICollection::CollectionAdder _PIP_ADD_COUNTER(_collection_adder_)(#group, new class(), #name, true);
#endif
//! \ingroup Core
//! \~\brief
//! \~english Helper to collect and retrieve classes to groups.
//! \~russian Помощник для создания и получения классов в группы.
class PIP_EXPORT PICollection {
friend class __PICollectionInitializer;
public:
PICollection() { ; }
//! \~english Returns all existing groups by their names
//! \~russian Возвращает имена всех групп
static PIStringList groups();
//! \~english Returns all elements of group "group"
//! \~russian Возвращает все элементы группы "group"
static PIVector groupElements(const PIString & group);
static bool addToGroup(const PIString & group, const PIObject * element);
class PIP_EXPORT CollectionAdder {
public:
CollectionAdder(const PIString & group, const PIObject * element, const PIString & name = PIString(), bool own = false);
};
protected:
struct PIP_EXPORT Group {
Group(const PIString & name_ = PIString()) { name = name_; }
PIString name;
PIVector elements;
};
static PIVector & _groups();
};
#endif // PICOLLECTION_H