Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remove remaining bits of parmap in MC (not used)
[simgrid.git] / src / mc / ChunkedData.hpp
1 /* Copyright (c) 2014-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_CHUNKED_DATA_HPP
8 #define SIMGRID_MC_CHUNKED_DATA_HPP
9
10 #include <cstddef>
11 #include <cstdint>
12
13 #include <utility>
14 #include <vector>
15
16 #include "src/mc/mc_forward.hpp"
17 #include "src/mc/AddressSpace.hpp"
18 #include "src/mc/PageStore.hpp"
19
20 namespace simgrid {
21 namespace mc {
22
23 /** A byte-string represented as a sequence of chunks from a PageStor */
24 class ChunkedData {
25   PageStore* store_ = nullptr;
26   /** Indices of the chunks */
27   std::vector<std::size_t> pagenos_;
28 public:
29
30   ChunkedData() {}
31   void clear()
32   {
33     for (std::size_t pageno : pagenos_)
34       store_->unref_page(pageno);
35     pagenos_.clear();
36   }
37   ~ChunkedData()
38   {
39     clear();
40   }
41
42   // Copy and move
43   ChunkedData(ChunkedData const& that)
44   {
45     store_ = that.store_;
46     pagenos_ = that.pagenos_;
47     for (std::size_t pageno : pagenos_)
48       store_->ref_page(pageno);
49   }
50   ChunkedData(ChunkedData&& that)
51   {
52     store_ = that.store_;
53     that.store_ = nullptr;
54     pagenos_ = std::move(that.pagenos_);
55     that.pagenos_.clear();
56   }
57   ChunkedData& operator=(ChunkedData const& that)
58   {
59     this->clear();
60     store_ = that.store_;
61     pagenos_ = that.pagenos_;
62     for (std::size_t pageno : pagenos_)
63       store_->ref_page(pageno);
64     return *this;
65   }
66   ChunkedData& operator=(ChunkedData && that)
67   {
68     this->clear();
69     store_ = that.store_;
70     that.store_ = nullptr;
71     pagenos_ = std::move(that.pagenos_);
72     that.pagenos_.clear();
73     return *this;
74   }
75
76   std::size_t page_count()          const { return pagenos_.size(); }
77   std::size_t pageno(std::size_t i) const { return pagenos_[i]; }
78   const std::size_t* pagenos()      const { return pagenos_.data(); }
79
80   const void* page(std::size_t i) const
81   {
82     return store_->get_page(pagenos_[i]);
83   }
84
85   ChunkedData(PageStore& store, AddressSpace& as,
86     RemotePtr<void> addr, std::size_t page_count,
87     const std::size_t* ref_page_numbers, const std::uint64_t* pagemap);
88 };
89
90 }
91 }
92
93 #endif