aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/Bookmark.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-01-22 21:02:58 +0100
committer hop311 <hop3114@gmail.com>2024-01-23 23:14:53 +0100
commit268a6948c0400905dfc335427395519689f067f5 (patch)
treeb30e9b5774130552fe97e27deaf0370d83920c43 /src/openvic-simulation/history/Bookmark.cpp
parentd4e597da089a81f719a9c33b46111d1c2c590124 (diff)
Added reserve_more, expect_dictionary_key[s|_map]_reserve_length[_and_default]reserve_more
Diffstat (limited to 'src/openvic-simulation/history/Bookmark.cpp')
-rw-r--r--src/openvic-simulation/history/Bookmark.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp
index b758867..ee7b494 100644
--- a/src/openvic-simulation/history/Bookmark.cpp
+++ b/src/openvic-simulation/history/Bookmark.cpp
@@ -23,27 +23,30 @@ bool BookmarkManager::add_bookmark(
}
bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) {
- const bool ret = expect_dictionary([this](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key != "bookmark") {
- Logger::error("Invalid bookmark declaration ", key);
- return false;
+ const bool ret = expect_dictionary_reserve_length(
+ bookmarks,
+ [this](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key != "bookmark") {
+ Logger::error("Invalid bookmark declaration ", key);
+ return false;
+ }
+
+ std::string_view name, description;
+ Date date;
+ uint32_t initial_camera_x, initial_camera_y;
+
+ bool ret = expect_dictionary_keys(
+ "name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
+ "desc", ONE_EXACTLY, expect_string(assign_variable_callback(description)),
+ "date", ONE_EXACTLY, expect_date(assign_variable_callback(date)),
+ "cameraX", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_x)),
+ "cameraY", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_y))
+ )(value);
+
+ ret &= add_bookmark(name, description, date, initial_camera_x, initial_camera_y);
+ return ret;
}
-
- std::string_view name, description;
- Date date;
- uint32_t initial_camera_x, initial_camera_y;
-
- bool ret = expect_dictionary_keys(
- "name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
- "desc", ONE_EXACTLY, expect_string(assign_variable_callback(description)),
- "date", ONE_EXACTLY, expect_date(assign_variable_callback(date)),
- "cameraX", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_x)),
- "cameraY", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_y))
- )(value);
-
- ret &= add_bookmark(name, description, date, initial_camera_x, initial_camera_y);
- return ret;
- })(root);
+ )(root);
lock_bookmarks();
return ret;