Skip to content
Merged
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 include/Stl/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <locale>
#include <stdexcept>

#include <string>

#if __has_include(<string_view>)
# include <string_view>

Expand Down
33 changes: 19 additions & 14 deletions modules/Language/VirtualMachine.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export namespace CppUtils::Language::VirtualMachine
case '#':
if (auto startPosition = stack.template get<std::size_t>(); not startPosition) [[unlikely]]
return std::unexpected{startPosition.error()};
else if (auto result = stack.set(std::hash<decltype(source)>{}(decltype(source){std::cbegin(source) + startPosition.value() + 1, std::cbegin(source) + position - 1})); not result) [[unlikely]]
else if (auto result = stack.set(std::hash<decltype(source)>{}(decltype(source){std::cbegin(source) + static_cast<long long>(startPosition.value() + 1), std::cbegin(source) + static_cast<long long>(position - 1)})); not result) [[unlikely]]
return result;
break;

Expand Down Expand Up @@ -178,9 +178,9 @@ export namespace CppUtils::Language::VirtualMachine
case '>':
if (auto key = stack.template get<std::size_t>(); not key) [[unlikely]]
return std::unexpected{key.error()};
else if (registers.contains(key.value())) [[likely]]
stack.set(registers[key.value()]);
else
else if (registers.contains(key.value())) [[likely]] {
auto _ = stack.set(registers[key.value()]);
} else
return std::unexpected{"Unknown register key"sv};
break;

Expand Down Expand Up @@ -253,55 +253,60 @@ export namespace CppUtils::Language::VirtualMachine

case '\\': ++position; break;

case '!':
case '!': {
if (auto result = stack.template get<std::size_t>(); not result) [[unlikely]]
return std::unexpected{result.error()};
else
stack.set<std::size_t>(not result.value());
auto _ = stack.set<std::size_t>(not result.value());
break;
}

case '?':
case '?': {
if (auto condition = stack.template get<std::size_t>(sizeof(std::size_t)); not condition) [[unlikely]]
return std::unexpected{condition.error()};
else if (auto newPosition = stack.template pop<std::size_t>(); not newPosition) [[unlikely]]
return std::unexpected{newPosition.error()};
else if (not condition.value())
position = newPosition.value();
stack.drop(sizeof(std::size_t));
auto _ = stack.drop(sizeof(std::size_t));
break;
}

case 'X': return {};

case '+':
case '+': {
if (auto lhs = stack.template pop<std::size_t>(); not lhs) [[unlikely]]
return std::unexpected{lhs.error()};
else if (auto rhs = stack.template get<std::size_t>(); not rhs) [[unlikely]]
return std::unexpected{rhs.error()};
else
stack.set(lhs.value() + rhs.value());
auto _ = stack.set(lhs.value() + rhs.value());
break;
}

case '-':
case '-': {
if (auto lhs = stack.template pop<std::size_t>(); not lhs) [[unlikely]]
return std::unexpected{lhs.error()};
else if (auto rhs = stack.template get<std::size_t>(); not rhs) [[unlikely]]
return std::unexpected{rhs.error()};
else
stack.set(lhs.value() - rhs.value());
auto _ = stack.set(lhs.value() - rhs.value());
break;
}

case ',': stack.dump(); break;

case '\'': stack.set(source[++position]); break;
case '\'': { auto _ = stack.set(source[++position]); break; }

default:
if (instruction >= '0' and instruction <= '9')
{
if (auto result = stack.template get<std::size_t>(); not result) [[unlikely]]
return std::unexpected{result.error()};
else
stack.set(result.value() * 10 + static_cast<std::size_t>(instruction - '0'));
auto _ = stack.set(result.value() * 10 + static_cast<std::size_t>(instruction - '0'));
}
break;
}

return {};
Expand Down
7 changes: 6 additions & 1 deletion modules/Network/Socket.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ export namespace CppUtils::Network
auto data = T{};
for (auto totalBytesReceived = 0uz; totalBytesReceived < sizeof(T);)
{
auto bytesReceived = ::recv(m_socket, reinterpret_cast<char*>(std::addressof(data)) + totalBytesReceived, sizeof(T) - totalBytesReceived, 0);
#if defined(OS_WINDOWS)
const auto size = static_cast<int>(sizeof(T) - totalBytesReceived);
#else
const auto size = sizeof(T) - totalBytesReceived;
#endif
auto bytesReceived = ::recv(m_socket, reinterpret_cast<char*>(std::addressof(data)) + totalBytesReceived, size, 0);
if (bytesReceived < 0)
{
#if defined(OS_WINDOWS)
Expand Down
6 changes: 3 additions & 3 deletions modules/Terminal/Cursor.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export namespace CppUtils::Terminal
auto consoleScreenBufferInfo = CONSOLE_SCREEN_BUFFER_INFO{};
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &consoleScreenBufferInfo);
return Container::Size2{
consoleScreenBufferInfo.srWindow.X,
consoleScreenBufferInfo.srWindow.Y};
consoleScreenBufferInfo.srWindow.Left,
consoleScreenBufferInfo.srWindow.Top};
}
#elif defined(OS_MAC) or defined(OS_LINUX)
[[nodiscard]] inline auto getCursorPosition() -> std::expected<Container::Size2, std::string_view>
Expand All @@ -41,7 +41,7 @@ export namespace CppUtils::Terminal
#if defined(OS_WINDOWS)
inline auto setCursorPosition(Container::Size2 position) -> void
{
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), COORD{position.x(), position.y()});
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), COORD{static_cast<SHORT>(position.x()), static_cast<SHORT>(position.y())});
}
#elif defined(OS_MAC) or defined(OS_LINUX)
inline auto setCursorPosition([[maybe_unused]] Container::Size2 position) -> void
Expand Down
2 changes: 2 additions & 0 deletions modules/Terminal/Handle.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module;

#include <CppUtils/System/Windows.hpp>

#include <cstdio>

export module CppUtils.Terminal.Handle;

import std;
Expand Down
1 change: 1 addition & 0 deletions modules/Terminal/TextModifier.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import CppUtils.Terminal.BackgroundColor;
import CppUtils.Terminal.Utility;
import CppUtils.Terminal.TextColor;
import CppUtils.Terminal.TextStyle;
import CppUtils.Terminal.Handle;

export namespace CppUtils::Terminal
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Container/DependencyGraph.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export namespace CppUtils::UnitTest::Container::DependencyGraph

suite.expect(not graph.hasCycle());

graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void {
auto _ = graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void {
std::println("{}: {}", key, value);
});
});
Expand All @@ -159,7 +159,7 @@ export namespace CppUtils::UnitTest::Container::DependencyGraph

suite.expect(graph.hasCycle());

graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void {
auto _ = graph.forEach([](const auto& key, const auto& value, [[maybe_unused]] const auto& dependencies) -> void {
std::println("{}: {}", key, value);
});
});
Expand Down
16 changes: 8 additions & 8 deletions tests/Container/Stack.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export namespace CppUtils::UnitTest::Container::Stack
auto getNumber = []() -> std::size_t {
return 42uz;
};
stack.call(+getNumber);
auto _ = stack.call(+getNumber);
{
auto result = stack.pop<std::size_t>();
suite.expect(result.has_value());
Expand All @@ -97,7 +97,7 @@ export namespace CppUtils::UnitTest::Container::Stack
std::println("{}", nb);
};
stack.push(42uz);
stack.call(print);
auto _ = stack.call(print);
});

suite.addTest("Call function: (std::size_t, std::size_t) -> std::size_t", [&] {
Expand All @@ -108,8 +108,8 @@ export namespace CppUtils::UnitTest::Container::Stack
auto add = [](std::size_t lhs, std::size_t rhs) -> std::size_t {
return lhs + rhs;
};
stack.call(add);
stack.drop(sizeof(std::size_t) * 2);
auto _ = stack.call(add);
auto _ = stack.drop(sizeof(std::size_t) * 2);
{
auto result = stack.pop<std::size_t>();
suite.expect(result.has_value());
Expand All @@ -129,15 +129,15 @@ export namespace CppUtils::UnitTest::Container::Stack
auto print = [](std::size_t nb) -> void {
std::println("{}", nb);
};
stack.call(add);
stack.drop(sizeof(std::size_t) * 2);
auto _ = stack.call(add);
auto _ = stack.drop(sizeof(std::size_t) * 2);
{
auto result = stack.get<std::size_t>();
suite.expect(result.has_value());
suite.expectEqual(result.value(), 42uz);
}
stack.call(print);
stack.drop(sizeof(std::size_t));
auto _ = stack.call(print);
auto _ = stack.drop(sizeof(std::size_t));
suite.expect(std::empty(stack));
});
}};
Expand Down
32 changes: 32 additions & 0 deletions tests/FileSystem/Watcher.mpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module;

#include <CppUtils/System/OS.hpp>

export module CppUtils.UnitTests.FileSystem.Watcher;

import std;
Expand All @@ -10,18 +14,25 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
{"Logger", "FileSystem/Directory", "FileSystem/File"},
[](auto& suite) {
using namespace std::chrono_literals;
#if defined(OS_LINUX)
using Logger = CppUtils::Logger<"CppUtils">;
#endif

suite.addTest("No file", [&] {
CppUtils::FileSystem::TemporaryDirectory{[&suite](const auto& directory) -> void {
auto watcher = CppUtils::FileSystem::Watcher{};
watcher.watch(directory / "test.tmp");
#if defined(OS_LINUX)
watcher.onEvent(
[&suite](
[[maybe_unused]] CppUtils::FileSystem::Event event,
[[maybe_unused]] const std::filesystem::path& filePath) -> void {
suite.expect(false);
});
#else
auto &_ = suite;
#warning "TODO onEvent not implemented for this platform"
#endif
std::this_thread::sleep_for(10ms);
}};
});
Expand All @@ -33,12 +44,17 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher

auto watcher = CppUtils::FileSystem::Watcher{};
watcher.watch(filePath);
#if defined(OS_LINUX)
watcher.onEvent(
[&suite](
[[maybe_unused]] CppUtils::FileSystem::Event event,
[[maybe_unused]] const std::filesystem::path& filePath) -> void {
suite.expect(false);
});
#else
auto &_ = suite;
#warning "TODO onEvent not implemented for this platform"
#endif
std::this_thread::sleep_for(10ms);
}};
});
Expand All @@ -59,6 +75,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher

auto watcher = CppUtils::FileSystem::Watcher{};
watcher.watch(directory);
#if defined(OS_LINUX)
watcher.onEvent(
[](CppUtils::FileSystem::Event event,
const std::filesystem::path& filePath) -> void {
Expand All @@ -80,6 +97,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
suite.expectEqual(eventFilePath, filePath);
expectCloseFile = true;
});
#else
#warning "TODO onEvent not implemented for this platform"
#endif

CppUtils::FileSystem::String::write(directory / "test.tmp", "Hello World!");
std::this_thread::sleep_for(100ms);
Expand All @@ -96,6 +116,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher

auto watcher = CppUtils::FileSystem::Watcher{};
watcher.watch(filePath);
#if defined(OS_LINUX)
watcher.onEvent(
[](CppUtils::FileSystem::Event event,
const std::filesystem::path& filePath) -> void {
Expand All @@ -109,6 +130,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
suite.expectEqual(eventFilePath, filePath);
expectModifyFile = true;
});
#else
#warning "TODO onEvent not implemented for this platform"
#endif

CppUtils::FileSystem::String::write(filePath, "Bar");
std::this_thread::sleep_for(100ms);
Expand All @@ -124,6 +148,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher

auto watcher = CppUtils::FileSystem::Watcher{};
watcher.watch(directory);
#if defined(OS_LINUX)
watcher.onEvent(
[](CppUtils::FileSystem::Event event,
const std::filesystem::path& filePath) -> void {
Expand All @@ -137,6 +162,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
suite.expectEqual(eventFilePath, filePath);
expectModifyFile = true;
});
#else
#warning "TODO onEvent not implemented for this platform"
#endif

CppUtils::FileSystem::String::write(filePath, "Bar");
std::this_thread::sleep_for(100ms);
Expand All @@ -152,6 +180,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher

auto watcher = CppUtils::FileSystem::Watcher{};
watcher.watch(directory);
#if defined(OS_LINUX)
watcher.onEvent(
[](CppUtils::FileSystem::Event event,
const std::filesystem::path& filePath) -> void {
Expand All @@ -165,6 +194,9 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
suite.expectEqual(eventFilePath, filePath);
expectDeleteFile = true;
});
#else
#warning "TODO onEvent not implemented for this platform"
#endif

std::filesystem::remove(filePath);
std::this_thread::sleep_for(100ms);
Expand Down
2 changes: 1 addition & 1 deletion tests/Type/Tuple.mpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export namespace CppUtils::UnitTest::Type::Tuple
};

auto tuple = std::make_tuple(1, "Hello World!");
CppUtils::Type::Tuple::visitAt(tuple, 1, function);
auto _ = CppUtils::Type::Tuple::visitAt(tuple, 1, function);

suite.expect(called);
});
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set_version("0.0.0", {build = "%Y%m%d%H%M"})
set_license("LGPL3")
set_languages("clatest", "cxxlatest")
set_warnings("allextra", "pedantic", "error")
add_cxflags("clang::-Wconversion", "clang::-Wfatal-errors", "clang::-Wno-deprecated-declarations -Wno-unknown-attributes")
add_cxflags("clang::-Wno-error=#warnings", "clang::-Wconversion", "clang::-Wfatal-errors", "clang::-Wno-deprecated-declarations -Wno-unknown-attributes")
add_cxflags("clang::-fcolor-diagnostics", "clang::-fansi-escape-codes", "gcc::-fdiagnostics-color=always")
-- add_cxflags("-Wno-gnu-statement-expression-from-macro-expansion -Wno-gnu-statement-expression", {tools = { "clang", "gcc" })
set_optimize("fastest")
Expand Down
Loading