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 "app/rom.h"
7
8namespace yaze {
9namespace editor {
10
11// Macro for checking ROM loading state in editor methods
12#define REQUIRE_ROM_LOADED(rom_ptr, operation) \
13 do { \
14 if (!(rom_ptr) || !(rom_ptr)->is_loaded()) { \
15 return absl::FailedPreconditionError( \
16 absl::StrFormat("%s: ROM not loaded", (operation))); \
17 } \
18 } while (0)
19
20// Macro for ROM state checking with custom error message
21#define CHECK_ROM_STATE(rom_ptr, message) \
22 do { \
23 if (!(rom_ptr) || !(rom_ptr)->is_loaded()) { \
24 return absl::FailedPreconditionError(message); \
25 } \
26 } while (0)
27
28// Helper function for generating consistent ROM status messages
29inline std::string GetRomStatusMessage(const Rom* rom) {
30 if (!rom) return "No ROM loaded";
31 if (!rom->is_loaded()) return "ROM failed to load";
32 return absl::StrFormat("ROM loaded: %s", rom->title());
33}
34
35// Helper function to check if ROM is in a valid state for editing
36inline bool IsRomReadyForEditing(const Rom* rom) {
37 return rom && rom->is_loaded() && !rom->title().empty();
38}
39
40} // namespace editor
41} // namespace yaze
42
43#endif // YAZE_APP_EDITOR_SAFEGUARDS_H
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
bool is_loaded() const
Definition rom.h:197
auto title() const
Definition rom.h:201
std::string GetRomStatusMessage(const Rom *rom)
bool IsRomReadyForEditing(const Rom *rom)
Main namespace for the application.