HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
operator.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include <cstdint>
7#include <limits>
8#include <tuple>
9
10namespace tt {
11
12enum class graphic_character_t {
13 none = 0x00,
14 exclamation_mark = 0x01,
15 double_quote = 0x02,
16 hash = 0x03,
17 dollar = 0x04,
18 percent = 0x05,
19 ampersand = 0x06,
20 single_quote = 0x07,
21 open_paren = 0x08,
22 close_paren = 0x09,
23 star = 0x0a,
24 plus = 0x0b,
25 comma = 0x0c,
26 minus = 0x0d,
27 dot = 0x0e,
28 slash = 0x0f,
29 colon = 0x10,
30 semi_colon = 0x11,
31 less_than = 0x12,
32 equal = 0x13,
33 greater_than = 0x14,
34 question_mark = 0x15,
35 open_bracket = 0x16,
36 back_slash = 0x17,
37 close_bracket = 0x18,
38 carret = 0x19,
39 underscore = 0x1a,
40 back_quote = 0x1b,
41 open_brace = 0x1c,
42 pipe = 0x1d,
43 close_brace = 0x1e,
44 tilde = 0x1f
45};
46
47[[nodiscard]] constexpr graphic_character_t char_to_graphic_character(char x) noexcept
48{
49 switch (x) {
50 case '!': return graphic_character_t::exclamation_mark;
51 case '"': return graphic_character_t::double_quote;
52 case '#': return graphic_character_t::hash;
53 case '$': return graphic_character_t::dollar;
54 case '%': return graphic_character_t::percent;
55 case '&': return graphic_character_t::ampersand;
56 case '\'': return graphic_character_t::single_quote;
57 case '(': return graphic_character_t::open_paren;
58 case ')': return graphic_character_t::close_paren;
59 case '*': return graphic_character_t::star;
60 case '+': return graphic_character_t::plus;
61 case ',': return graphic_character_t::comma;
62 case '-': return graphic_character_t::minus;
63 case '.': return graphic_character_t::dot;
64 case '/': return graphic_character_t::slash;
65 case ':': return graphic_character_t::colon;
66 case ';': return graphic_character_t::semi_colon;
67 case '<': return graphic_character_t::less_than;
68 case '=': return graphic_character_t::equal;
69 case '>': return graphic_character_t::greater_than;
70 case '?': return graphic_character_t::question_mark;
71 case '[': return graphic_character_t::open_bracket;
72 case '\\': return graphic_character_t::back_slash;
73 case ']': return graphic_character_t::close_bracket;
74 case '^': return graphic_character_t::carret;
75 case '_': return graphic_character_t::underscore;
76 case '`': return graphic_character_t::back_quote;
77 case '{': return graphic_character_t::open_brace;
78 case '|': return graphic_character_t::pipe;
79 case '}': return graphic_character_t::close_brace;
80 case '~': return graphic_character_t::tilde;
81 default: return graphic_character_t::none;
82 }
83}
84
85[[nodiscard]] constexpr uint64_t operator_to_int(char const *s) noexcept
86{
87 uint64_t r = 0;
88 for (; *s != '\0'; s++) {
89 r <<= 5;
90 r |= static_cast<uint64_t>(char_to_graphic_character(*s));
91 }
92 return r;
93}
94
95
99[[nodiscard]] std::pair<uint8_t,bool> binary_operator_precedence(char const *str) noexcept {
100 switch (operator_to_int(str)) {
101 case operator_to_int("::"): return {uint8_t{1}, true};
102 case operator_to_int("("): return {uint8_t{2}, true};
103 case operator_to_int("["): return {uint8_t{2}, true};
104 case operator_to_int("."): return {uint8_t{2}, true};
105 case operator_to_int("->"): return {uint8_t{2}, true};
106 case operator_to_int(".*"): return {uint8_t{4}, true};
107 case operator_to_int("->*"): return {uint8_t{4}, true};
108 case operator_to_int("**"): return {uint8_t{4}, true};
109 case operator_to_int("*"): return {uint8_t{5}, true};
110 case operator_to_int("/"): return {uint8_t{5}, true};
111 case operator_to_int("%"): return {uint8_t{5}, true};
112 case operator_to_int("+"): return {uint8_t{6}, true};
113 case operator_to_int("-"): return {uint8_t{6}, true};
114 case operator_to_int("<<"): return {uint8_t{7}, true};
115 case operator_to_int(">>"): return {uint8_t{7}, true};
116 case operator_to_int("<=>"): return {uint8_t{8}, true};
117 case operator_to_int("<"): return {uint8_t{9}, true};
118 case operator_to_int(">"): return {uint8_t{9}, true};
119 case operator_to_int("<="): return {uint8_t{9}, true};
120 case operator_to_int(">="): return {uint8_t{9}, true};
121 case operator_to_int("=="): return {uint8_t{10}, true};
122 case operator_to_int("!="): return {uint8_t{10}, true};
123 case operator_to_int("&"): return {uint8_t{11}, true};
124 case operator_to_int("^"): return {uint8_t{12}, true};
125 case operator_to_int("|"): return {uint8_t{13}, true};
126 case operator_to_int("&&"): return {uint8_t{14}, true};
127 case operator_to_int("||"): return {uint8_t{15}, true};
128 case operator_to_int("?"): return {uint8_t{16}, false};
129 case operator_to_int("="): return {uint8_t{16}, false};
130 case operator_to_int("+="): return {uint8_t{16}, false};
131 case operator_to_int("-="): return {uint8_t{16}, false};
132 case operator_to_int("*="): return {uint8_t{16}, false};
133 case operator_to_int("/="): return {uint8_t{16}, false};
134 case operator_to_int("%="): return {uint8_t{16}, false};
135 case operator_to_int("<<="): return {uint8_t{16}, false};
136 case operator_to_int(">>="): return {uint8_t{16}, false};
137 case operator_to_int("&="): return {uint8_t{16}, false};
138 case operator_to_int("^="): return {uint8_t{16}, false};
139 case operator_to_int("|="): return {uint8_t{16}, false};
140 case operator_to_int(","): return {uint8_t{17}, true};
141 case operator_to_int("]"): return {uint8_t{17}, true};
142 case operator_to_int(")"): return {uint8_t{17}, true};
143 case operator_to_int("!"): return {uint8_t{18}, true};
144 default: return {std::numeric_limits<uint8_t>::max(), true};
145 }
146}
147
151[[nodiscard]] std::pair<uint8_t,bool> operator_precedence(char const *str, bool binary) noexcept {
152 return binary ? binary_operator_precedence(str) : std::pair<uint8_t,bool>{uint8_t{3}, false};
153}
154
155}
STL namespace.
T equal(T... args)
T max(T... args)