ChampSim
repeatable.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 The ChampSim Contributors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef REPEATABLE_H
18 #define REPEATABLE_H
19 
20 #include <memory>
21 #include <string>
22 
23 #include "instruction.h"
24 #include <fmt/ranges.h>
25 
26 namespace champsim
27 {
28 template <typename T, typename... Args>
29 struct repeatable {
30  static_assert(std::is_move_constructible_v<T>);
31  static_assert(std::is_move_assignable_v<T>);
32  std::tuple<Args...> args_;
33  T intern_{std::apply([](auto... x) { return T{x...}; }, args_)};
34  explicit repeatable(Args... args) : args_(args...) {}
35 
36  auto operator()()
37  {
38  // Reopen trace if we've reached the end of the file
39  if (intern_.eof()) {
40  fmt::print("*** Reached end of trace: {}\n", args_);
41  intern_ = T{std::apply([](auto... x) { return T{x...}; }, args_)};
42  }
43 
44  return intern_();
45  }
46 
47  bool eof() const { return false; }
48 };
49 } // namespace champsim
50 
51 #endif
Definition: champsim.h:24
Definition: repeatable.h:29
T intern_
Definition: repeatable.h:33
auto operator()()
Definition: repeatable.h:36
bool eof() const
Definition: repeatable.h:47
std::tuple< Args... > args_
Definition: repeatable.h:30
repeatable(Args... args)
Definition: repeatable.h:34