*: reformat
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#include <utils/types.hpp>
|
|
||||||
#include <utils/error.hpp>
|
#include <utils/error.hpp>
|
||||||
|
#include <utils/types.hpp>
|
||||||
|
|
||||||
namespace kvm {
|
namespace kvm {
|
||||||
|
|
||||||
@@ -8,12 +8,12 @@ namespace kvm {
|
|||||||
class VM {
|
class VM {
|
||||||
/// The primary vCPU.
|
/// The primary vCPU.
|
||||||
util::Ref<CPU> vcpu;
|
util::Ref<CPU> vcpu;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
/// Creates a new VM instance.
|
/// Creates a new VM instance.
|
||||||
static util::ErrorOr<util::Ref<VM>> create();
|
static util::ErrorOr<util::Ref<VM>> create();
|
||||||
|
|
||||||
// TODO: more stuff
|
// TODO: more stuff
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace kvm
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ namespace util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Error Error::systemError() {
|
Error Error::systemError() {
|
||||||
char errBuffer[128]{};
|
char errBuffer[128] {};
|
||||||
auto* pStr = strerror_r(errno, &errBuffer[0], sizeof(errBuffer));
|
auto* pStr = strerror_r(errno, &errBuffer[0], sizeof(errBuffer));
|
||||||
return Error::format("System error: {}", std::string_view(pStr));
|
return Error::format("System error: {}", std::string_view(pStr));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace util
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <format>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <optional>
|
|
||||||
#include <format>
|
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
@@ -12,11 +12,10 @@ namespace util {
|
|||||||
|
|
||||||
static Error vFormat(const std::string_view formatString, std::format_args args);
|
static Error vFormat(const std::string_view formatString, std::format_args args);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Error(const std::string& message)
|
explicit Error(const std::string& message) : msg(message) {}
|
||||||
: msg(message) {}
|
|
||||||
|
|
||||||
template<class ...Args>
|
template <class... Args>
|
||||||
static constexpr auto format(const std::string_view formatString, Args... args) {
|
static constexpr auto format(const std::string_view formatString, Args... args) {
|
||||||
return vFormat(formatString, std::make_format_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.
|
/// A type which can store either an error or a value.
|
||||||
template<class T>
|
template <class T>
|
||||||
class ErrorOr {
|
class ErrorOr {
|
||||||
std::variant<
|
std::variant<Error, T> variant;
|
||||||
Error,
|
|
||||||
T
|
|
||||||
> variant;
|
|
||||||
public:
|
|
||||||
constexpr ErrorOr(const Error& error)
|
|
||||||
: variant(error) {}
|
|
||||||
|
|
||||||
constexpr ErrorOr(const T& value)
|
public:
|
||||||
: variant(value) {}
|
constexpr ErrorOr(const Error& error) : variant(error) {}
|
||||||
|
|
||||||
bool isValue() const {
|
constexpr ErrorOr(const T& value) : variant(value) {}
|
||||||
return std::holds_alternative<T>(variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isError() const {
|
bool isValue() const { return std::holds_alternative<T>(variant); }
|
||||||
return std::holds_alternative<Error>(variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Error& err() const {
|
bool isError() const { return std::holds_alternative<Error>(variant); }
|
||||||
return std::get<Error>(variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
T& value() {
|
const Error& err() const { return std::get<Error>(variant); }
|
||||||
return std::get<T>(variant);
|
|
||||||
}
|
|
||||||
|
|
||||||
T& value() const {
|
T& value() { return std::get<T>(variant); }
|
||||||
return std::get<T>(variant);
|
|
||||||
}
|
T& value() const { return std::get<T>(variant); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
class ErrorOr<void> {
|
class ErrorOr<void> {
|
||||||
std::optional<Error> error;
|
std::optional<Error> error;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
ErrorOr() = default;
|
ErrorOr() = default;
|
||||||
ErrorOr(const Error& error)
|
ErrorOr(const Error& error) : error(error) {}
|
||||||
: error(error) {}
|
|
||||||
|
|
||||||
bool isError() const {
|
bool isError() const { return error.has_value(); }
|
||||||
return error.has_value();
|
|
||||||
}
|
|
||||||
|
|
||||||
const Error& err() const {
|
const Error& err() const { return error.value(); }
|
||||||
return error.value();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace util
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
//! Core types and includes
|
//! Core types and includes
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <base/assert.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
#include <base/assert.hpp>
|
|
||||||
|
|
||||||
// these are in the global namespace since most libraries
|
// these are in the global namespace since most libraries
|
||||||
// won't try defining anything like this in the global namespace
|
// 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)
|
// (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>
|
template <class T, auto Free = std::free>
|
||||||
using CUnique = Unique<T, UniqueCDeleter<T, Free>>;
|
using CUnique = Unique<T, UniqueCDeleter<T, Free>>;
|
||||||
|
|
||||||
} // namespace base
|
} // namespace util
|
||||||
|
|||||||
3
tools/format.sh
Executable file
3
tools/format.sh
Executable 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 "{}"
|
||||||
Reference in New Issue
Block a user