yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
editor_safeguards.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_SAFEGUARDS_H
2#define YAZE_APP_EDITOR_SAFEGUARDS_H
3
4#include "absl/status/status.h"
5#include "absl/strings/str_format.h"
6#include "rom/rom.h"
7
8namespace yaze {
9namespace editor {
10
11// Helper function to check if ROM is loaded and return error if not
12inline absl::Status RequireRomLoaded(const Rom* rom, const std::string& operation) {
13 if (!rom || !rom->is_loaded()) {
14 return absl::FailedPreconditionError(
15 absl::StrFormat("%s: ROM not loaded", operation));
16 }
17 return absl::OkStatus();
18}
19
20// Helper function to check ROM state with custom message
21inline absl::Status CheckRomState(const Rom* rom, const std::string& message) {
22 if (!rom || !rom->is_loaded()) {
23 return absl::FailedPreconditionError(message);
24 }
25 return absl::OkStatus();
26}
27
28// Helper function for generating consistent ROM status messages
29inline std::string GetRomStatusMessage(const Rom* rom) {
30 if (!rom)
31 return "No ROM loaded";
32 if (!rom->is_loaded())
33 return "ROM failed to load";
34 return absl::StrFormat("ROM loaded: %s", rom->title());
35}
36
37// Helper function to check if ROM is in a valid state for editing
38inline bool IsRomReadyForEditing(const Rom* rom) {
39 return rom && rom->is_loaded() && !rom->title().empty();
40}
41
42} // namespace editor
43} // namespace yaze
44
45#endif // YAZE_APP_EDITOR_SAFEGUARDS_H
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
bool is_loaded() const
Definition rom.h:128
auto title() const
Definition rom.h:133
std::string GetRomStatusMessage(const Rom *rom)
absl::Status CheckRomState(const Rom *rom, const std::string &message)
absl::Status RequireRomLoaded(const Rom *rom, const std::string &operation)
bool IsRomReadyForEditing(const Rom *rom)