PMT Renovated main
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
definations.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Yağız Zengin
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24#ifndef LIBHELPER_MACROS_HPP
25#define LIBHELPER_MACROS_HPP
26
27#include <concepts>
28#include <unistd.h>
29
31inline constexpr mode_t DEFAULT_FILE_PERMS = 0644;
32
34inline constexpr mode_t DEFAULT_EXTENDED_FILE_PERMS = 0755;
35
37inline constexpr mode_t DEFAULT_DIR_PERMS = 0755;
38
40inline constexpr int YES = 1;
41
43inline constexpr int NO = 0;
44
46enum sizeCastTypes { B = static_cast<int>('B'), KB = static_cast<int>('K'), MB = static_cast<int>('M'), GB = static_cast<int>('G') };
47
52namespace Helper {
53
59template <typename T>
60concept HasCStrFunction = requires(T v) {
61 { v.c_str() } -> std::constructible_from<char *>;
62};
63
71template <typename Func, typename Ret, typename... Args>
72concept Invocable = std::invocable<Func, Args...> && std::same_as<std::invoke_result_t<Func, Args...>, Ret>;
73
85template <typename T> struct DeepConst {
87};
88
90template <typename T> struct DeepConst<T *> {
91 using type = const T *;
92};
104template <typename T> using DeepConst_t = DeepConst<T>::type;
105
117template <typename T> struct ConstIfCharPointer {
118 using type = T;
119};
120
123template <> struct ConstIfCharPointer<char *> {
124 using type = const char *;
125};
126
128template <> struct ConstIfCharPointer<const char *> {
129 using type = const char *;
130};
143template <typename T> using ConstIfCharPointer_t = ConstIfCharPointer<T>::type;
144
145} // namespace Helper
146
148#define HELPER "libhelper"
149
159#define B(x) (static_cast<uint64_t(x)> * 8)
160
170#define KB(x) (static_cast<uint64_t>(x) * 1024)
171
181#define MB(x) (KB(x) * 1024)
182
192#define GB(x) (MB(x) * 1024)
193
203#define TO_KB(x) (x / 1024)
204
214#define TO_MB(x) (TO_KB(x) / 1024)
215
225#define TO_GB(x) (TO_MB(x) / 1024)
226
232#define STYLE_RESET "\033[0m"
233#define BOLD "\033[1m"
234#define FAINT "\033[2m"
235#define ITALIC "\033[3m"
236#define UNDERLINE "\033[4m"
237#define BLINC "\033[5m"
238#define FAST_BLINC "\033[6m"
239#define STRIKE_THROUGHT "\033[9m"
240#define NO_UNDERLINE "\033[24m"
241#define NO_BLINC "\033[25m"
250// Foreground (text) colors
251#define BLACK "\033[30m"
252#define RED "\033[31m"
253#define GREEN "\033[32m"
254#define YELLOW "\033[33m"
255#define BLUE "\033[34m"
256#define MAGENTA "\033[35m"
257#define CYAN "\033[36m"
258#define WHITE "\033[37m"
259
260// Bright roreground colors
261#define BRIGHT_BLACK "\033[90m"
262#define BRIGHT_RED "\033[91m"
263#define BRIGHT_GREEN "\033[92m"
264#define BRIGHT_YELLOW "\033[93m"
265#define BRIGHT_BLUE "\033[94m"
266#define BRIGHT_MAGENTA "\033[95m"
267#define BRIGHT_CYAN "\033[96m"
268#define BRIGHT_WHITE "\033[97m"
269
270// Background colors
271#define BG_BLACK "\033[40m"
272#define BG_RED "\033[41m"
273#define BG_GREEN "\033[42m"
274#define BG_YELLOW "\033[43m"
275#define BG_BLUE "\033[44m"
276#define BG_MAGENTA "\033[45m"
277#define BG_CYAN "\033[46m"
278#define BG_WHITE "\033[47m"
281#ifndef HELPER_NO_C_TYPE_HANDLERS
282// ABORT(message), ex: ABORT("memory error!\n")
283#define ABORT(msg) \
284 do { \
285 fprintf(stderr, "%s%sCRITICAL ERROR%s: %s\nAborting...\n", BOLD, RED, STYLE_RESET, msg); \
286 abort(); \
287 } while (0)
288
289// ERROR(message, exit), ex: ERROR("an error occured.\n", 1)
290#define ERROR(msg, code) \
291 do { \
292 fprintf(stderr, "%s%sERROR%s: %s", BOLD, RED, STYLE_RESET, msg); \
293 exit(code); \
294 } while (0)
295
296// WARNING(message), ex: WARNING("using default setting.\n")
297#define WARNING(msg) fprintf(stderr, "%s%sWARNING%s: %s", BOLD, YELLOW, STYLE_RESET, msg);
298
299// INFO(message), ex: INFO("operation ended.\n")
300#define INFO(msg) fprintf(stdout, "%s%sINFO%s: %s", BOLD, GREEN, STYLE_RESET, msg);
301#endif // #ifndef HELPER_NO_C_TYPE_HANDLERS
302
313#define MKVERSION(name) \
314 char vinfo[512]; \
315 sprintf(vinfo, \
316 "%s %s-%s [%s %s]\nBuild type: %s\nCMake version: %s\nCompiler version: " \
317 "%s\nCompiler flags: %s", \
318 name, BUILD_VERSION, COMMIT_ID, BUILD_DATE, BUILD_TIME, BUILD_TYPE, BUILD_CMAKE_VERSION, BUILD_COMPILER_VERSION, \
319 BUILD_FLAGS); \
320 return std::string(vinfo)
321
322#endif // #ifndef LIBHELPER_MACROS_HPP
Checks whether the input type provides a c_str() member function.
Definition definations.hpp:60
Checks whether the input is invocable and returns requested type.
Definition definations.hpp:72
T forward(T... args)
constexpr mode_t DEFAULT_FILE_PERMS
Default file permissions.
Definition definations.hpp:31
#define MB(x)
Take x megabyte as bytes.
Definition definations.hpp:181
constexpr int YES
Alternative of true.
Definition definations.hpp:40
#define KB(x)
Take x kilobyte as bytes.
Definition definations.hpp:170
constexpr mode_t DEFAULT_EXTENDED_FILE_PERMS
Extended file permissions (using by executables etc).
Definition definations.hpp:34
#define B(x)
Take x byte as bits.
Definition definations.hpp:159
constexpr int NO
Alternative of false.
Definition definations.hpp:43
constexpr mode_t DEFAULT_DIR_PERMS
Default directory permissions.
Definition definations.hpp:37
sizeCastTypes
Short names used in dimension type conversions.
Definition definations.hpp:46
#define GB(x)
Take x gigabyte as bytes.
Definition definations.hpp:192
Main namespace of libhelper library.
Definition capsule.hpp:27
Add the const qualifier if input type is char*.
Definition definations.hpp:117
ConstIfCharPointer< T >::type ConstIfCharPointer_t
Shorcut of ConstIfCharPointer<T>::type.
Definition definations.hpp:143
Add the const qualifier to the input type.
Definition definations.hpp:85