13 template<std::derived_from<rtti_pure_base> base_component_t>
14 typename components<base_component_t>::SClassData& components<base_component_t>::SClassData::get_or_add_class_data(
15 class_identificator
id) noexcept
17 if (
const auto it = derivedClasses.find(
id); it != derivedClasses.end())
18 return *it->second.get();
20 auto pClassData = std::make_unique<SClassData>();
21 auto pRawClassData = pClassData.get();
22 derivedClasses[id] = std::move(pClassData);
23 return *pRawClassData;
26 template<std::derived_from<rtti_pure_base> base_component_t>
27 template<std::derived_from<base_component_t> component_t>
29 std::unique_ptr<component_t> pComponent,
36 auto pRawComponent = pComponent.get();
37 SClassData& classData = get_or_add_class_data(
39 [ePriority, statusFlags, pRawComponent](SClassData& classData)
43 classData.components.push_back(std::move(pComponent));
47 template<std::derived_from<rtti_pure_base> base_component_t>
53 SClassData& classData = get_or_add_class_data(
55 [pRawComponent](SClassData& classData)
58 classData.priorityCache,
59 [pRawComponent](
const auto& pair)
61 return pair.second.pComponent == pRawComponent;
65 const auto it = std::ranges::find_if(
67 [pRawComponent](
const pointer_type& pointer)
69 return pointer.get() == pRawComponent;
72 if (it == classData.components.end())
75 std::unique_ptr<base_component_t> pComponent = std::move(*it);
76 classData.components.erase(it);
80 template<std::derived_from<rtti_pure_base> base_component_t>
81 template<std::derived_from<base_component_t> component_t>
84 SClassData& classData = get_or_add_class_data<component_t>();
85 const auto it = std::ranges::find_if(
86 classData.priorityCache,
89 return !pair.second.statusFlags.contains(status::disabled);
92 return it != classData.priorityCache.end() ?
static_cast<component_t*
>(it->second.pComponent) :
nullptr;
95 template<std::derived_from<rtti_pure_base> base_component_t>
96 template<std::derived_from<base_component_t> component_t>
99 return QX_CONST_CAST_THIS()->template try_get<component_t>();
102 template<std::derived_from<rtti_pure_base> base_component_t>
107 const auto it = std::ranges::find_if(
108 m_RootClass.priorityCache,
109 [
id](
const auto& pair)
111 return !pair.second.statusFlags.contains(status::disabled)
112 && pair.second.pComponent->is_derived_from_id(id);
115 return it != m_RootClass.priorityCache.end() ? it->second.pComponent :
nullptr;
118 template<std::derived_from<rtti_pure_base> base_component_t>
121 return QX_CONST_CAST_THIS()->try_get(
id);
124 template<std::derived_from<rtti_pure_base> base_component_t>
125 template<std::derived_from<base_component_t> component_t>
128 SClassData& classData = get_or_add_class_data<component_t>();
129 const auto it = std::ranges::find_if(
130 classData.priorityCache,
133 return !pair.second.statusFlags.contains(status::disabled);
136 return *
static_cast<component_t*
>(it->second.pComponent);
139 template<std::derived_from<rtti_pure_base> base_component_t>
140 template<std::derived_from<base_component_t> component_t>
143 return QX_CONST_CAST_THIS()->template get<component_t>();
146 template<std::derived_from<rtti_pure_base> base_component_t>
147 template<std::derived_from<base_component_t> component_t>
150 SClassData& classData = get_or_add_class_data<component_t>();
151 return classData.priorityCache
152 | std::views::filter(
155 return pair.second.pComponent->template is_derived_from<component_t>()
156 && !pair.second.statusFlags.contains(status::disabled);
158 | std::views::transform(
159 [](
auto& pair) -> component_t&
161 return *
static_cast<component_t*
>(pair.second.pComponent);
165 template<std::derived_from<rtti_pure_base> base_component_t>
166 template<std::derived_from<base_component_t> component_t>
169 const SClassData& classData = get_or_add_class_data<component_t>();
170 return classData.priorityCache
171 | std::views::filter(
174 return pair.second.pComponent->template is_derived_from<component_t>()
175 && !pair.second.statusFlags.contains(status::disabled);
177 | std::views::transform(
178 [](
const auto& pair) ->
const component_t&
180 return *
static_cast<const component_t*
>(pair.second.pComponent);
184 template<std::derived_from<rtti_pure_base> base_component_t>
190 auto it = std::ranges::find_if(
191 m_RootClass.priorityCache,
192 [pRawComponent](
const auto& pair)
194 return pair.second.pComponent == pRawComponent;
197 return it != m_RootClass.priorityCache.end() ? std::optional<priority>(it->first) : std::nullopt;
201 template<std::derived_from<rtti_pure_base> base_component_t>
207 bool bChanged =
true;
208 get_or_add_class_data(
210 [pRawComponent, ePriority, &bChanged](SClassData& classData)
212 const auto it = std::ranges::find_if(
213 classData.priorityCache,
214 [pRawComponent](
const auto& pair)
216 return pair.second.pComponent == pRawComponent;
219 if (it == classData.priorityCache.end())
225 if (it->first != ePriority)
227 classData.priorityCache.emplace(ePriority, it->second);
228 classData.priorityCache.erase(it);
235 template<std::derived_from<rtti_pure_base> base_component_t>
237 const base_component_t* pRawComponent)
const noexcept
242 auto it = std::ranges::find_if(
243 m_RootClass.priorityCache,
244 [pRawComponent](
const auto& pair)
246 return pair.second.pComponent == pRawComponent;
249 return it != m_RootClass.priorityCache.end() ? std::optional<flags<status>>(it->second.statusFlags) : std::nullopt;
253 template<std::derived_from<rtti_pure_base> base_component_t>
259 bool bChanged =
true;
260 get_or_add_class_data(
262 [pRawComponent, status, &bChanged](SClassData& classData)
264 const auto it = std::ranges::find_if(
265 classData.priorityCache,
266 [pRawComponent](
const auto& pair)
268 return pair.second.pComponent == pRawComponent;
271 if (it == classData.priorityCache.end())
277 it->second.statusFlags = status;
283 template<std::derived_from<rtti_pure_base> base_component_t>
286 return m_RootClass.priorityCache.empty();
289 template<std::derived_from<rtti_pure_base> base_component_t>
292 m_RootClass.derivedClasses.clear();
293 m_RootClass.components.clear();
294 m_RootClass.priorityCache.clear();
component_t * add(std::unique_ptr< component_t > pComponent, priority ePriority=priority::normal, flags< status > statusFlags=status::default_value) noexcept
Add a component.
std::unique_ptr< base_component_t > remove(const base_component_t *pRawComponent) noexcept
Remove the component from the container.
bool set_priority(const base_component_t *pRawComponent, priority ePriority) noexcept
Set a priority of a given component.
component_t * try_get() noexcept
Try to get a component of the given type with the highest priority.
std::optional< priority > get_priority(const base_component_t *pRawComponent) const noexcept
Get a priority of a given component.
void clear() noexcept
Clear the container, e.g. remove all the components.
auto view() noexcept
Get a view which may be used in a ranged-based for loop and consists of components of a given type wi...
bool empty() const noexcept
Check if container doesn't have any components.
std::optional< flags< status > > get_status(const base_component_t *pRawComponent) const noexcept
Get a status of a given component.
component_t & get() noexcept
Get a component of the given type with the highest priority (no existence checks are performed)
bool set_status(const base_component_t *pRawComponent, flags< status > status) noexcept
Set a status of a given component.
priority
User may use the predefined values or the custom ones, for ex. "normal - 1", this type is supposed to...