1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "src/mc/explo/udpor/StateManager.hpp"
7 #include "xbt/asserts.h"
9 namespace simgrid::mc::udpor {
11 StateManager::Handle StateManager::record_state(std::unique_ptr<State> state)
13 if (state.get() == nullptr) {
14 throw std::invalid_argument("Expected a newly-allocated State but got NULL instead");
17 const auto integer_handle = this->current_handle_;
18 this->state_map_.insert({integer_handle, std::move(state)});
20 this->current_handle_++;
21 xbt_assert(integer_handle <= this->current_handle_, "Too many states were vended out during exploration via UDPOR.\n"
22 "It's suprising you didn't run out of memory elsewhere first...\n"
23 "Please report this as a bug along with the very large program");
25 return integer_handle;
28 std::optional<std::reference_wrapper<State>> StateManager::get_state(StateManager::Handle handle)
30 auto state = this->state_map_.find(handle);
31 if (state == this->state_map_.end()) {
34 auto& state_ref = *state->second.get();
35 return std::optional<std::reference_wrapper<State>>{state_ref};
38 } // namespace simgrid::mc::udpor