diff --git a/src/kvm/vm.hpp b/src/kvm/vm.hpp index 37c42f4..8964db9 100644 --- a/src/kvm/vm.hpp +++ b/src/kvm/vm.hpp @@ -1,5 +1,5 @@ -#include #include +#include namespace kvm { @@ -8,12 +8,12 @@ namespace kvm { class VM { /// The primary vCPU. util::Ref vcpu; - public: + public: /// Creates a new VM instance. static util::ErrorOr> create(); // TODO: more stuff }; -} +} // namespace kvm diff --git a/src/main.cpp b/src/main.cpp index 79f5231..49207c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ int main(int argc, char** argv) { - } diff --git a/src/utils/error.cpp b/src/utils/error.cpp index 8d8120f..17b4443 100644 --- a/src/utils/error.cpp +++ b/src/utils/error.cpp @@ -8,9 +8,9 @@ namespace util { } Error Error::systemError() { - char errBuffer[128]{}; + char errBuffer[128] {}; auto* pStr = strerror_r(errno, &errBuffer[0], sizeof(errBuffer)); return Error::format("System error: {}", std::string_view(pStr)); } -} +} // namespace util diff --git a/src/utils/error.hpp b/src/utils/error.hpp index 765d0b7..5eb8d94 100644 --- a/src/utils/error.hpp +++ b/src/utils/error.hpp @@ -1,8 +1,8 @@ #pragma once +#include +#include #include #include -#include -#include namespace util { @@ -12,11 +12,10 @@ namespace util { static Error vFormat(const std::string_view formatString, std::format_args args); - public: - explicit Error(const std::string& message) - : msg(message) {} + public: + explicit Error(const std::string& message) : msg(message) {} - template + template static constexpr auto format(const std::string_view formatString, Args... args) { return vFormat(formatString, std::make_format_args(args...)); } @@ -28,55 +27,37 @@ namespace util { }; /// A type which can store either an error or a value. - template + template class ErrorOr { - std::variant< - Error, - T - > variant; - public: - constexpr ErrorOr(const Error& error) - : variant(error) {} + std::variant variant; - constexpr ErrorOr(const T& value) - : variant(value) {} + public: + constexpr ErrorOr(const Error& error) : variant(error) {} - bool isValue() const { - return std::holds_alternative(variant); - } + constexpr ErrorOr(const T& value) : variant(value) {} - bool isError() const { - return std::holds_alternative(variant); - } + bool isValue() const { return std::holds_alternative(variant); } - const Error& err() const { - return std::get(variant); - } + bool isError() const { return std::holds_alternative(variant); } - T& value() { - return std::get(variant); - } + const Error& err() const { return std::get(variant); } - T& value() const { - return std::get(variant); - } + T& value() { return std::get(variant); } + + T& value() const { return std::get(variant); } }; - template<> + template <> class ErrorOr { std::optional error; - public: + + public: ErrorOr() = default; - ErrorOr(const Error& error) - : error(error) {} + ErrorOr(const Error& error) : error(error) {} - bool isError() const { - return error.has_value(); - } + bool isError() const { return error.has_value(); } - const Error& err() const { - return error.value(); - } + const Error& err() const { return error.value(); } }; -} +} // namespace util diff --git a/src/utils/types.hpp b/src/utils/types.hpp index 597a48b..2b493dc 100644 --- a/src/utils/types.hpp +++ b/src/utils/types.hpp @@ -1,12 +1,11 @@ //! Core types and includes #pragma once +#include #include #include #include -#include - // these are in the global namespace since most libraries // won't try defining anything like this in the global namespace // (and I'd like these types to be used globally a lot more anyways) @@ -56,4 +55,4 @@ namespace util { template using CUnique = Unique>; -} // namespace base +} // namespace util diff --git a/tools/format.sh b/tools/format.sh new file mode 100755 index 0000000..1f00792 --- /dev/null +++ b/tools/format.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# Reformats the entire tv2hv source tree. +find src/ -type f | rg -e "(.cpp|.h|.hpp)" | xargs -i -- clang-format -i "{}"