#ifndef __XIOS_CGroupFactory_impl__ #define __XIOS_CGroupFactory_impl__ #include "group_factory.hpp" namespace xios { /// ////////////////////// Définitions ////////////////////// /// template void CGroupFactory::AddGroup(std::shared_ptr pgroup, std::shared_ptr cgroup) { if (cgroup.get() == NULL || pgroup.get() == NULL ) ERROR("CGroupFactory::AddGroup(std::shared_ptr pgroup, std::shared_ptr cgroup)", << " pgroup or cgroup NULL !"); if (!cgroup->hasId()) pgroup->groupList.insert(pgroup->groupList.end(), cgroup.get()); else { pgroup->groupList.insert(pgroup->groupList.end(), cgroup.get()); pgroup->groupMap.insert(std::make_pair(cgroup->getId(), cgroup.get())); } } template void CGroupFactory::AddChild(std::shared_ptr group, std::shared_ptr child) { if (group.get() == NULL || child.get() == NULL ) ERROR("CGroupFactory::AddGroup(std::shared_ptr pgroup, std::shared_ptr cgroup)", << " pgroup or cgroup NULL !"); if (!child->hasId()) group->childList.insert(group->childList.end(), child.get()); else { group->childList.insert(group->childList.end(), child.get()); group->childMap.insert(std::make_pair(child->getId(), child.get())); } } template std::shared_ptr CGroupFactory::CreateGroup(std::shared_ptr group, const StdString & id) { CObjectFactory::SetCurrentContextId (CGroupFactory::GetCurrentContextId()); if (id.size() == 0) { std::shared_ptr value = CObjectFactory::CreateObject(CObjectFactory::GenUId()); group->groupList.insert(group->groupList.end(), value.get()); group->groupMap.insert(std::make_pair(value->getId(), value.get())); return (value); } else if (CGroupFactory::HasGroup(group, id)) return (CGroupFactory::GetGroup(group, id)); else { std::shared_ptr value = CObjectFactory::CreateObject(id); group->groupList.insert(group->groupList.end(), value.get()); group->groupMap.insert(std::make_pair(id, value.get())); return (value); } } template std::shared_ptr CGroupFactory::CreateChild(std::shared_ptr group, const StdString & id) { CObjectFactory::SetCurrentContextId (CGroupFactory::GetCurrentContextId()); if (id.size() == 0) { std::shared_ptr value = CObjectFactory::CreateObject(); group->childList.insert(group->childList.end(), value.get()); group->childMap.insert(std::make_pair(value->getId(), value.get())); return (value); } else if (CGroupFactory::HasChild(group, id)) return (CGroupFactory::GetChild(group, id)); else { std::shared_ptr value = CObjectFactory::CreateObject(id); group->childList.insert(group->childList.end(), value.get()); group->childMap.insert(std::make_pair(id, value.get())); return (value); } } template bool CGroupFactory::HasGroup(std::shared_ptr group, const StdString & id) { return (group->groupMap.find(id) != group->groupMap.end()); } template bool CGroupFactory::HasChild(std::shared_ptr group, const StdString & id) { return (group->childMap.find(id) != group->childMap.end()); } template int CGroupFactory::GetGroupNum(std::shared_ptr group) { return (group->groupList.size()); } template int CGroupFactory::GetGroupIdNum(std::shared_ptr group) { return (group->groupMap.size()); } template int CGroupFactory::GetChildNum(std::shared_ptr group) { return (group->childList.size()); } template int CGroupFactory::GetChildIdNum(std::shared_ptr group) { return (group->childMap.size()); } template std::shared_ptr CGroupFactory::GetGroup(std::shared_ptr group, const StdString & id) { if (!CGroupFactory::HasGroup(group, id)) ERROR("CGroupFactory::GetGroup(std::shared_ptr group, const StdString & id)", << "[ id = " << id << ", U = " << U::GetName() << " ] " << " group is not referenced !"); return (group->groupMap[id]->getShared()); } template std::shared_ptr CGroupFactory::GetChild(std::shared_ptr group, const StdString & id) { if (!CGroupFactory::HasChild(group, id)) ERROR("CGroupFactory::GetChild(std::shared_ptr group, const StdString & id)", << "[ id = " << id << ", U = " << U::GetName() << " ] " << " child is not referenced !"); return (group->childMap[id]->getShared()); } } // namespace xios #endif // __XIOS_CGroupFactory_impl__