Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add first batch of tests for UDPOR
[simgrid.git] / src / mc / explo / udpor / StateManager.cpp
1 /* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "src/mc/explo/udpor/StateManager.hpp"
7 #include "xbt/asserts.h"
8
9 namespace simgrid::mc::udpor {
10
11 StateManager::Handle StateManager::record_state(std::unique_ptr<State> state)
12 {
13   if (state.get() == nullptr) {
14     throw std::invalid_argument("Expected a newly-allocated State but got NULL instead");
15   }
16
17   const auto integer_handle = this->current_handle_;
18   this->state_map_.insert({integer_handle, std::move(state)});
19
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");
24
25   return integer_handle;
26 }
27
28 std::optional<std::reference_wrapper<State>> StateManager::get_state(StateManager::Handle handle)
29 {
30   auto state = this->state_map_.find(handle);
31   if (state == this->state_map_.end()) {
32     return std::nullopt;
33   }
34   auto& state_ref = *state->second.get();
35   return std::optional<std::reference_wrapper<State>>{state_ref};
36 }
37
38 } // namespace simgrid::mc::udpor