Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In C++, classes don't need a name because they have a class
[simgrid.git] / src / kernel / EngineImpl.cpp
1 /* Copyright (c) 2016-2019. 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/kernel/EngineImpl.hpp"
7 #include "simgrid/kernel/routing/NetPoint.hpp"
8 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
9 #include "simgrid/s4u/Host.hpp"
10 #include "src/surf/StorageImpl.hpp"
11 #include "src/surf/network_interface.hpp"
12
13 #include <algorithm>
14
15 namespace simgrid {
16 namespace kernel {
17
18 EngineImpl::EngineImpl() = default;
19 EngineImpl::~EngineImpl()
20 {
21   /* copy all names to not modify the map while iterating over it.
22    *
23    * Plus, the hosts are destroyed in the lexicographic order to ensure
24    * that the output is reproducible: we don't want to kill them in the
25    * pointer order as it could be platform-dependent, which would break
26    * the tests.
27    */
28   std::vector<std::string> names;
29   for (auto const& kv : hosts_)
30     names.push_back(kv.second->get_name());
31
32   std::sort(names.begin(), names.end());
33
34   for (auto const& name : names)
35     hosts_.at(name)->destroy();
36
37   /* Also delete the other data */
38   delete netzone_root_;
39   for (auto const& kv : netpoints_)
40     delete kv.second;
41
42   for (auto const& kv : storages_)
43     if (kv.second)
44       kv.second->get_impl()->destroy();
45
46   for (auto const& kv : links_)
47     if (kv.second)
48       kv.second->get_impl()->destroy();
49 }
50 }
51 }