Skip to content

Commit

Permalink
style: fix multiple clang-tidy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 27, 2024
1 parent 72eea69 commit 0244800
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 102 deletions.
12 changes: 8 additions & 4 deletions core/include/cubos/core/memory/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ namespace cubos::core::memory
template <typename F>
static void* (*getCopier())(const void*)
{
constexpr bool IsCopyable = requires(const F& f) { new F(f); };
constexpr bool IsCopyable = requires(const F& f)
{
new F(f);
};

if constexpr (IsCopyable)
{
return [](const void* function) -> void* { return new F(*static_cast<const F*>(function)); };
Expand All @@ -172,9 +176,9 @@ namespace cubos::core::memory
}

void* mFunction{nullptr};
I mInvoke;
void (*mFree)(void*);
void* (*mCopy)(const void*);
I mInvoke{};
void (*mFree)(void*){};
void* (*mCopy)(const void*){};
};

template <typename R, typename... Ts>
Expand Down
2 changes: 1 addition & 1 deletion core/include/cubos/core/reflection/type_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace cubos::core::reflection
using Deserialize = memory::Function<bool(const TypeRegistry&, Type&, data::Deserializer&) const>;

/// @brief Function type for discovering new types from a trait.
using DiscoverTypes = void (*)(const Type&, memory::Function<void(const Type&) const>);
using DiscoverTypes = void (*)(const Type&, memory::Function<void(const Type&) const>&);

/// @brief Default constructor.
TypeClient();
Expand Down
2 changes: 1 addition & 1 deletion core/include/cubos/core/reflection/type_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace cubos::core::reflection
using Serialize = memory::Function<bool(data::Serializer&, const Type&, bool) const>;

/// @brief Function type for discovering new types from a trait.
using DiscoverTypes = void (*)(const Type&, memory::Function<void(const Type&) const>);
using DiscoverTypes = void (*)(const Type&, memory::Function<void(const Type&) const>&);

/// @brief Default constructs.
TypeServer();
Expand Down
2 changes: 1 addition & 1 deletion core/src/al/oal_audio_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ OALAudioDevice::OALAudioDevice(const std::string& specifier)
#endif // WITH_OPENAL
}

OALAudioDevice::~OALAudioDevice()
OALAudioDevice::~OALAudioDevice() // NOLINT(modernize-use-equals-default)
{
#ifdef WITH_OPENAL
auto* context = alcGetCurrentContext();
Expand Down
2 changes: 1 addition & 1 deletion core/src/data/des/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool BinaryDeserializer::decompose(const Type& type, void* value)
return false;
}

for (auto& bit : trait)
for (const auto& bit : trait)
{
bit.clear(value);
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/ecs/system/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ auto Planner::add() -> TagId

auto Planner::add(std::string name) -> TagId
{
mTags.push_back(TagData{.name = name});
mTags.push_back(TagData{.name = memory::move(name)});
return {mTags.size() - 1};
}

auto Planner::add(std::string name, SystemId systemId) -> TagId
{
mTags.push_back(TagData{.name = name, .systemId = systemId});
mTags.push_back(TagData{.name = memory::move(name), .systemId = systemId});
return {mTags.size() - 1};
}

Expand Down Expand Up @@ -370,7 +370,7 @@ void Planner::makeSystemOrRepeatNode(TagId tagId, Schedule& schedule, const std:
return;
}

auto& tag = tags[tagId.inner];
const auto& tag = tags[tagId.inner];

// Get the repeating node the new node will belong to.
Opt<Schedule::NodeId> repeatingNodeId{};
Expand Down
2 changes: 1 addition & 1 deletion core/src/ecs/system/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool Schedule::order(NodeId before, NodeId after)
return true;
}

if (this->ordered(after, before))
if (this->ordered(after, before)) // NOLINT(readability-suspicious-call-argument)
{
// Would form a cycle.
CUBOS_ERROR("Making node {} run before {} would form a cycle, as {} must already run before {}", before.inner,
Expand Down
2 changes: 1 addition & 1 deletion core/src/ecs/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ void World::ConstRelations::Iterator::advance()
for (; mTableIndex < tables.size(); ++mTableIndex)
{
mTableId = tables[mTableIndex];
auto& table = registry.at(mTableId);
const auto& table = registry.at(mTableId);

if (mRow >= table.size())
{
Expand Down
36 changes: 18 additions & 18 deletions core/src/gl/ogl_render_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class OGLFramebuffer : public impl::Framebuffer
{
public:
OGLFramebuffer(std::shared_ptr<bool> destroyed, GLuint id)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
{
}
Expand Down Expand Up @@ -536,7 +536,7 @@ class OGLPixelPackBuffer : public impl::PixelPackBuffer
{
public:
OGLPixelPackBuffer(std::shared_ptr<bool> destroyed, GLuint id)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
{
}
Expand Down Expand Up @@ -569,7 +569,7 @@ class OGLSampler : public impl::Sampler
{
public:
OGLSampler(std::shared_ptr<bool> destroyed, GLuint id)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
{
}
Expand All @@ -591,7 +591,7 @@ class OGLTexture1D : public impl::Texture1D
{
public:
OGLTexture1D(std::shared_ptr<bool> destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, internalFormat(internalFormat)
, format(format)
Expand Down Expand Up @@ -632,7 +632,7 @@ class OGLTexture2D : public impl::Texture2D
{
public:
OGLTexture2D(std::shared_ptr<bool> destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, internalFormat(internalFormat)
, format(format)
Expand Down Expand Up @@ -689,7 +689,7 @@ class OGLTexture2DArray : public impl::Texture2DArray
{
public:
OGLTexture2DArray(std::shared_ptr<bool> destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, internalFormat(internalFormat)
, format(format)
Expand Down Expand Up @@ -732,7 +732,7 @@ class OGLTexture3D : public impl::Texture3D
{
public:
OGLTexture3D(std::shared_ptr<bool> destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, internalFormat(internalFormat)
, format(format)
Expand Down Expand Up @@ -775,7 +775,7 @@ class OGLCubeMap : public impl::CubeMap
{
public:
OGLCubeMap(std::shared_ptr<bool> destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, internalFormat(internalFormat)
, format(format)
Expand Down Expand Up @@ -820,7 +820,7 @@ class OGLCubeMapArray : public impl::CubeMapArray
{
public:
OGLCubeMapArray(std::shared_ptr<bool> destroyed, GLuint id, GLenum internalFormat, GLenum format, GLenum type)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, internalFormat(internalFormat)
, format(format)
Expand Down Expand Up @@ -863,7 +863,7 @@ class OGLConstantBuffer : public impl::ConstantBuffer
{
public:
OGLConstantBuffer(std::shared_ptr<bool> destroyed, GLuint id)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
{
}
Expand Down Expand Up @@ -902,7 +902,7 @@ class OGLIndexBuffer : public impl::IndexBuffer
{
public:
OGLIndexBuffer(std::shared_ptr<bool> destroyed, GLuint id, GLenum format, std::size_t indexSz)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
, format(format)
, indexSz(indexSz)
Expand Down Expand Up @@ -939,7 +939,7 @@ class OGLVertexBuffer : public impl::VertexBuffer
{
public:
OGLVertexBuffer(std::shared_ptr<bool> destroyed, GLuint id)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
{
}
Expand Down Expand Up @@ -980,7 +980,7 @@ class OGLVertexArray : public impl::VertexArray
{
public:
OGLVertexArray(std::shared_ptr<bool> destroyed, GLuint id, const VertexBuffer* buffers)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, id(id)
{
for (std::size_t i = 0; i < CUBOS_CORE_GL_MAX_VERTEX_ARRAY_BUFFER_COUNT; ++i)
Expand All @@ -1007,7 +1007,7 @@ class OGLShaderStage : public impl::ShaderStage
{
public:
OGLShaderStage(std::shared_ptr<bool> destroyed, Stage type, GLuint shader)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, type(type)
, shader(shader)
{
Expand Down Expand Up @@ -1253,7 +1253,7 @@ class OGLShaderPipeline : public impl::ShaderPipeline
{
public:
OGLShaderPipeline(std::shared_ptr<bool> destroyed, ShaderStage vs, ShaderStage ps, GLuint program)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, vs(std::move(vs))
, ps(std::move(ps))
, program(program)
Expand All @@ -1264,13 +1264,13 @@ class OGLShaderPipeline : public impl::ShaderPipeline
}

OGLShaderPipeline(std::shared_ptr<bool> destroyed, ShaderStage vs, ShaderStage gs, ShaderStage ps, GLuint program)
: OGLShaderPipeline(destroyed, std::move(vs), std::move(ps), program)
: OGLShaderPipeline(std::move(destroyed), std::move(vs), std::move(ps), program)
{
this->gs = std::move(gs);
}

OGLShaderPipeline(std::shared_ptr<bool> destroyed, ShaderStage cs, GLuint program)
: destroyed(destroyed)
: destroyed(std::move(destroyed))
, cs(std::move(cs))
, program(program)
{
Expand Down Expand Up @@ -2215,7 +2215,7 @@ PixelPackBuffer OGLRenderDevice::createPixelPackBuffer(std::size_t size)
GLuint id;
glGenBuffers(1, &id);
glBindBuffer(GL_PIXEL_PACK_BUFFER, id);
glBufferData(GL_PIXEL_PACK_BUFFER, static_cast<GLsizeiptr>(size), NULL, GL_STREAM_COPY);
glBufferData(GL_PIXEL_PACK_BUFFER, static_cast<GLsizeiptr>(size), nullptr, GL_STREAM_COPY);

// Check errors
GLenum glErr = glGetError();
Expand Down
5 changes: 3 additions & 2 deletions core/src/memory/any_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ void AnyVector::reserve(std::size_t capacity)
}

// Allocate a new buffer, move the values there and then free the old one.
void* data = operator new(capacity * mStride, static_cast<std::align_val_t>(mConstructibleTrait->alignment()),
std::nothrow);
auto size = capacity * mStride;
auto alignment = static_cast<std::align_val_t>(mConstructibleTrait->alignment());
void* data = operator new(size, alignment, std::nothrow);
CUBOS_ASSERT(data != nullptr, "Vector memory allocation failed");
for (std::size_t i = 0; i < mSize; ++i)
{
Expand Down
10 changes: 4 additions & 6 deletions core/src/net/tcp_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using cubos::core::net::Address;
using cubos::core::net::TcpListener;
using cubos::core::net::TcpStream;

TcpListener::TcpListener()
TcpListener::TcpListener() // NOLINT(modernize-use-equals-default)
{
#ifdef _WIN32
WSADATA wsa;
Expand Down Expand Up @@ -135,9 +135,7 @@ bool TcpListener::create()
CUBOS_ERROR("Failed to create TCP socket, got error {}", logSystemError());
return false;
}
else
{
this->setBlocking(mBlocking);
return true;
}

this->setBlocking(mBlocking);
return true;
}
10 changes: 4 additions & 6 deletions core/src/net/tcp_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using cubos::core::net::Address;
using cubos::core::net::TcpStream;

TcpStream::TcpStream()
TcpStream::TcpStream() // NOLINT(modernize-use-equals-default)
{
#ifdef _WIN32
WSADATA wsa;
Expand Down Expand Up @@ -215,9 +215,7 @@ bool TcpStream::create()
CUBOS_ERROR("Failed to create TCP socket, got error {}", logSystemError());
return false;
}
else
{
this->setBlocking(mBlocking);
return true;
}

this->setBlocking(mBlocking);
return true;
}
12 changes: 6 additions & 6 deletions core/src/reflection/traits/mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ MaskTrait::Bit::Bit(std::string name, Tester tester, Setter setter, Clearer clea
{
}

bool MaskTrait::Bit::test(const void* instance) const
bool MaskTrait::Bit::test(const void* value) const
{
return mTester(instance);
return mTester(value);
}

void MaskTrait::Bit::set(void* instance) const
void MaskTrait::Bit::set(void* value) const
{
mSetter(instance);
mSetter(value);
}

void MaskTrait::Bit::clear(void* instance) const
void MaskTrait::Bit::clear(void* value) const
{
mClearer(instance);
mClearer(value);
}

const std::string& MaskTrait::Bit::name() const
Expand Down
6 changes: 4 additions & 2 deletions core/src/reflection/type_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ void TypeClient::addTrait(bool isStructural, const Type& traitType, Deserialize
auto& trait = mTraits.at(traitType);

// Re-discover types that are already known and have the new trait.
memory::Function<void(const Type&) const> addType = [this](const Type& type) { this->addType(type); };
auto oldKnownTypes = mKnownTypes;
for (auto [type, _] : oldKnownTypes)
{
if (type->has(traitType))
{
trait.discoverTypes(*type, [this](const Type& type) { this->addType(type); });
trait.discoverTypes(*type, addType);
}
}
}
Expand All @@ -52,11 +53,12 @@ void TypeClient::addType(const Type& type)
mKnownTypes.insert(type);

// Add types which can be discovered from the new type.
memory::Function<void(const Type&) const> addType = [this](const Type& type) { this->addType(type); };
for (const auto& [traitType, trait] : mTraits)
{
if (type.has(*traitType))
{
trait.discoverTypes(type, [this](const Type& type) { this->addType(type); });
trait.discoverTypes(type, addType);
}
}
}
Expand Down
Loading

0 comments on commit 0244800

Please sign in to comment.