Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
179ca4e39118fef577a7b0eb00df21dbe260ab89
[simgrid.git] / src / mc / explo / udpor / CompatibilityGraph.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/CompatibilityGraph.hpp"
7
8 #include <stdexcept>
9
10 namespace simgrid::mc::udpor {
11
12 // TODO: Remove duplication between the CompatibilityGraph
13 // and the Unfolding: they are practically identical
14
15 void CompatibilityGraph::remove(CompatibilityGraphNode* e)
16 {
17   if (e == nullptr) {
18     throw std::invalid_argument("Expected a non-null pointer to an event, but received NULL");
19   }
20   this->nodes.erase(e);
21 }
22
23 void CompatibilityGraph::insert(std::unique_ptr<CompatibilityGraphNode> e)
24 {
25   CompatibilityGraphNode* handle = e.get();
26   auto loc                       = this->nodes.find(handle);
27   if (loc != this->nodes.end()) {
28     // This is bad: someone wrapped the raw event address twice
29     // in two different unique ptrs and attempted to
30     // insert it into the unfolding...
31     throw std::invalid_argument("Attempted to insert a node owned twice."
32                                 "This will result in a  double free error and must be fixed.");
33   }
34
35   // Map the handle to its owner
36   this->nodes[handle] = std::move(e);
37 }
38
39 } // namespace simgrid::mc::udpor