Skip to content

Commit

Permalink
fix: clang-tidy pain
Browse files Browse the repository at this point in the history
  • Loading branch information
luishfonseca committed Sep 25, 2023
1 parent d946246 commit 4bdc7bc
Show file tree
Hide file tree
Showing 49 changed files with 269 additions and 216 deletions.
30 changes: 15 additions & 15 deletions core/include/cubos/core/data/deserializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,21 @@ namespace cubos::core::data
/// This is a special case because std::vector<bool> are stored as arrays of bits, and therefore
/// need special handling.
/// @param des The deserializer.
/// @param val The value to deserialize.
void deserialize(Deserializer& des, std::vector<bool>::reference val);
/// @param obj The value to deserialize.
void deserialize(Deserializer& des, std::vector<bool>::reference obj);

/// Overload for deserializing std::vector.
/// @tparam T The type of the vector.
/// @param des The deserializer.
/// @param vec The vector to deserialize.
/// @param obj The vector to deserialize.
template <typename T>
inline void deserialize(Deserializer& des, std::vector<T>& vec)
inline void deserialize(Deserializer& des, std::vector<T>& obj)
{
std::size_t length = des.beginArray();
vec.resize(length);
obj.resize(length);
for (std::size_t i = 0; i < length; ++i)
{
deserialize(des, vec[i]);
deserialize(des, obj[i]);
}
des.endArray();
}
Expand All @@ -216,20 +216,20 @@ namespace cubos::core::data
/// @tparam K The key type of the map.
/// @tparam V The value type of the map.
/// @param des The deserializer.
/// @param map The map to deserialize.
/// @param obj The map to deserialize.
template <typename K, typename V>
inline void deserialize(Deserializer& des, std::unordered_map<K, V>& map)
inline void deserialize(Deserializer& des, std::unordered_map<K, V>& obj)
{
std::size_t length = des.beginDictionary();
map.clear();
map.reserve(length);
obj.clear();
obj.reserve(length);
for (std::size_t i = 0; i < length; ++i)
{
K key;
V value;
des.read(key);
des.read(value);
map.emplace(std::move(key), std::move(value));
obj.emplace(std::move(key), std::move(value));
}
des.endDictionary();
}
Expand All @@ -238,13 +238,13 @@ namespace cubos::core::data
/// @tparam T The type of the first value.
/// @tparam U The type of the second value.
/// @param des The deserializer.
/// @param pair The pair to deserialize.
/// @param obj The pair to deserialize.
template <typename T, typename U>
inline void deserialize(Deserializer& des, std::pair<T, U>& pair)
inline void deserialize(Deserializer& des, std::pair<T, U>& obj)
{
des.beginObject();
des.read(pair.first);
des.read(pair.second);
des.read(obj.first);
des.read(obj.second);
des.endObject();
}
} // namespace cubos::core::data
2 changes: 1 addition & 1 deletion core/include/cubos/core/data/fs/standard_archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace cubos::core::data
std::size_t parent(std::size_t id) const override;
std::size_t sibling(std::size_t id) const override;
std::size_t child(std::size_t id) const override;
std::unique_ptr<memory::Stream> open(std::size_t id, File::Handle handle, File::OpenMode mode) override;
std::unique_ptr<memory::Stream> open(std::size_t id, File::Handle file, File::OpenMode mode) override;

private:
/// @brief Information about a file in the directory.
Expand Down
36 changes: 18 additions & 18 deletions core/include/cubos/core/data/serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,34 @@ namespace cubos::core::data
/// This is a special case because std::vector<bool> are stored as arrays of bits, and therefore
/// need special handling.
/// @param ser The serializer.
/// @param val The value to serialize.
/// @param obj The value to serialize.
/// @param name The name of the value (optional).
void serialize(Serializer& ser, std::vector<bool>::const_reference val, const char* name);
void serialize(Serializer& ser, std::vector<bool>::const_reference obj, const char* name);

/// Overload for serializing char arrays.
/// Necessary because literal strings are treated as char arrays by the compiler.
/// Without this overload, the linker would fail.
/// @param ser The serializer.
/// @param str The string to serialize.
/// @param obj The string to serialize.
/// @param name The name of the string (optional).
template <std::size_t N>
inline void serialize(Serializer& ser, char const (&str)[N], const char* name)
inline void serialize(Serializer& ser, char const (&obj)[N], const char* name)
{
ser.writeString(str, name);
ser.writeString(obj, name);
}

/// Overload for serializing std::vector.
/// @tparam T The type of the vector.
/// @param ser The serializer.
/// @param vec The vector to serialize.
/// @param obj The vector to serialize.
/// @param name The name of the vector (optional).
template <typename T>
inline void serialize(Serializer& ser, const std::vector<T>& vec, const char* name)
inline void serialize(Serializer& ser, const std::vector<T>& obj, const char* name)
{
ser.beginArray(vec.size(), name);
for (const auto& obj : vec)
ser.beginArray(obj.size(), name);
for (const auto& element : obj)
{
ser.write(obj, nullptr);
ser.write(element, nullptr);
}
ser.endArray();
}
Expand All @@ -228,13 +228,13 @@ namespace cubos::core::data
/// @tparam K The type of the key.
/// @tparam V The type of the value.
/// @param ser The serializer.
/// @param map The map to serialize.
/// @param obj The map to serialize.
/// @param name The name of the map (optional).
template <typename K, typename V>
inline void serialize(Serializer& ser, const std::unordered_map<K, V>& map, const char* name)
inline void serialize(Serializer& ser, const std::unordered_map<K, V>& obj, const char* name)
{
ser.beginDictionary(map.size(), name);
for (const auto& pair : map)
ser.beginDictionary(obj.size(), name);
for (const auto& pair : obj)
{
ser.write(pair.first, nullptr);
ser.write(pair.second, nullptr);
Expand All @@ -246,14 +246,14 @@ namespace cubos::core::data
/// @tparam T The type of the first value.
/// @tparam U The type of the second value.
/// @param ser The serializer.
/// @param pair The pair to serialize.
/// @param obj The pair to serialize.
/// @param name The name of the pair (optional).
template <typename T, typename U>
inline void serialize(Serializer& ser, const std::pair<T, U>& pair, const char* name)
inline void serialize(Serializer& ser, const std::pair<T, U>& obj, const char* name)
{
ser.beginObject(name);
ser.write(pair.first, "first");
ser.write(pair.second, "second");
ser.write(obj.first, "first");
ser.write(obj.second, "second");
ser.endObject();
}
} // namespace cubos::core::data
2 changes: 1 addition & 1 deletion core/include/cubos/core/ecs/event_pipe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace cubos::core::ecs
mutable std::atomic_size_t readCount{0};

Event(T e, unsigned int m)
: event(e)
: event(std::move(e))
, mask(m)
{
}
Expand Down
4 changes: 2 additions & 2 deletions core/include/cubos/core/ecs/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ namespace cubos::core::ecs

#if CUBOS_LOG_LEVEL <= CUBOS_LOG_LEVEL_DEBUG
// Get the number of components being added.
constexpr std::size_t componentCount = sizeof...(ComponentTypes);
constexpr std::size_t ComponentCount = sizeof...(ComponentTypes);

std::string componentNames[] = {"", "'" + std::string{getComponentName<ComponentTypes>().value()} + "'" ...};
CUBOS_DEBUG("Created entity {} with components {}", entity.index,
fmt::join(componentNames + 1, componentNames + componentCount + 1, ", "));
fmt::join(componentNames + 1, componentNames + ComponentCount + 1, ", "));
#endif
return entity;
}
Expand Down
2 changes: 1 addition & 1 deletion core/include/cubos/core/geom/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace cubos::core::geom
/// @ingroup core-geom
struct Box
{
glm::vec3 halfSize{0.5f}; ///< Half size of the box.
glm::vec3 halfSize{0.5F}; ///< Half size of the box.

/// @brief Computes two opposite corners of the box on the major diagonal.
/// @param corners Array to store the two corners in.
Expand Down
8 changes: 4 additions & 4 deletions core/include/cubos/core/geom/capsule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ namespace cubos::core::geom
/// @ingroup core-geom
struct Capsule
{
float radius = 1.0f; ///< Radius of the capsule.
float length = 0.0f; ///< Length of the capsule.
float radius = 1.0F; ///< Radius of the capsule.
float length = 0.0F; ///< Length of the capsule.

/// @brief Constructs a sphere.
/// @param radius Sphere radius.
/// @return Sphere shape.
static Capsule sphere(float radius)
{
return {radius, 0.0f};
return {radius, 0.0F};
}

/// @brief Gets the height of the capsule.
/// @return Height of the capsule.
float height() const
{
return length + 2.0f * radius;
return length + 2.0F * radius;
}
};
} // namespace cubos::core::geom
Expand Down
2 changes: 1 addition & 1 deletion core/include/cubos/core/geom/plane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace cubos::core::geom
/// @ingroup core-geom
struct Plane
{
glm::vec3 normal{0.0f, 1.0f, 0.0f}; ///< Normal of the plane.
glm::vec3 normal{0.0F, 1.0F, 0.0F}; ///< Normal of the plane.
};
} // namespace cubos::core::geom

Expand Down
6 changes: 3 additions & 3 deletions core/include/cubos/core/reflection/traits/constructible.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ namespace cubos::core::reflection
std::size_t mSize;
std::size_t mAlignment;
Destructor mDestructor;
DefaultConstructor mDefaultConstructor;
CopyConstructor mCopyConstructor;
MoveConstructor mMoveConstructor;
DefaultConstructor mDefaultConstructor{nullptr};
CopyConstructor mCopyConstructor{nullptr};
MoveConstructor mMoveConstructor{nullptr};
};

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions core/include/cubos/core/reflection/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ namespace cubos::core::reflection
{
// This variable is unused, but since there is one for each type, its address is
// guaranteed to be unique for each type.
static const bool var = false;
return reinterpret_cast<uintptr_t>(&var);
static const bool Var = false;
return reinterpret_cast<uintptr_t>(&Var);
}

/// @brief %Trait entry in the type.
Expand Down
18 changes: 9 additions & 9 deletions core/samples/data/fs/embedded_archive/embed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@

using cubos::core::data::EmbeddedArchive;

static const uint8_t fileData3[] = {
static const uint8_t FileData3[] = {
0x62,
0x61,
0x7a,
};
static const uint8_t fileData4[] = {
static const uint8_t FileData4[] = {
0x66,
0x6f,
0x6f,
};

static const EmbeddedArchive::Data::Entry entries[] = {
static const EmbeddedArchive::Data::Entry Entries[] = {
{"", true, 0, 0, 2, nullptr, 0},
{"bar", true, 1, 4, 3, nullptr, 0},
{"baz.txt", false, 2, 0, 0, fileData3, sizeof(fileData3)},
{"foo.txt", false, 1, 0, 0, fileData4, sizeof(fileData4)},
{"baz.txt", false, 2, 0, 0, FileData3, sizeof(FileData3)},
{"foo.txt", false, 1, 0, 0, FileData4, sizeof(FileData4)},
};

static const EmbeddedArchive::Data embeddedArchiveData = {
entries,
sizeof(entries) / sizeof(entries[0]),
static const EmbeddedArchive::Data EmbeddedArchiveData = {
Entries,
sizeof(Entries) / sizeof(Entries[0]),
};

class DataRegister
{
public:
DataRegister()
{
EmbeddedArchive::registerData("assets", embeddedArchiveData);
EmbeddedArchive::registerData("assets", EmbeddedArchiveData);
}
};

Expand Down
4 changes: 2 additions & 2 deletions core/src/cubos/core/data/deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ void cubos::core::data::deserialize<std::string>(Deserializer& des, std::string&
des.readString(obj);
}

void cubos::core::data::deserialize(Deserializer& des, std::vector<bool>::reference val)
void cubos::core::data::deserialize(Deserializer& des, std::vector<bool>::reference obj)
{
bool boolean;
des.readBool(boolean);
val = boolean;
obj = boolean;
}

// Implementation of deserialize() for GLM types.
Expand Down
14 changes: 6 additions & 8 deletions core/src/cubos/core/data/fs/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ std::unique_ptr<memory::Stream> FileSystem::open(std::string_view path, File::Op
CUBOS_ERROR("Could not open file for reading at path '{}': the file does not exist", path);
return nullptr;
}
else
{
if (auto file = FileSystem::root()->create(path))
{
return file->open(mode);
}

CUBOS_ERROR("Could not open file for writing at path '{}': the file could not be created", path);
return nullptr;
if (auto file = FileSystem::root()->create(path))
{
return file->open(mode);
}

CUBOS_ERROR("Could not open file for writing at path '{}': the file could not be created", path);
return nullptr;
}
42 changes: 20 additions & 22 deletions core/src/cubos/core/data/fs/standard_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,30 @@ StandardArchive::StandardArchive(const std::filesystem::path& osPath, bool isDir
CUBOS_ERROR("File/directory '{}' does not exist on the host file system", osPath.string());
return;
}
else

// Create the file/directory.
if (isDirectory)
{
// Create the file/directory.
if (isDirectory)
std::error_code err;
if (!std::filesystem::create_directory(osPath, err))
{
std::error_code err;
if (!std::filesystem::create_directory(osPath, err))
{
CUBOS_ERROR("std::filesystem::create_directory() failed: {}", err.message());
CUBOS_ERROR("Could not create root directory '{}' on the host file system", osPath.string());
return;
}
CUBOS_ERROR("std::filesystem::create_directory() failed: {}", err.message());
CUBOS_ERROR("Could not create root directory '{}' on the host file system", osPath.string());
return;
}
else
}
else
{
// Write an empty file.
std::string path = osPath.string();
FILE* file = fopen(path.c_str(), "w");
if (file == nullptr)
{
// Write an empty file.
std::string path = osPath.string();
FILE* file = fopen(path.c_str(), "w");
if (file == nullptr)
{
CUBOS_ERROR("fopen() failed: {}", strerror(errno));
CUBOS_ERROR("Could not create root file '{}' on the host file system", path);
return;
}
fclose(file);
CUBOS_ERROR("fopen() failed: {}", strerror(errno));
CUBOS_ERROR("Could not create root file '{}' on the host file system", path);
return;
}
fclose(file);
}
}

Expand Down Expand Up @@ -264,7 +262,7 @@ std::unique_ptr<Stream> StandardArchive::open(std::size_t id, File::Handle file,
}

std::string path = it->second.osPath.string();
auto fd = fopen(path.c_str(), stdMode);
auto* fd = fopen(path.c_str(), stdMode);
if (fd == nullptr)
{
CUBOS_ERROR("fopen() failed: {}", strerror(errno));
Expand Down
Loading

0 comments on commit 4bdc7bc

Please sign in to comment.