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>(CObjectFactory::GenUId<U>()); |
---|
49 | group->groupList.insert(group->groupList.end(), value); |
---|
50 | group->groupMap.insert(std::make_pair(value->getId(), value)); |
---|
51 | return (value); |
---|
52 | } |
---|
53 | else if (CGroupFactory::HasGroup(group, id)) |
---|
54 | return (CGroupFactory::GetGroup(group, id)); |
---|
55 | else |
---|
56 | { |
---|
57 | boost::shared_ptr<U> value = CObjectFactory::CreateObject<U>(id); |
---|
58 | group->groupList.insert(group->groupList.end(), value); |
---|
59 | group->groupMap.insert(std::make_pair(id, value)); |
---|
60 | return (value); |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | template <typename U> |
---|
65 | boost::shared_ptr<typename U::RelChild> |
---|
66 | CGroupFactory::CreateChild(boost::shared_ptr<U> group, const StdString & id) |
---|
67 | { |
---|
68 | CObjectFactory::SetCurrentContextId |
---|
69 | (CGroupFactory::GetCurrentContextId()); |
---|
70 | if (id.size() == 0) |
---|
71 | { |
---|
72 | boost::shared_ptr<typename U::RelChild> value = |
---|
73 | CObjectFactory::CreateObject<typename U::RelChild>(); |
---|
74 | group->childList.insert(group->childList.end(), value); |
---|
75 | group->childMap.insert(std::make_pair(value->getId(), value)); |
---|
76 | return (value); |
---|
77 | } |
---|
78 | else if (CGroupFactory::HasChild(group, id)) |
---|
79 | return (CGroupFactory::GetChild(group, id)); |
---|
80 | else |
---|
81 | { |
---|
82 | boost::shared_ptr<typename U::RelChild> value = |
---|
83 | CObjectFactory::CreateObject<typename U::RelChild>(id); |
---|
84 | group->childList.insert(group->childList.end(), value); |
---|
85 | group->childMap.insert(std::make_pair(id, value)); |
---|
86 | return (value); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | template <typename U> |
---|
91 | bool CGroupFactory::HasGroup(boost::shared_ptr<U> group, const StdString & id) |
---|
92 | { return (group->groupMap.find(id) != group->groupMap.end()); } |
---|
93 | |
---|
94 | template <typename U> |
---|
95 | bool CGroupFactory::HasChild(boost::shared_ptr<U> group, const StdString & id) |
---|
96 | { return (group->childMap.find(id) != group->childMap.end()); } |
---|
97 | |
---|
98 | template <typename U> |
---|
99 | int CGroupFactory::GetGroupNum(boost::shared_ptr<U> group) |
---|
100 | { return (group->groupList.size()); } |
---|
101 | |
---|
102 | template <typename U> |
---|
103 | int CGroupFactory::GetGroupIdNum(boost::shared_ptr<U> group) |
---|
104 | { return (group->groupMap.size()); } |
---|
105 | |
---|
106 | template <typename U> |
---|
107 | int CGroupFactory::GetChildNum(boost::shared_ptr<U> group) |
---|
108 | { return (group->childList.size()); } |
---|
109 | |
---|
110 | template <typename U> |
---|
111 | int CGroupFactory::GetChildIdNum(boost::shared_ptr<U> group) |
---|
112 | { return (group->childMap.size()); } |
---|
113 | |
---|
114 | template <typename U> |
---|
115 | boost::shared_ptr<U> |
---|
116 | CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id) |
---|
117 | { |
---|
118 | if (!CGroupFactory::HasGroup<U>(group, id)) |
---|
119 | ERROR("CGroupFactory::GetGroup(boost::shared_ptr<U> group, const StdString & id)", |
---|
120 | << "[ id = " << id << ", U = " << U::GetName() << " ] " |
---|
121 | << " group is not referenced !"); |
---|
122 | return (group->groupMap[id]); |
---|
123 | } |
---|
124 | |
---|
125 | template <typename U> |
---|
126 | boost::shared_ptr<typename U::RelChild> |
---|
127 | CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id) |
---|
128 | { |
---|
129 | if (!CGroupFactory::HasChild<U>(group, id)) |
---|
130 | ERROR("CGroupFactory::GetChild(boost::shared_ptr<U> group, const StdString & id)", |
---|
131 | << "[ id = " << id << ", U = " << U::GetName() << " ] " |
---|
132 | << " child is not referenced !"); |
---|
133 | return (group->childMap[id]); |
---|
134 | } |
---|
135 | |
---|
136 | } // namespace xmlioserver |
---|
137 | |
---|
138 | #endif // __XMLIO_CGroupFactory_impl__ |
---|