Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to fix stack handling
[simgrid.git] / src / mc / explo / udpor / Unfolding.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/Unfolding.hpp"
7
8 #include <stdexcept>
9
10 namespace simgrid::mc::udpor {
11
12 void Unfolding::remove(const UnfoldingEvent* e)
13 {
14   if (e == nullptr) {
15     throw std::invalid_argument("Expected a non-null pointer to an event, but received NULL");
16   }
17   this->global_events_.erase(e);
18 }
19
20 void Unfolding::insert(std::unique_ptr<UnfoldingEvent> e)
21 {
22   const UnfoldingEvent* handle = e.get();
23   if (auto loc = this->global_events_.find(handle); loc != this->global_events_.end()) {
24     // This is bad: someone wrapped the raw event address twice
25     // in two different unique ptrs and attempted to
26     // insert it into the unfolding...
27     throw std::invalid_argument("Attempted to insert an unfolding event owned twice."
28                                 "This will result in a  double free error and must be fixed.");
29   }
30
31   // Map the handle to its owner
32   this->global_events_[handle] = std::move(e);
33 }
34
35 bool Unfolding::contains_event_equivalent_to(const UnfoldingEvent* e) const
36 {
37   // Notice the use of `==` equality here. `e` may not be contained in the
38   // unfolding; but some event which is "equivalent" to it could be.
39   for (const auto& [event, _] : global_events_) {
40     if (*event == *e) {
41       return true;
42     }
43   }
44   return false;
45 }
46
47 } // namespace simgrid::mc::udpor