Define basic type aliases and useful functions/macros for use throughout the system
This commit is contained in:
53
src/base.hpp
Normal file
53
src/base.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/* base.hpp: Basic definitions
|
||||
* Created: 2025-11-27
|
||||
* Author: Aryadev Chavali
|
||||
* License: See end of file
|
||||
* Commentary:
|
||||
*/
|
||||
|
||||
#ifndef BASE_HPP
|
||||
#define BASE_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
#define MAX(A, B) ((B) < (A) ? (A) : (B))
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
|
||||
static_assert(sizeof(float) == 4, "f32 requires 4 byte floats");
|
||||
static_assert(sizeof(double) == 8, "f64 requires 8 byte doubles");
|
||||
using f32 = float;
|
||||
using f64 = double;
|
||||
|
||||
using index_t = i64;
|
||||
|
||||
inline bool index_has_value(index_t i)
|
||||
{
|
||||
return i >= 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Copyright (C) 2025 Aryadev Chavali
|
||||
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for
|
||||
* details.
|
||||
|
||||
* You may distribute and modify this code under the terms of the GNU General
|
||||
* Public License Version 2, which you should have received a copy of along with
|
||||
* this program. If not, please go to <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user