AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
PropertyListRecursive.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 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
   24    struct PropertyListConditional;
   25
   26    template<typename T>
   28
   29    struct PropertyListRecursive: public PropertyList {
   30    public:
   31        template<ValidDeclarationOrPropertyList... Declarations>
   32        PropertyListRecursive(Declarations&& ... declarations): PropertyListRecursive() {
   33            processDeclarations(std::forward<Declarations>(declarations)...);
   34        }
   35
   36        PropertyListRecursive(const PropertyListRecursive&);
   37        PropertyListRecursive();
   38        ~PropertyListRecursive();
   39
   40
   41        PropertyListRecursive(const PropertyList& p);
   42        PropertyListRecursive(PropertyList&& p);
   43
   44        [[nodiscard]]
   45        const AVector<PropertyListConditional>& conditionalPropertyLists() const noexcept {
   46            return mConditionalPropertyLists;
   47        }
   48
   49    private:
   50        AVector<PropertyListConditional> mConditionalPropertyLists;
   51
   52        template<typename Property, typename... Declarations>
   53        void processDeclarations(Property&& declaration, Declarations&& ... declarations) {
   54            processDeclaration(std::forward<Property>(declaration));
   55            if constexpr (sizeof...(Declarations) > 0) {
   56                processDeclarations(std::forward<Declarations>(declarations)...);
   57            }
   58        }
   59
   60        template<typename T>
   61        void processDeclaration(T&& t);
   62
   63    };
   64
   65    struct PropertyListConditional {
   66        AAssSelector selector;
   67        PropertyListRecursive list;
   68
   69        template<typename... Declarations>
   70        PropertyListConditional(AAssSelector selector, Declarations&&... declarations):
   71                selector(std::move(selector)), list(std::forward<Declarations>(declarations)...)
   72        {}
   73    };
   74
   75    inline PropertyListRecursive::PropertyListRecursive() = default;
   76    inline PropertyListRecursive::PropertyListRecursive(const PropertyList& p) : PropertyList(p) {}
   77    inline PropertyListRecursive::PropertyListRecursive(PropertyList&& p) : PropertyList(std::move(p)) {}
   78    inline PropertyListRecursive::PropertyListRecursive(const PropertyListRecursive&) = default;
   79    inline PropertyListRecursive::~PropertyListRecursive() = default;
   80
   81
   82    template<typename T>
   83    void PropertyListRecursive::processDeclaration(T&& t) {
   84        if constexpr (std::is_base_of_v<PropertyListConditional, T>) {
   85            mConditionalPropertyLists << std::forward<PropertyListConditional&&>(t);
   86        } else if constexpr (std::is_same_v<T, PropertyListRecursive>) {
   87            // aka move constructor
   88            mProperties = std::move(t.mProperties);
   89            mConditionalPropertyLists = std::move(t.mConditionalPropertyLists);
   90        } else {
   91            using declaration_t = ass::prop::Property<std::decay_t<T>>;
   92            static_assert(aui::is_complete<declaration_t>,
   93                          "ass::prop::Property template specialization is not defined for this property");
   94
   95            mProperties << _new<declaration_t>(t);
   96        }
   97    }
   98}
A std::vector with AUI extensions.
Definition AVector.h:39
Definition AAssSelector.h:36
Definition PropertyListRecursive.h:27
Definition PropertyList.h:26
Definition concepts.h:25
type_of< T > t
Selects views that are of the specified C++ types.
Definition type_of.h:71
constexpr bool is_complete
Determines whether T is complete or not.
Definition types.h:23
Definition PropertyListRecursive.h:65
Definition PropertyListRecursive.h:29
Definition PropertyList.h:28