AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
PropertyListRecursive.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12//
13// Created by alex2 on 03.01.2021.
14//
15
16#pragma once
17
18#include "PropertyList.h"
19#include "AUI/ASS/Selector/AAssSelector.h"
20
21
22namespace ass {
23
25 public:
27
28 template<typename... Declarations>
29 PropertyListRecursive(Declarations&& ... declarations): PropertyListRecursive() {
30 processDeclarations(std::forward<Declarations>(declarations)...);
31 }
32
36
37
40
41 [[nodiscard]]
42 const AVector<ConditionalPropertyList>& conditionalPropertyLists() const noexcept {
43 return mConditionalPropertyLists;
44 }
45
46 private:
47 AVector<ConditionalPropertyList> mConditionalPropertyLists;
48
49 template<typename Property, typename... Declarations>
50 void processDeclarations(Property&& declaration, Declarations&& ... declarations) {
51 processDeclaration(std::forward<Property>(declaration));
52 if constexpr (sizeof...(Declarations) > 0) {
53 processDeclarations(std::forward<Declarations>(declarations)...);
54 }
55 }
56
57 template<typename T>
58 void processDeclaration(T&& t);
59
60 };
61
63 AAssSelector selector;
65
66 template<typename... Declarations>
67 ConditionalPropertyList(AAssSelector selector, Declarations&&... declarations):
68 selector(std::move(selector)), list(std::forward<Declarations>(declarations)...)
69 {}
70 };
71
72 inline PropertyListRecursive::PropertyListRecursive() = default;
73 inline PropertyListRecursive::PropertyListRecursive(const PropertyList& p) : PropertyList(p) {}
74 inline PropertyListRecursive::PropertyListRecursive(PropertyList&& p) : PropertyList(std::move(p)) {}
75 inline PropertyListRecursive::PropertyListRecursive(const PropertyListRecursive&) = default;
76 inline PropertyListRecursive::~PropertyListRecursive() = default;
77
78
79 template<typename T>
80 void PropertyListRecursive::processDeclaration(T&& t) {
81 if constexpr (std::is_base_of_v<PropertyListRecursive::ConditionalPropertyList, T>) {
82 mConditionalPropertyLists << std::forward<ConditionalPropertyList&&>(t);
83 } else if constexpr (std::is_same_v<T, PropertyListRecursive>) {
84 // aka move constructor
85 mProperties = std::move(t.mProperties);
86 mConditionalPropertyLists = std::move(t.mConditionalPropertyLists);
87 } else {
88 using declaration_t = ass::prop::Property<std::decay_t<T>>;
89 static_assert(aui::is_complete<declaration_t>,
90 "ass::prop::Property template specialization is not defined for this property");
91
92 mProperties << _new<declaration_t>(t);
93 }
94 }
95}
A std::vector with AUI extensions.
Definition: AVector.h:38
Definition: AAssSelector.h:36
Definition: PropertyListRecursive.h:62
Definition: PropertyListRecursive.h:24
Definition: PropertyList.h:25
Definition: IProperty.h:19
Definition: type_of.h:44