~aleteoryx/muditaos

ref: a702bbd17cd005d236aa1a227c561df12c8f9184 muditaos/module-apps/application-calculator/data/CalculatorInputProcessor.hpp -rw-r--r-- 1.8 KiB
a702bbd1 — Artur Śleszyński [EGD-6561] Make calculator input testable 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
52
53
54
// 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 <utf8/UTF8.hpp>

namespace gui
{
    class InputEvent;
}

namespace calc
{
    namespace symbols
    {
        namespace codes
        {
            inline constexpr auto plus           = 0x002B;
            inline constexpr auto minus          = 0x002D;
            inline constexpr auto division       = 0x00F7;
            inline constexpr auto multiplication = 0x00D7;
            inline constexpr auto full_stop      = 0x002E;
            inline constexpr auto comma          = 0x002C;
            inline constexpr auto equals         = 0x003D;
            inline constexpr auto zero           = 0x0030;
        } // namespace codes

        namespace strings
        {
            inline constexpr auto plus           = "\u002B";
            inline constexpr auto minus          = "\u002D";
            inline constexpr auto division       = "\u00F7";
            inline constexpr auto multiplication = "\u00D7";
            inline constexpr auto equals         = "\u003D";
            inline constexpr auto full_stop      = "\u002E";
            inline constexpr auto comma          = "\u002C";
            inline constexpr auto asterisk       = "\u002A";
            inline constexpr auto solidus        = "\u002F";
        } // namespace strings
    }     // namespace symbols

    class InputProcessor
    {
      public:
        virtual ~InputProcessor() = default;

        virtual bool handle(const gui::InputEvent &event) = 0;
        virtual void clear()                              = 0;

        static bool isSymbol(std::uint32_t code);
        static bool isDecimalSeparator(std::uint32_t c);
    };
} // namespace calc