AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AQueue.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#pragma once
   13#include <queue>
   14#include <AUI/Core.h>
   15#include <AUI/Traits/containers.h>
   16
   17
   22template <class StoredType>
   23class AQueue : public std::queue<StoredType>
   24{
   25    using super = std::queue<StoredType>;
   26public:
   31    void removeAll(const StoredType& item) noexcept
   32    {
   33        aui::container::remove_all(*this, item);
   34    }
   35
   40    void removeFirst(const StoredType& item) noexcept
   41    {
   42        aui::container::remove_first(*this, item);
   43    }
   44
   45
   46    AQueue<StoredType>& operator<<(const StoredType& rhs)
   47    {
   48        super::push(rhs);
   49        return *this;
   50    }
   51
   52
   53    AQueue<StoredType>& operator<<(StoredType&& rhs)
   54    {
   55        super::push(std::move(rhs));
   56        return *this;
   57    }
   58
   62    bool contains(const StoredType& value) const noexcept {
   63        return aui::container::contains(*this, value);
   64    }
   65
   66
   70    template<typename OtherContainer>
   71    bool isSubsetOf(const OtherContainer& c) const noexcept
   72    {
   73        return aui::container::is_subset(*this, c);
   74    }
   75
   81    template<typename Factory>
   82    [[nodiscard]]
   83    StoredType popOrGenerate(Factory factory) noexcept(noexcept(factory())) {
   84        if (super::empty()) {
   85            return factory();
   86        }
   87        auto v = std::move(super::front());
   88        super::pop();
   89        return v;
   90    }
   91};
A std::queue with AUI extensions.
Definition AQueue.h:24
void removeFirst(const StoredType &item) noexcept
Definition AQueue.h:40
StoredType popOrGenerate(Factory factory) noexcept(noexcept(factory()))
Pops the element and returns it. If queue is empty, the result of factory() returned....
Definition AQueue.h:83
void removeAll(const StoredType &item) noexcept
Definition AQueue.h:31
bool contains(const StoredType &value) const noexcept
Definition AQueue.h:62
bool isSubsetOf(const OtherContainer &c) const noexcept
Definition AQueue.h:71
Definition Factory.h:18
bool is_subset(LContainer &l, RContainer &r) noexcept
Definition containers.h:205
bool contains(const Container &c, const typename Container::const_reference value) noexcept
Definition containers.h:124
AOptional< std::size_t > remove_first(Container &container, typename Container::const_reference value) noexcept
Removes first occurrence of value.
Definition containers.h:172
void remove_all(Container &container, typename Container::const_reference value) noexcept
Removes all occurrences of value.
Definition containers.h:143