[152] | 1 | #ifndef __XMLIO_CGroupFactory_impl__ |
---|
| 2 | #define __XMLIO_CGroupFactory_impl__ |
---|
| 3 | |
---|
| 4 | namespace xmlioserver |
---|
| 5 | { |
---|
| 6 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 7 | |
---|
| 8 | template <typename U> |
---|
| 9 | void CGroupFactory::AddGroup(boost::shared_ptr<U> pgroup, |
---|
| 10 | boost::shared_ptr<U> cgroup) |
---|
| 11 | { |
---|
| 12 | if (cgroup.get() == NULL || pgroup.get() == NULL ) |
---|
| 13 | ERROR("CGroupFactory::AddGroup(boost::shared_ptr<U> pgroup, boost::shared_ptr<U> cgroup)", |
---|
| 14 | << " pgroup or cgroup NULL !"); |
---|
| 15 | if (!cgroup->hasId()) |
---|
| 16 | pgroup->groupList.insert(pgroup->groupList.end(), cgroup); |
---|
| 17 | else |
---|
| 18 | { |
---|
| 19 | pgroup->groupList.insert(pgroup->groupList.end(), cgroup); |
---|
| 20 | pgroup->groupMap.insert(std::make_pair(cgroup->getId(), cgroup)); |
---|
| 21 | } |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | template <typename U> |
---|
| 25 | void CGroupFactory::AddChild(boost::shared_ptr<U> group, |
---|
| 26 | boost::shared_ptr<typename U::RelChild> child) |
---|
| 27 | { |
---|
| 28 | if (group.get() == NULL || child.get() == NULL ) |
---|
| 29 | ERROR("CGroupFactory::AddGroup(boost::shared_ptr<U> pgroup, boost::shared_ptr<U> cgroup)", |
---|
| 30 | << " pgroup or cgroup NULL !"); |
---|
| 31 | if (!child->hasId()) |
---|
| 32 | group->childList.insert(group->childList.end(), child); |
---|
| 33 | else |
---|
| 34 | { |
---|
| 35 | group->childList.insert(group->childList.end(), child); |
---|
| 36 | group->childMap.insert(std::make_pair(child->getId(), child)); |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | template <typename U> |
---|
| 41 | boost::shared_ptr<U> |
---|
| 42 | CGroupFactory::CreateGroup(boost::shared_ptr<U> group, const StdString & id) |
---|
| 43 | { |
---|
| 44 | CObjectFactory::SetCurrentContextId |
---|
| 45 | (CGroupFactory::GetCurrentContextId()); |
---|
| 46 | if (id.size() == 0) |
---|
| 47 | { |
---|
| 48 | boost::shared_ptr<U> value = CObjectFactory::CreateObject<U>(); |
---|
| 49 | group->groupList.insert(group->groupList.end(), value); |
---|
| 50 | return (value); |
---|
| 51 | } |
---|
| 52 | else if (CGroupFactory::HasGroup(group, id)) |
---|
| 53 | return (CGroupFactory::GetGroup(group, id)); |
---|
| 54 | else |
---|
| 55 | { |
---|
| 56 | boost::shared_ptr<U> value = CObjectFactory::CreateObject<U>(id); |
---|
| 57 | group->groupList.insert(group->groupList.end(), value); |
---|
| 58 | group->groupMap.insert(std::make_pair(id, value)); |
---|
| 59 | return (value); |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | template <typename U> |
---|
| 64 | boost::shared_ptr<typename U::RelChild> |
---|
| 65 | CGroupFactory::CreateChild(boost::shared_ptr<U> group, const StdString & id) |
---|
| 66 | { |
---|
| 67 | CObjectFactory::SetCurrentContextId |
---|
| 68 | (CGroupFactory::GetCurrentContextId()); |
---|
| 69 | if (id.size() == 0) |
---|
| 70 | { |
---|
| 71 | boost::shared_ptr<typename U::RelChild> value = |
---|
| 72 | CObjectFactory::CreateObject<typename U::RelChild>(); |
---|
| 73 | group->childList.insert(group->childList.end(), value); |
---|
| 74 | return (value); |
---|
| 75 | } |
---|
| 76 | else if (CGroupFactory::HasChild(group, id)) |
---|
| 77 | return (CGroupFactory::GetChild(group, id)); |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | boost::shared_ptr<typename U::RelChild> value = |
---|
| 81 | CObjectFactory::CreateObject<typename U::RelChild>(id); |
---|
| 82 | group->childList.insert(group->childList.end(), value); |
---|
| 83 | group->childMap.insert(std::make_pair(id, value)); |
---|
| 84 | return (value); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | template <typename U> |
---|
| 89 | bool CGroupFactory::HasGroup(boost::shared_ptr<U> group, const StdString & id) |
---|
| 90 | { return (group->groupMap.find(id) != group->groupMap.end()); } |
---|
| 91 | |
---|
| 92 | template <typename U> |
---|
| 93 | bool CGroupFactory::HasChild(boost::shared_ptr<U> group, const StdString & id) |
---|
| 94 | { return (group->childMap.find(id) != group->childMap.end()); } |
---|
| 95 | |
---|
| 96 | template <typename U> |
---|
| 97 | int CGroupFactory::GetGroupNum(boost::shared_ptr<U> group) |
---|
| 98 | { return (group->groupList.size()); } |
---|
| 99 | |
---|
| 100 | template <typename U> |
---|
| 101 | int CGroupFactory::GetGroupIdNum(boost::shared_ptr<U> group) |
---|
| 102 | { return (group->groupMap.size()); } |
---|
| 103 | |
---|
| 104 | template <typename U> |
---|
| 105 | int CGroupFactory::GetChildNum(boost::shared_ptr<U> group) |
---|
| 106 | { return (group->childList.size()); } |
---|
| 107 | |
---|
| 108 | template <typename U> |
---|
| 109 | int CGroupFactory::GetChildIdNum(boost::shared_ptr<U> group) |
---|
| 110 | { return (group->childMap.size()); } |
---|
| 111 | |
---|
| 112 | template <typename U> |
---|
| 113 | boost::shared_ptr<U> |
---|
| 114 | CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id) |
---|
| 115 | { |
---|
| 116 | if (!CGroupFactory::HasGroup<U>(group, id)) |
---|
| 117 | ERROR("CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id)", |
---|
| 118 | << "[ id = " << id << ", U = " << U::GetName() << " ] " |
---|
| 119 | << " group is not referenced !"); |
---|
| 120 | return (group->groupMap[id]); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | template <typename U> |
---|
| 124 | boost::shared_ptr<typename U::RelChild> |
---|
| 125 | CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id) |
---|
| 126 | { |
---|
| 127 | if (!CGroupFactory::HasChild<U>(group, id)) |
---|
| 128 | ERROR("CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id)", |
---|
| 129 | << "[ id = " << id << ", U = " << U::GetName() << " ] " |
---|
| 130 | << " child is not referenced !"); |
---|
| 131 | return (group->childMap[id]); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | } // namespace xmlioserver |
---|
| 135 | |
---|
| 136 | #endif // __XMLIO_CGroupFactory_impl__ |
---|