CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
DataTypes.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include <cstddef>
11#include <cstdint>
12#include <type_traits>
13
14namespace CeresEngine {
15 using Int8 = std::int8_t;
16 using SInt8 = std::int8_t;
17 using UInt8 = std::uint8_t;
18 using Int16 = std::int16_t;
19 using SInt16 = std::int16_t;
20 using UInt16 = std::uint16_t;
21 using Int32 = std::int32_t;
22 using SInt32 = std::int32_t;
23 using UInt32 = std::uint32_t;
24 using Int64 = std::int64_t;
25 using SInt64 = std::int64_t;
26 using UInt64 = std::uint64_t;
27
28 using Int = Int32;
29 using SInt = Int32;
30 using UInt = UInt32;
31
32 using Float = float;
33 using Double = double;
34
35 using Bool = bool;
36
37#if defined(__cpp_lib_byte)
38 using Byte = std::byte;
39#else
40 enum class Byte : unsigned char {
41 };
42
43 template<class _IntType, std::enable_if_t<std::is_integral_v<_IntType>, int> = 0>
44 [[nodiscard]] constexpr Byte operator<<(const Byte arg,
45 const _IntType shift) noexcept { // bitwise LEFT SHIFT, every
46 // static_cast is intentional
47 return static_cast<Byte>(static_cast<unsigned char>(static_cast<unsigned int>(arg) << shift));
48 }
49
50 template<class _IntType, std::enable_if_t<std::is_integral_v<_IntType>, int> = 0>
51 [[nodiscard]] constexpr Byte operator>>(const Byte arg,
52 const _IntType shift) noexcept { // bitwise RIGHT SHIFT, every
53 // static_cast is intentional
54 return static_cast<Byte>(static_cast<unsigned char>(static_cast<unsigned int>(arg) >> shift));
55 }
56
57 [[nodiscard]] constexpr Byte operator|(const Byte left,
58 const Byte right) noexcept { // bitwise OR, every static_cast is
59 // intentional
60 return static_cast<Byte>(static_cast<unsigned char>(static_cast<unsigned int>(left) | static_cast<unsigned int>(right)));
61 }
62
63 [[nodiscard]] constexpr Byte operator&(const Byte left,
64 const Byte right) noexcept { // bitwise AND, every static_cast is
65 // intentional
66 return static_cast<Byte>(static_cast<unsigned char>(static_cast<unsigned int>(left) & static_cast<unsigned int>(right)));
67 }
68
69 [[nodiscard]] constexpr Byte operator^(const Byte left,
70 const Byte right) noexcept { // bitwise XOR, every static_cast is
71 // intentional
72 return static_cast<Byte>(static_cast<unsigned char>(static_cast<unsigned int>(left) ^ static_cast<unsigned int>(right)));
73 }
74
75 [[nodiscard]] constexpr Byte operator~(const Byte arg) noexcept { // bitwise NOT, every static_cast is
76 // intentional
77 return static_cast<Byte>(static_cast<unsigned char>(~static_cast<unsigned int>(arg)));
78 }
79
80 template<class _IntType, std::enable_if_t<std::is_integral_v<_IntType>, int> = 0>
81 constexpr Byte& operator<<=(Byte& arg, const _IntType shift) noexcept { // bitwise LEFT SHIFT
82 return arg = arg << shift;
83 }
84
85 template<class _IntType, std::enable_if_t<std::is_integral_v<_IntType>, int> = 0>
86 constexpr Byte& operator>>=(Byte& arg, const _IntType shift) noexcept { // bitwise RIGHT SHIFT
87 return arg = arg >> shift;
88 }
89
90 constexpr Byte& operator|=(Byte& left, const Byte right) noexcept { // bitwise OR
91 return left = left | right;
92 }
93
94 constexpr Byte& operator&=(Byte& left, const Byte right) noexcept { // bitwise AND
95 return left = left & right;
96 }
97
98 constexpr Byte& operator^=(Byte& left, const Byte right) noexcept { // bitwise XOR
99 return left = left ^ right;
100 }
101
102 template<class _IntType, std::enable_if_t<std::is_integral_v<_IntType>, int> = 0>
103 [[nodiscard]] constexpr _IntType to_integer(const Byte arg) noexcept { // convert byte to integer
104 return static_cast<_IntType>(arg);
105 }
106#endif
107} // namespace CeresEngine
Definition Application.hpp:19
constexpr Byte operator>>(const Byte arg, const _IntType shift) noexcept
Definition DataTypes.hpp:51
Byte
Definition DataTypes.hpp:40
Int32 SInt
Definition DataTypes.hpp:29
std::uint64_t UInt64
Definition DataTypes.hpp:26
constexpr Byte operator^(const Byte left, const Byte right) noexcept
Definition DataTypes.hpp:69
std::int64_t SInt64
Definition DataTypes.hpp:25
constexpr Byte & operator^=(Byte &left, const Byte right) noexcept
Definition DataTypes.hpp:98
std::int16_t SInt16
Definition DataTypes.hpp:19
Int32 Int
Definition DataTypes.hpp:28
constexpr Byte operator<<(const Byte arg, const _IntType shift) noexcept
Definition DataTypes.hpp:44
UInt32 UInt
Definition DataTypes.hpp:30
constexpr Byte operator~(const Byte arg) noexcept
Definition DataTypes.hpp:75
std::int32_t Int32
Definition DataTypes.hpp:21
std::uint16_t UInt16
Definition DataTypes.hpp:20
constexpr Byte & operator>>=(Byte &arg, const _IntType shift) noexcept
Definition DataTypes.hpp:86
bool Bool
Definition DataTypes.hpp:35
std::uint8_t UInt8
Definition DataTypes.hpp:17
std::int32_t SInt32
Definition DataTypes.hpp:22
constexpr Byte & operator|=(Byte &left, const Byte right) noexcept
Definition DataTypes.hpp:90
std::int8_t SInt8
Definition DataTypes.hpp:16
std::int64_t Int64
Definition DataTypes.hpp:24
constexpr Byte operator|(const Byte left, const Byte right) noexcept
Definition DataTypes.hpp:57
constexpr Byte & operator<<=(Byte &arg, const _IntType shift) noexcept
Definition DataTypes.hpp:81
constexpr _IntType to_integer(const Byte arg) noexcept
Definition DataTypes.hpp:103
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr Byte operator&(const Byte left, const Byte right) noexcept
Definition DataTypes.hpp:63
float Float
Definition DataTypes.hpp:32
std::int8_t Int8
Definition DataTypes.hpp:15
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::int16_t Int16
Definition DataTypes.hpp:18
constexpr Byte & operator&=(Byte &left, const Byte right) noexcept
Definition DataTypes.hpp:94
double Double
Definition DataTypes.hpp:33