diff --git a/code/common/aligned_allocator.h b/code/common/aligned_allocator.h index 72160d06..36491473 100644 --- a/code/common/aligned_allocator.h +++ b/code/common/aligned_allocator.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include "common/types.h" #include "common/macros.h" diff --git a/code/common/bits.h b/code/common/bits.h index e6f33008..09a0eb2f 100644 --- a/code/common/bits.h +++ b/code/common/bits.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include diff --git a/code/common/clock.cc b/code/common/clock.cc index fffd919e..ef0450e4 100644 --- a/code/common/clock.cc +++ b/code/common/clock.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #if defined(_WIN32) #include #elif defined(__linux__) diff --git a/code/common/clock.h b/code/common/clock.h index d7f8931b..7812f72f 100644 --- a/code/common/clock.h +++ b/code/common/clock.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include diff --git a/code/common/console.cc b/code/common/console.cc index 40faba22..f9fedd65 100644 --- a/code/common/console.cc +++ b/code/common/console.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #ifdef _WIN32 #include #endif diff --git a/code/common/console.h b/code/common/console.h index 811d1f5b..2bd58061 100644 --- a/code/common/console.h +++ b/code/common/console.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include "common/strings.h" diff --git a/code/common/console_logger.cc b/code/common/console_logger.cc index 512b9dce..c7eb585e 100644 --- a/code/common/console_logger.cc +++ b/code/common/console_logger.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #include #include "common/log.h" #include "common/debug.h" diff --git a/code/common/console_logger.h b/code/common/console_logger.h index d408cd59..572bf7a0 100644 --- a/code/common/console_logger.h +++ b/code/common/console_logger.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once namespace common::log::console_logger diff --git a/code/common/constants.h b/code/common/constants.h index caf3cc53..64d1ea07 100644 --- a/code/common/constants.h +++ b/code/common/constants.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include diff --git a/code/common/data_stream.cc b/code/common/data_stream.cc index 5778affc..489ab1eb 100644 --- a/code/common/data_stream.cc +++ b/code/common/data_stream.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #include "common/log.h" #include "common/debug.h" #include "common/macros.h" diff --git a/code/common/data_stream.h b/code/common/data_stream.h index e547e2d8..b64cf8fa 100644 --- a/code/common/data_stream.h +++ b/code/common/data_stream.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include diff --git a/code/common/debug.cc b/code/common/debug.cc index 3fb3021f..769b56ad 100644 --- a/code/common/debug.cc +++ b/code/common/debug.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #include #include diff --git a/code/common/debug.h b/code/common/debug.h index 5b104129..fae67350 100644 --- a/code/common/debug.h +++ b/code/common/debug.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include diff --git a/code/common/dictionary.h b/code/common/dictionary.h index 0e0a11fd..fbceb272 100644 --- a/code/common/dictionary.h +++ b/code/common/dictionary.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include // std::pair #include // std::find_if diff --git a/code/common/dynamic_library.cc b/code/common/dynamic_library.cc index cbdba304..438c233a 100644 --- a/code/common/dynamic_library.cc +++ b/code/common/dynamic_library.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #if defined(_WIN32) #include #elif defined(__linux__) diff --git a/code/common/dynamic_library.h b/code/common/dynamic_library.h index d14a3904..26aac458 100644 --- a/code/common/dynamic_library.h +++ b/code/common/dynamic_library.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include diff --git a/code/common/file_helpers.cc b/code/common/file_helpers.cc index 5386cc7d..3b31ac83 100644 --- a/code/common/file_helpers.cc +++ b/code/common/file_helpers.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #include "common/file_helpers.h" #include "common/debug.h" diff --git a/code/common/file_helpers.h b/code/common/file_helpers.h index 3bce4385..719fc5be 100644 --- a/code/common/file_helpers.h +++ b/code/common/file_helpers.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include "common/types.h" diff --git a/code/common/helpers.h b/code/common/helpers.h index ac86a34f..60ff5ee9 100644 --- a/code/common/helpers.h +++ b/code/common/helpers.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include "common/types.h" diff --git a/code/common/log.cc b/code/common/log.cc index 06831472..4505128b 100644 --- a/code/common/log.cc +++ b/code/common/log.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #include #include "common/log.h" diff --git a/code/common/log.h b/code/common/log.h index 714ca6b8..835a6d86 100644 --- a/code/common/log.h +++ b/code/common/log.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include diff --git a/code/common/macros.h b/code/common/macros.h index f43dd4fd..270e543c 100644 --- a/code/common/macros.h +++ b/code/common/macros.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include "common/helpers.h" diff --git a/code/common/math.h b/code/common/math.h index 61db92aa..3313fbc8 100644 --- a/code/common/math.h +++ b/code/common/math.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include diff --git a/code/common/platform.h b/code/common/platform.h index fc9af3c4..c848efae 100644 --- a/code/common/platform.h +++ b/code/common/platform.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once namespace common diff --git a/code/common/result.h b/code/common/result.h index 7f740139..6cc1b480 100644 --- a/code/common/result.h +++ b/code/common/result.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include diff --git a/code/common/scoped_function.h b/code/common/scoped_function.h index 4b54be06..ce06077d 100644 --- a/code/common/scoped_function.h +++ b/code/common/scoped_function.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include diff --git a/code/common/strings.cc b/code/common/strings.cc index ce6242da..48516d86 100644 --- a/code/common/strings.cc +++ b/code/common/strings.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #if defined(_WIN32) #include #elif defined(__linux__) diff --git a/code/common/strings.h b/code/common/strings.h index d667a64d..2be33385 100644 --- a/code/common/strings.h +++ b/code/common/strings.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include diff --git a/code/common/synchro.cc b/code/common/synchro.cc index f7de141e..b38b9efa 100644 --- a/code/common/synchro.cc +++ b/code/common/synchro.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #if defined(_WIN32) #include #elif defined(__linux__) diff --git a/code/common/synchro.h b/code/common/synchro.h index fbb2e115..e26b20fa 100644 --- a/code/common/synchro.h +++ b/code/common/synchro.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include diff --git a/code/common/types.h b/code/common/types.h index 86f57b2d..4181cae4 100644 --- a/code/common/types.h +++ b/code/common/types.h @@ -1,9 +1,11 @@ +// SPDX-License-Identifier: MIT + #pragma once #include #include #include -// unsigned +// unsigned integer using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; @@ -16,7 +18,7 @@ using ullong = unsigned long long; using usize = std::size_t; using uptr = std::uintptr_t; -// signed +// signed integer using s8 = std::int8_t; using s16 = std::int16_t; using s32 = std::int32_t; @@ -25,11 +27,51 @@ using schar = signed char; using sint = signed int; using ssize = std::intmax_t; -// bool -using b8 = u8; -using b16 = u16; -using b32 = u32; -using b64 = u64; +// wrapper for bools of a defined size +template +requires std::is_unsigned_v +struct portable_bool +{ + using type = underlying_type; + + constexpr portable_bool() = default; + + constexpr portable_bool(bool init) + { + set(init); + } + + constexpr bool set(const bool val) + { + value_ = static_cast(val); + + return value_; + } + + constexpr explicit operator bool() const + { + return static_cast(value_); + } + + constexpr bool operator =(bool val) + { + return set(val); + } + + template + static constexpr portable_bool from(other val) + { + return portable_bool{static_cast(val)}; + } + + type value_{ 0 }; +}; + +// boolean +using b8 = portable_bool; +using b16 = portable_bool; +using b32 = portable_bool; +using b64 = portable_bool; // floating point using f32 = float; diff --git a/test/common-test/common-test.vcxproj b/test/common-test/common-test.vcxproj index 79bb4fea..feb8d6cb 100644 --- a/test/common-test/common-test.vcxproj +++ b/test/common-test/common-test.vcxproj @@ -12,6 +12,7 @@ + diff --git a/test/common-test/portable_bool.cc b/test/common-test/portable_bool.cc new file mode 100644 index 00000000..38f1ef7e --- /dev/null +++ b/test/common-test/portable_bool.cc @@ -0,0 +1,30 @@ +#include + +#include "common/types.h" + +TEST(PortableBool, ShouldConvertToBool) +{ + b8 val0 = true; + EXPECT_TRUE(val0); + + val0 = false; + EXPECT_FALSE(val0); + + b16 val1 = true; + EXPECT_TRUE(val1); + + val1 = false; + EXPECT_FALSE(val1); + + b32 val2 = true; + EXPECT_TRUE(val2); + + val2 = false; + EXPECT_FALSE(val2); + + b64 val3 = true; + EXPECT_TRUE(val3); + + val3 = false; + EXPECT_FALSE(val3); +} \ No newline at end of file