~aleteoryx/muditaos

ref: 060a472d479fb012252511e88c1eabd4ff4b5fb9 muditaos/module-services/service-appmgr/service-appmgr/model/ApplicationStack.hpp -rw-r--r-- 2.0 KiB
060a472d — Mateusz Grzegorzek [BH-663] Fix CMake in service-antenna 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <deque>
#include <string>
#include <vector>

namespace app::manager
{
    using ApplicationName = std::string;
    class ApplicationStack
    {
      public:
        struct Item
        {
            ApplicationName appName;
            bool isCloseable;
        };
        using Container = std::deque<Item>;

        void push(Item &&item);
        void pop();
        void eraseFirstOf(const ApplicationName &appName) noexcept;
        void clear();

        [[nodiscard]] auto unique() const noexcept -> std::vector<ApplicationName>;
        [[nodiscard]] auto isEmpty() const noexcept -> bool;
        [[nodiscard]] auto size() const noexcept -> Container::size_type;
        [[nodiscard]] auto front() noexcept -> Item &;
        [[nodiscard]] auto front() const noexcept -> const Item &;
        [[nodiscard]] auto find(const ApplicationName &appName) const -> std::vector<Item>;
        [[nodiscard]] auto contains(const ApplicationName &appName) const noexcept -> bool;
        [[nodiscard]] auto getIndexOf(const ApplicationName &appName) const noexcept -> int;
        [[nodiscard]] auto begin() -> Container::iterator;
        [[nodiscard]] auto begin() const -> Container::const_iterator;
        [[nodiscard]] auto end() -> Container::iterator;
        [[nodiscard]] auto end() const -> Container::const_iterator;
        [[nodiscard]] auto operator[](int index) -> Item &;
        [[nodiscard]] auto operator[](int index) const -> const Item &;

      private:
        Container stack;
    };

    bool operator==(const ApplicationStack::Item &lhs, const ApplicationStack::Item &rhs) noexcept;
    bool operator!=(const ApplicationStack::Item &lhs, const ApplicationStack::Item &rhs) noexcept;
    bool operator<(const ApplicationStack::Item &lhs, const ApplicationStack::Item &rhs) noexcept;
    bool operator>(const ApplicationStack::Item &lhs, const ApplicationStack::Item &rhs) noexcept;
} // namespace app::manager