Files
2026-11-03 15:22:24 -03:00

67 lines
2.4 KiB
C++

#pragma once
#include <string_view>
/**
* @file Status.hpp
* @brief hot_reload::Status -- the C++ API's outcome code, and toString() for logging it.
*
* Carries the same meaning as hot_reload.h's `HotReloadStatus`, which exists side by side with
* this one: the plain C API is a wrapper around the C++ API this file is part of (see
* `Context.hpp`), not the other way around, but both are supported, stable public surfaces --
* `HotReloadStatus`'s own values are not going away. A Status is never constructed on its own;
* see Result.hpp for the type that actually carries one back from a call.
*/
namespace hot_reload
{
/**
* @brief The outcome of a Context::load() or Context::reload() call.
*
* @see Result, which pairs a Status with the human-readable message a failure deserves.
*/
enum class Status
{
/** The call did exactly what it says: loaded, or diffed-and-patched. */
Ok,
/**
* A required argument was empty or otherwise invalid, or Context::load() was called for
* a module name that is already loaded -- call Context::reload() for that name instead.
*/
InvalidArgument,
/**
* The platform could not load the image at all. Result::message() carries the
* platform's own explanation -- this one status covers everything from a missing file,
* to a genuinely corrupt image, to a shared library with an unresolved symbol
* reference, and those need very different fixes. On Context::reload(), this is
* non-destructive: the previously loaded version is left running untouched, exactly as
* if reload had not been called.
*/
LoadFailed,
/** Context::reload() was called for a module name nothing has ever loaded. */
NoPreviousVersion,
/**
* This process's CPU architecture has no patch backend compiled in (see
* `Architecture.hpp` -- currently x86, x86-64, ARM64, and ARM32). Nothing was patched;
* Context::load() still succeeded, you just cannot Context::reload() on this target.
*/
UnsupportedArchitecture,
};
/**
* @brief A short, human-readable label for @p status, suitable for logging.
*
* The C API's equivalent, `hot_reload_status_string()`, calls this.
*
* @param status The status to describe.
* @return A `string_view` into a static string -- valid for the life of the program, safe to
* copy out or hold onto indefinitely, never null.
*/
[[nodiscard]] std::string_view toString(Status status) noexcept;
}