Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/common/aligned_allocator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include "common/types.h"
#include "common/macros.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/bits.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <algorithm>
#include <limits>
Expand Down
2 changes: 2 additions & 0 deletions code/common/clock.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#if defined(_WIN32)
#include <Windows.h>
#elif defined(__linux__)
Expand Down
2 changes: 2 additions & 0 deletions code/common/clock.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <string_view>

Expand Down
2 changes: 2 additions & 0 deletions code/common/console.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#ifdef _WIN32
#include <Windows.h>
#endif
Expand Down
2 changes: 2 additions & 0 deletions code/common/console.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <fmt/core.h>
#include "common/strings.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/console_logger.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#include <chrono>
#include "common/log.h"
#include "common/debug.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/console_logger.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once

namespace common::log::console_logger
Expand Down
2 changes: 2 additions & 0 deletions code/common/constants.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once

#include <limits>
Expand Down
2 changes: 2 additions & 0 deletions code/common/data_stream.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#include "common/log.h"
#include "common/debug.h"
#include "common/macros.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/data_stream.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <memory>
#include <string_view>
Expand Down
2 changes: 2 additions & 0 deletions code/common/debug.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#include <vector>
#include <limits>

Expand Down
2 changes: 2 additions & 0 deletions code/common/debug.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <array>

Expand Down
2 changes: 2 additions & 0 deletions code/common/dictionary.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <utility> // std::pair
#include <algorithm> // std::find_if
Expand Down
2 changes: 2 additions & 0 deletions code/common/dynamic_library.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#if defined(_WIN32)
#include <wil/resource.h>
#elif defined(__linux__)
Expand Down
2 changes: 2 additions & 0 deletions code/common/dynamic_library.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <string_view>
#include <memory>
Expand Down
2 changes: 2 additions & 0 deletions code/common/file_helpers.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#include "common/file_helpers.h"
#include "common/debug.h"

Expand Down
2 changes: 2 additions & 0 deletions code/common/file_helpers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <cstdio>
#include "common/types.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/helpers.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include "common/types.h"

Expand Down
2 changes: 2 additions & 0 deletions code/common/log.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#include <limits>

#include "common/log.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/log.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <functional>
#include <optional>
Expand Down
2 changes: 2 additions & 0 deletions code/common/macros.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once

#include "common/helpers.h"
Expand Down
2 changes: 2 additions & 0 deletions code/common/math.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <numbers>

Expand Down
2 changes: 2 additions & 0 deletions code/common/platform.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once

namespace common
Expand Down
2 changes: 2 additions & 0 deletions code/common/result.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <variant>

Expand Down
2 changes: 2 additions & 0 deletions code/common/scoped_function.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <concepts>
#include <optional>
Expand Down
2 changes: 2 additions & 0 deletions code/common/strings.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#if defined(_WIN32)
#include <Windows.h>
#elif defined(__linux__)
Expand Down
2 changes: 2 additions & 0 deletions code/common/strings.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once

#include <optional>
Expand Down
2 changes: 2 additions & 0 deletions code/common/synchro.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#if defined(_WIN32)
#include <Windows.h>
#elif defined(__linux__)
Expand Down
2 changes: 2 additions & 0 deletions code/common/synchro.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <string_view>
#include <thread>
Expand Down
56 changes: 49 additions & 7 deletions code/common/types.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// SPDX-License-Identifier: MIT

#pragma once
#include <array>
#include <cstdint>
#include <cstddef>

// unsigned
// unsigned integer
using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
Expand All @@ -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;
Expand All @@ -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<typename underlying_type>
requires std::is_unsigned_v<underlying_type>
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<type>(val);

return value_;
}

constexpr explicit operator bool() const
{
return static_cast<bool>(value_);
}

constexpr bool operator =(bool val)
{
return set(val);
}

template<typename other>
static constexpr portable_bool<type> from(other val)
{
return portable_bool<type>{static_cast<bool>(val)};
}

type value_{ 0 };
};

// boolean
using b8 = portable_bool<u8>;
using b16 = portable_bool<u16>;
using b32 = portable_bool<u32>;
using b64 = portable_bool<u64>;

// floating point
using f32 = float;
Expand Down
1 change: 1 addition & 0 deletions test/common-test/common-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ItemGroup>
<ClCompile Include="aligned-allocator-test.cc" />
<ClCompile Include="dictionary-test.cc" />
<ClCompile Include="portable_bool.cc" />
<ClCompile Include="string-test.cc" />
<ClCompile Include="vector-comparison-tests.cc" />
<ClCompile Include="vector-math-tests.cc" />
Expand Down
30 changes: 30 additions & 0 deletions test/common-test/portable_bool.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <gtest/gtest.h>

#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);
}