*: reformat

This commit is contained in:
2026-02-15 11:02:43 -05:00
parent c6e2128875
commit 97a001ac90
6 changed files with 33 additions and 51 deletions

View File

@@ -1,5 +1,5 @@
#include <utils/types.hpp>
#include <utils/error.hpp>
#include <utils/types.hpp>
namespace kvm {
@@ -8,12 +8,12 @@ namespace kvm {
class VM {
/// The primary vCPU.
util::Ref<CPU> vcpu;
public:
public:
/// Creates a new VM instance.
static util::ErrorOr<util::Ref<VM>> create();
// TODO: more stuff
};
}
} // namespace kvm

View File

@@ -1,5 +1,4 @@
int main(int argc, char** argv) {
}

View File

@@ -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

View File

@@ -1,8 +1,8 @@
#pragma once
#include <format>
#include <optional>
#include <string>
#include <variant>
#include <optional>
#include <format>
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<class ...Args>
template <class... Args>
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<class T>
template <class T>
class ErrorOr {
std::variant<
Error,
T
> variant;
public:
constexpr ErrorOr(const Error& error)
: variant(error) {}
std::variant<Error, T> variant;
constexpr ErrorOr(const T& value)
: variant(value) {}
public:
constexpr ErrorOr(const Error& error) : variant(error) {}
bool isValue() const {
return std::holds_alternative<T>(variant);
}
constexpr ErrorOr(const T& value) : variant(value) {}
bool isError() const {
return std::holds_alternative<Error>(variant);
}
bool isValue() const { return std::holds_alternative<T>(variant); }
const Error& err() const {
return std::get<Error>(variant);
}
bool isError() const { return std::holds_alternative<Error>(variant); }
T& value() {
return std::get<T>(variant);
}
const Error& err() const { return std::get<Error>(variant); }
T& value() const {
return std::get<T>(variant);
}
T& value() { return std::get<T>(variant); }
T& value() const { return std::get<T>(variant); }
};
template<>
template <>
class ErrorOr<void> {
std::optional<Error> 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

View File

@@ -1,12 +1,11 @@
//! Core types and includes
#pragma once
#include <base/assert.hpp>
#include <cstdint>
#include <memory>
#include <span>
#include <base/assert.hpp>
// 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 <class T, auto Free = std::free>
using CUnique = Unique<T, UniqueCDeleter<T, Free>>;
} // namespace base
} // namespace util

3
tools/format.sh Executable file
View File

@@ -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 "{}"