Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / mc / explo / udpor / Configuration.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/Configuration.hpp"
7 #include "src/mc/explo/udpor/History.hpp"
8
9 #include <algorithm>
10 #include <stdexcept>
11
12 namespace simgrid::mc::udpor {
13
14 Configuration::Configuration(std::initializer_list<UnfoldingEvent*> events) : Configuration(EventSet(std::move(events)))
15 {
16 }
17
18 Configuration::Configuration(EventSet events) : events_(events)
19 {
20   if (!events_.is_valid_configuration()) {
21     throw std::invalid_argument("The events do not form a valid configuration");
22   }
23 }
24
25 void Configuration::add_event(UnfoldingEvent* e)
26 {
27   if (e == nullptr) {
28     throw std::invalid_argument("Expected a nonnull `UnfoldingEvent*` but received NULL instead");
29   }
30
31   if (this->events_.contains(e)) {
32     return;
33   }
34
35   this->events_.insert(e);
36   this->newest_event = e;
37
38   // Preserves the property that the configuration is valid
39   History history(e);
40   if (!this->events_.contains(history)) {
41     throw std::invalid_argument("The newly added event has dependencies "
42                                 "which are missing from this configuration");
43   }
44 }
45
46 } // namespace simgrid::mc::udpor