Added clang-tidy config and cleaned up the code a little.
This commit is contained in:
parent
9f011952c2
commit
6d111904d4
73
.clang-tidy
Normal file
73
.clang-tidy
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
Checks: '*,
|
||||||
|
-abseil-*,
|
||||||
|
-altera-*,
|
||||||
|
-android-*,
|
||||||
|
-boost-*,
|
||||||
|
-darwin-*,
|
||||||
|
-fuchsia-*,
|
||||||
|
-google-*,
|
||||||
|
-hicpp-*,
|
||||||
|
-linuxkernel-*,
|
||||||
|
-llvm-*,
|
||||||
|
-llvmlibc-*,
|
||||||
|
-mpi-*,
|
||||||
|
-objc-*,
|
||||||
|
-zircon-*,
|
||||||
|
|
||||||
|
-bugprone-easily-swappable-parameters,
|
||||||
|
-bugprone-exception-escape,
|
||||||
|
-bugprone-unhandled-exception-at-new,
|
||||||
|
-cert-dcl21-cpp,
|
||||||
|
-cert-err58-cpp,
|
||||||
|
-cppcoreguidelines-avoid-capturing-lambda-coroutines,
|
||||||
|
-cppcoreguidelines-avoid-const-or-ref-data-members,
|
||||||
|
-cppcoreguidelines-avoid-do-while,
|
||||||
|
-cppcoreguidelines-avoid-reference-coroutine-parameters,
|
||||||
|
-cppcoreguidelines-avoid-magic-numbers,
|
||||||
|
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||||
|
-cppcoreguidelines-macro-usage,
|
||||||
|
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||||
|
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||||
|
-cppcoreguidelines-pro-bounds-constant-array-index,
|
||||||
|
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||||
|
-cppcoreguidelines-pro-type-member-init,
|
||||||
|
-cppcoreguidelines-pro-type-reinterpret-cast,
|
||||||
|
-cppcoreguidelines-pro-type-static-cast-downcast,
|
||||||
|
-cppcoreguidelines-pro-type-union-access,
|
||||||
|
-cppcoreguidelines-pro-type-vararg,
|
||||||
|
-cppcoreguidelines-special-member-functions,
|
||||||
|
-modernize-macro-to-enum,
|
||||||
|
-misc-include-cleaner,
|
||||||
|
-misc-no-recursion,
|
||||||
|
-misc-non-private-member-variables-in-classes,
|
||||||
|
-misc-use-anonymous-namespace,
|
||||||
|
-modernize-return-braced-init-list,
|
||||||
|
-modernize-use-auto,
|
||||||
|
-modernize-use-trailing-return-type,
|
||||||
|
-portability-simd-intrinsics,
|
||||||
|
-readability-avoid-unconditional-preprocessor-if,
|
||||||
|
-readability-container-data-pointer,
|
||||||
|
-readability-convert-member-functions-to-static,
|
||||||
|
-readability-implicit-bool-conversion,
|
||||||
|
-readability-isolate-declaration,
|
||||||
|
-readability-magic-numbers,
|
||||||
|
-readability-named-parameter,
|
||||||
|
-readability-redundant-access-specifiers,
|
||||||
|
-readability-uppercase-literal-suffix,
|
||||||
|
-readability-use-anyofallof'
|
||||||
|
|
||||||
|
CheckOptions:
|
||||||
|
- key: readability-identifier-length.IgnoredParameterNames
|
||||||
|
value: '^[xyz]$'
|
||||||
|
- key: readability-identifier-length.IgnoredLoopCounterNames
|
||||||
|
value: '^[xyz]$'
|
||||||
|
- key: readability-identifier-length.IgnoredVariableNames
|
||||||
|
value: '(it|NO)'
|
||||||
|
- key: readability-function-cognitive-complexity.Threshold
|
||||||
|
value: 50
|
||||||
|
|
||||||
|
WarningsAsErrors: '*'
|
||||||
|
|
||||||
|
HeaderFilterRegex: 'source/*.hpp$'
|
||||||
|
|
||||||
|
UseColor: false
|
@ -53,7 +53,7 @@ public:
|
|||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
~BoxedObject()
|
~BoxedObject()
|
||||||
{
|
{
|
||||||
MIJIN_ASSERT(!constructed, "BoxedObject::~BoxedObject(): Object has not been destroyed prior to destructor!")
|
MIJIN_ASSERT(!constructed, "BoxedObject::~BoxedObject(): Object has not been destroyed prior to destructor!");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ public:
|
|||||||
void construct(TArgs&&... args)
|
void construct(TArgs&&... args)
|
||||||
{
|
{
|
||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
MIJIN_ASSERT(!constructed, "BoxedObject::construct(): Attempt to construct an already constructed object!")
|
MIJIN_ASSERT(!constructed, "BoxedObject::construct(): Attempt to construct an already constructed object!");
|
||||||
constructed = true;
|
constructed = true;
|
||||||
#endif
|
#endif
|
||||||
std::construct_at(&object_, std::forward<TArgs>(args)...);
|
std::construct_at(&object_, std::forward<TArgs>(args)...);
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
void destroy()
|
void destroy()
|
||||||
{
|
{
|
||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
MIJIN_ASSERT(constructed, "BoxedObject::destroy(): Attempt to destroy a not constructed object!")
|
MIJIN_ASSERT(constructed, "BoxedObject::destroy(): Attempt to destroy a not constructed object!");
|
||||||
constructed = false;
|
constructed = false;
|
||||||
#endif
|
#endif
|
||||||
std::destroy_at(&object_);
|
std::destroy_at(&object_);
|
||||||
@ -87,7 +87,7 @@ public:
|
|||||||
void copyTo(BoxedObject& other) const
|
void copyTo(BoxedObject& other) const
|
||||||
{
|
{
|
||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
MIJIN_ASSERT(constructed, "BoxedObject::copy(): Attempt to copy a not constructed object!")
|
MIJIN_ASSERT(constructed, "BoxedObject::copy(): Attempt to copy a not constructed object!");
|
||||||
#endif
|
#endif
|
||||||
other.construct(object_);
|
other.construct(object_);
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ public:
|
|||||||
void moveTo(BoxedObject& other)
|
void moveTo(BoxedObject& other)
|
||||||
{
|
{
|
||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
MIJIN_ASSERT(constructed, "BoxedObject::copy(): Attempt to copy a not constructed object!")
|
MIJIN_ASSERT(constructed, "BoxedObject::copy(): Attempt to copy a not constructed object!");
|
||||||
#endif
|
#endif
|
||||||
other.construct(std::move(object_));
|
other.construct(std::move(object_));
|
||||||
destroy();
|
destroy();
|
||||||
@ -104,7 +104,7 @@ public:
|
|||||||
[[nodiscard]] T& get()
|
[[nodiscard]] T& get()
|
||||||
{
|
{
|
||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
MIJIN_ASSERT(constructed, "BoxedObject::get(): Attempt to access a not constructed object!")
|
MIJIN_ASSERT(constructed, "BoxedObject::get(): Attempt to access a not constructed object!");
|
||||||
#endif
|
#endif
|
||||||
return object_;
|
return object_;
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ public:
|
|||||||
[[nodiscard]] const T& get() const
|
[[nodiscard]] const T& get() const
|
||||||
{
|
{
|
||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
MIJIN_ASSERT(constructed, "BoxedObject::get(): Attempt to access a not constructed object!")
|
MIJIN_ASSERT(constructed, "BoxedObject::get(): Attempt to access a not constructed object!");
|
||||||
#endif
|
#endif
|
||||||
return object_;
|
return object_;
|
||||||
}
|
}
|
||||||
|
@ -58,30 +58,33 @@ MIJIN_ERROR(msg) \
|
|||||||
std::abort()
|
std::abort()
|
||||||
|
|
||||||
// TODO: make ignoreAll work (static variables cannot be used in constexpr functions)
|
// TODO: make ignoreAll work (static variables cannot be used in constexpr functions)
|
||||||
#define MIJIN_ASSERT(condition, msg) \
|
#define MIJIN_ASSERT(condition, msg) \
|
||||||
if (!static_cast<bool>(condition)) \
|
do \
|
||||||
{ \
|
{ \
|
||||||
/* static bool ignoreAll = false; */ \
|
if (!static_cast<bool>(condition)) \
|
||||||
if (true) /*!ignoreAll */ \
|
{ \
|
||||||
{ \
|
/* static bool ignoreAll = false; */ \
|
||||||
const mijin::AssertionResult assertion_result__ = mijin::handleAssert( \
|
if (true) /*!ignoreAll */ \
|
||||||
#condition, msg, std::source_location::current()); \
|
{ \
|
||||||
switch (assertion_result__) \
|
const mijin::AssertionResult assertion_result__ = mijin::handleAssert( \
|
||||||
{ \
|
#condition, msg, std::source_location::current()); \
|
||||||
case mijin::AssertionResult::ABORT: \
|
switch (assertion_result__) \
|
||||||
std::abort(); \
|
{ \
|
||||||
break; \
|
case mijin::AssertionResult::ABORT: \
|
||||||
case mijin::AssertionResult::IGNORE: \
|
std::abort(); \
|
||||||
/*break*/; \
|
break; \
|
||||||
case mijin::AssertionResult::IGNORE_ALL: \
|
case mijin::AssertionResult::IGNORE: \
|
||||||
/* ignoreAll = true; */ \
|
/*break*/; \
|
||||||
break; \
|
case mijin::AssertionResult::IGNORE_ALL: \
|
||||||
default: /* ERROR */ \
|
/* ignoreAll = true; */ \
|
||||||
MIJIN_ERROR("Debug assertion failed: " #condition "\nMessage: " msg); \
|
break; \
|
||||||
break; \
|
default: /* ERROR */ \
|
||||||
} \
|
MIJIN_ERROR("Debug assertion failed: " #condition "\nMessage: " msg); \
|
||||||
} \
|
break; \
|
||||||
}
|
} \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while(false)
|
||||||
|
|
||||||
#define MIJIN_ASSERT_FATAL(condition, msg) \
|
#define MIJIN_ASSERT_FATAL(condition, msg) \
|
||||||
if (!static_cast<bool>(condition)) \
|
if (!static_cast<bool>(condition)) \
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace mijin
|
namespace mijin
|
||||||
@ -327,25 +326,25 @@ StreamError FileStream::open(const char* path, FileOpenMode mode_)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int result = std::fseek(handle, 0, SEEK_END);
|
int result = std::fseek(handle, 0, SEEK_END);
|
||||||
assert(result == 0);
|
MIJIN_ASSERT(result == 0, "fseek failed.");
|
||||||
length = std::ftell(handle);
|
length = std::ftell(handle);
|
||||||
result = std::fseek(handle, 0, SEEK_SET);
|
result = std::fseek(handle, 0, SEEK_SET);
|
||||||
assert(result == 0);
|
MIJIN_ASSERT(result == 0, "fseek failed.");
|
||||||
|
|
||||||
return StreamError::SUCCESS;
|
return StreamError::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileStream::close()
|
void FileStream::close()
|
||||||
{
|
{
|
||||||
assert(handle);
|
MIJIN_ASSERT(handle != nullptr, "FileStream is not open.");
|
||||||
const int result = std::fclose(handle); // NOLINT(cppcoreguidelines-owning-memory)
|
const int result = std::fclose(handle); // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
assert(result == 0);
|
MIJIN_ASSERT(result == 0, "fclose failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamError FileStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
StreamError FileStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
||||||
{
|
{
|
||||||
assert(handle);
|
MIJIN_ASSERT(handle != nullptr, "FileStream is not open.");
|
||||||
assert(mode == FileOpenMode::READ || mode == FileOpenMode::READ_WRITE);
|
MIJIN_ASSERT(mode == FileOpenMode::READ || mode == FileOpenMode::READ_WRITE, "Cannot read from this stream");
|
||||||
|
|
||||||
const std::size_t readBytes = std::fread(buffer.data(), 1, buffer.size(), handle);
|
const std::size_t readBytes = std::fread(buffer.data(), 1, buffer.size(), handle);
|
||||||
if (std::ferror(handle)) {
|
if (std::ferror(handle)) {
|
||||||
@ -369,8 +368,9 @@ StreamError FileStream::readRaw(std::span<std::uint8_t> buffer, const ReadOption
|
|||||||
|
|
||||||
StreamError FileStream::writeRaw(std::span<const std::uint8_t> buffer)
|
StreamError FileStream::writeRaw(std::span<const std::uint8_t> buffer)
|
||||||
{
|
{
|
||||||
assert(handle);
|
MIJIN_ASSERT(handle != nullptr, "FileStream is not open.");
|
||||||
assert(mode == FileOpenMode::WRITE || mode == FileOpenMode::APPEND || mode == FileOpenMode::READ_WRITE);
|
MIJIN_ASSERT(mode == FileOpenMode::WRITE || mode == FileOpenMode::READ_WRITE || mode == FileOpenMode::APPEND,
|
||||||
|
"Cannot write to this stream");
|
||||||
|
|
||||||
const std::size_t written = std::fwrite(buffer.data(), 1, buffer.size(), handle);
|
const std::size_t written = std::fwrite(buffer.data(), 1, buffer.size(), handle);
|
||||||
if (written != buffer.size() || std::ferror(handle)) {
|
if (written != buffer.size() || std::ferror(handle)) {
|
||||||
@ -383,15 +383,13 @@ StreamError FileStream::writeRaw(std::span<const std::uint8_t> buffer)
|
|||||||
|
|
||||||
std::size_t FileStream::tell()
|
std::size_t FileStream::tell()
|
||||||
{
|
{
|
||||||
assert(handle);
|
MIJIN_ASSERT(handle != nullptr, "FileStream is not open.");
|
||||||
|
|
||||||
return std::ftell(handle);
|
return std::ftell(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamError FileStream::seek(std::intptr_t pos, SeekMode seekMode)
|
StreamError FileStream::seek(std::intptr_t pos, SeekMode seekMode)
|
||||||
{
|
{
|
||||||
assert(handle);
|
MIJIN_ASSERT(handle != nullptr, "FileStream is not open.");
|
||||||
|
|
||||||
int origin; // NOLINT(cppcoreguidelines-init-variables)
|
int origin; // NOLINT(cppcoreguidelines-init-variables)
|
||||||
switch (seekMode)
|
switch (seekMode)
|
||||||
{
|
{
|
||||||
@ -405,7 +403,7 @@ StreamError FileStream::seek(std::intptr_t pos, SeekMode seekMode)
|
|||||||
origin = SEEK_END;
|
origin = SEEK_END;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"Invalid value passed as seekMode!");
|
MIJIN_ERROR("Invalid value passed as seekMode!");
|
||||||
return StreamError::UNKNOWN_ERROR;
|
return StreamError::UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
const int result = std::fseek(handle, static_cast<long>(pos), origin);
|
const int result = std::fseek(handle, static_cast<long>(pos), origin);
|
||||||
@ -418,19 +416,19 @@ StreamError FileStream::seek(std::intptr_t pos, SeekMode seekMode)
|
|||||||
void FileStream::flush()
|
void FileStream::flush()
|
||||||
{
|
{
|
||||||
const int result = std::fflush(handle);
|
const int result = std::fflush(handle);
|
||||||
assert(result == 0);
|
MIJIN_ASSERT(result == 0, "fflush failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileStream::isAtEnd()
|
bool FileStream::isAtEnd()
|
||||||
{
|
{
|
||||||
assert(handle);
|
MIJIN_ASSERT(handle != nullptr, "FileStream is not open.");
|
||||||
|
|
||||||
(void) std::fgetc(handle);
|
(void) std::fgetc(handle);
|
||||||
if (std::feof(handle)) {
|
if (std::feof(handle)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const int result = std::fseek(handle, -1, SEEK_CUR);
|
const int result = std::fseek(handle, -1, SEEK_CUR);
|
||||||
assert(result == 0);
|
MIJIN_ASSERT(result == 0, "fseek failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,7 +452,7 @@ StreamFeatures FileStream::getFeatures()
|
|||||||
|
|
||||||
void MemoryStream::openRW(std::span<std::uint8_t> data)
|
void MemoryStream::openRW(std::span<std::uint8_t> data)
|
||||||
{
|
{
|
||||||
assert(!isOpen());
|
MIJIN_ASSERT(!isOpen(), "MemoryStream is already open.");
|
||||||
data_ = data;
|
data_ = data;
|
||||||
pos_ = 0;
|
pos_ = 0;
|
||||||
canWrite_ = true;
|
canWrite_ = true;
|
||||||
@ -462,7 +460,7 @@ void MemoryStream::openRW(std::span<std::uint8_t> data)
|
|||||||
|
|
||||||
void MemoryStream::openROImpl(const void* data, std::size_t bytes)
|
void MemoryStream::openROImpl(const void* data, std::size_t bytes)
|
||||||
{
|
{
|
||||||
assert(!isOpen());
|
MIJIN_ASSERT(!isOpen(), "MemoryStream is already open.");
|
||||||
data_ = std::span<std::uint8_t>(const_cast<std::uint8_t*>(static_cast<const std::uint8_t*>(data)), bytes); // NOLINT(cppcoreguidelines-pro-type-const-cast) we'll be fine
|
data_ = std::span<std::uint8_t>(const_cast<std::uint8_t*>(static_cast<const std::uint8_t*>(data)), bytes); // NOLINT(cppcoreguidelines-pro-type-const-cast) we'll be fine
|
||||||
pos_ = 0;
|
pos_ = 0;
|
||||||
canWrite_ = false;
|
canWrite_ = false;
|
||||||
@ -470,13 +468,13 @@ void MemoryStream::openROImpl(const void* data, std::size_t bytes)
|
|||||||
|
|
||||||
void MemoryStream::close()
|
void MemoryStream::close()
|
||||||
{
|
{
|
||||||
assert(isOpen());
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
data_ = {};
|
data_ = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamError MemoryStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
StreamError MemoryStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
||||||
{
|
{
|
||||||
assert(isOpen());
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
if (!options.partial && availableBytes() < buffer.size()) {
|
if (!options.partial && availableBytes() < buffer.size()) {
|
||||||
return StreamError::IO_ERROR; // TODO: need more errors?
|
return StreamError::IO_ERROR; // TODO: need more errors?
|
||||||
}
|
}
|
||||||
@ -493,8 +491,11 @@ StreamError MemoryStream::readRaw(std::span<std::uint8_t> buffer, const ReadOpti
|
|||||||
|
|
||||||
StreamError MemoryStream::writeRaw(std::span<const std::uint8_t> buffer)
|
StreamError MemoryStream::writeRaw(std::span<const std::uint8_t> buffer)
|
||||||
{
|
{
|
||||||
assert(isOpen());
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
assert(canWrite_);
|
|
||||||
|
if (!canWrite_) {
|
||||||
|
return StreamError::NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
if (availableBytes() < buffer.size()) {
|
if (availableBytes() < buffer.size()) {
|
||||||
return StreamError::IO_ERROR;
|
return StreamError::IO_ERROR;
|
||||||
@ -506,13 +507,13 @@ StreamError MemoryStream::writeRaw(std::span<const std::uint8_t> buffer)
|
|||||||
|
|
||||||
std::size_t MemoryStream::tell()
|
std::size_t MemoryStream::tell()
|
||||||
{
|
{
|
||||||
assert(isOpen());
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
return pos_;
|
return pos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamError MemoryStream::seek(std::intptr_t pos, SeekMode seekMode)
|
StreamError MemoryStream::seek(std::intptr_t pos, SeekMode seekMode)
|
||||||
{
|
{
|
||||||
assert(isOpen());
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
std::intptr_t newPos = -1;
|
std::intptr_t newPos = -1;
|
||||||
switch (seekMode)
|
switch (seekMode)
|
||||||
{
|
{
|
||||||
@ -535,7 +536,7 @@ StreamError MemoryStream::seek(std::intptr_t pos, SeekMode seekMode)
|
|||||||
|
|
||||||
bool MemoryStream::isAtEnd()
|
bool MemoryStream::isAtEnd()
|
||||||
{
|
{
|
||||||
assert(isOpen());
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
return pos_ == data_.size();
|
return pos_ == data_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#if !defined(MIJIN_IO_STREAM_HPP_INCLUDED)
|
#if !defined(MIJIN_IO_STREAM_HPP_INCLUDED)
|
||||||
#define MIJIN_IO_STREAM_HPP_INCLUDED 1
|
#define MIJIN_IO_STREAM_HPP_INCLUDED 1
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
@ -322,8 +321,9 @@ public:
|
|||||||
}
|
}
|
||||||
void close();
|
void close();
|
||||||
[[nodiscard]] inline bool isOpen() const { return data_.data() != nullptr; }
|
[[nodiscard]] inline bool isOpen() const { return data_.data() != nullptr; }
|
||||||
[[nodiscard]] inline std::size_t availableBytes() const {
|
[[nodiscard]] inline std::size_t availableBytes() const
|
||||||
assert(isOpen());
|
{
|
||||||
|
MIJIN_ASSERT(isOpen(), "MemoryStream is not open.");
|
||||||
return data_.size() - pos_;
|
return data_.size() - pos_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cassert>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace mijin
|
namespace mijin
|
||||||
@ -32,8 +31,9 @@ private:
|
|||||||
using byte_type = std::conditional_t<threadSafe, std::atomic_uint8_t, std::uint8_t>;
|
using byte_type = std::conditional_t<threadSafe, std::atomic_uint8_t, std::uint8_t>;
|
||||||
std::array<byte_type, (numBits + 7) / 8> bytes;
|
std::array<byte_type, (numBits + 7) / 8> bytes;
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] bool get(std::size_t index) const {
|
[[nodiscard]] bool get(std::size_t index) const
|
||||||
assert(index < numBits);
|
{
|
||||||
|
MIJIN_ASSERT(index < numBits, "BitArray: index out of range.");
|
||||||
return (bytes[index / 8] & (1 << (index % 8)));
|
return (bytes[index / 8] & (1 << (index % 8)));
|
||||||
}
|
}
|
||||||
void set(std::size_t index, bool value)
|
void set(std::size_t index, bool value)
|
||||||
|
@ -51,13 +51,13 @@ Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) noexcept
|
|||||||
{
|
{
|
||||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||||
const std::unique_lock dlErrorLock(gDlErrorMutex);
|
const std::unique_lock dlErrorLock(gDlErrorMutex);
|
||||||
dlerror();
|
dlerror(); // NOLINT(concurrency-mt-unsafe) we take care of that
|
||||||
|
|
||||||
const fs::path libraryPath = fs::absolute(libraryFile);
|
const fs::path libraryPath = fs::absolute(libraryFile);
|
||||||
void* ptr = dlopen(libraryPath.c_str(), RTLD_NOW);
|
void* ptr = dlopen(libraryPath.c_str(), RTLD_NOW);
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
{
|
{
|
||||||
return ResultError(dlerror());
|
return ResultError(dlerror()); // NOLINT(concurrency-mt-unsafe) we take care of that
|
||||||
}
|
}
|
||||||
return LibraryHandle{.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
|
return LibraryHandle{.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
|
||||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user