PIDUINO
Loading...
Searching...
No Matches
global.h
1/* Copyright © 2018-2025 Pascal JEAN, All rights reserved.
2 This file is part of the Piduino Library.
3
4 The Piduino Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 3 of the License, or (at your option) any later version.
8
9 The Piduino Library 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 GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with the Piduino Library; if not, see <http://www.gnu.org/licenses/>.
16*/
17#pragma once
18
19#include <memory>
20#include <string>
21#include <iostream>
22#include <stdlib.h>
23#include <cstdint>
24#include <cstddef>
25#include <sys/types.h>
26
33#ifdef DOXYGEN
49#define PIMP_D(Class)
50
66#define PIMP_Q(Class)
67
82#define PIMP_DECLARE_PRIVATE(Class)
83
98#define PIMP_DECLARE_PUBLIC(Class)
99#else
100
101#ifndef BIT
102#define BIT(n) (1UL << (n))
103#endif
104
105#ifdef __FILE_NAME__
106#define EXCEPTION_MSG(m) std::string{} + __FILE_NAME__ + "(" + std::to_string(__LINE__) + "): [" + __func__ +"] " + m
107#else
108#define EXCEPTION_MSG(m) std::string{} + __FILE__ + "(" + std::to_string(__LINE__) + "): [" + __func__ +"] " + m
109#endif
110
111namespace Piduino {
112 static inline void Assert (const char *expr_str, bool expr, const char *file, int line, const std::string msg) {
113 if (!expr) {
114 std::cerr << std::endl
115 << "---------->>>" << std::endl
116 << "Assert failed:\t" << msg << std::endl
117 << "Expected:\t" << expr_str << std::endl
118 << "Source:\t\t" << file << ":" << line << std::endl
119 << "----------<<<" << std::endl;
120 abort();
121 }
122 }
123} // namespace Piduino
124
125#ifndef NDEBUG
126# define M_Assert(Expr, Msg) \
127 Piduino::Assert(#Expr, Expr, __FILE__, __LINE__, Msg)
128#else
129# define M_Assert(Expr, Msg) ;
130#endif
131
132// ---------------------------------------------------------
133// PIMP_D
134#define PIMP_D(Class) Class::Private * const d = d_func()
135#define PIMP_Q(Class) Class * const q = q_func()
136#define PIMP_DECLARE_PRIVATE(Class)\
137 inline Class::Private* d_func() {\
138 return reinterpret_cast<Class::Private*>(d_ptr.get());\
139 }\
140 inline const Class::Private* d_func() const {\
141 return reinterpret_cast<const Class::Private *>(d_ptr.get());\
142 }\
143 friend class Class::Private;
144#define PIMP_DECLARE_PUBLIC(Class) \
145 inline Class* q_func() { return reinterpret_cast<Class *>(q_ptr); } \
146 inline const Class* q_func() const { return reinterpret_cast<const Class *>(q_ptr); } \
147 friend class Class;
148// ---------------------------------------------------------
149#endif
150
154namespace Piduino {
155}
156
161/* ========================================================================== */
Global namespace for Piduino.
Definition board.h:28