PerScheduleContainer.h
Go to the documentation of this file.
1 #ifndef art_Utilities_PerScheduleContainer_h
2 #define art_Utilities_PerScheduleContainer_h
3 // vim: set sw=2 expandtab :
4 
8 
9 #include <utility>
10 #include <vector>
11 
12 namespace art {
13 
14  template <typename T>
16 
17  static_assert(ScheduleID::first().id() == 0);
18 
19  public:
20  PerScheduleContainer() = default;
22 
23  bool
24  is_valid() const
25  {
26  return !data_.empty();
27  }
28 
29  auto
30  size() const
31  {
32  return data_.size();
33  }
34 
35  auto
36  cbegin() const noexcept
37  {
38  return data_.cbegin();
39  }
40 
41  auto
42  begin() const noexcept
43  {
44  return data_.begin();
45  }
46 
47  auto
48  begin() noexcept
49  {
50  return data_.begin();
51  }
52 
53  auto
54  cend() const noexcept
55  {
56  return data_.cend();
57  }
58 
59  auto
60  end() const noexcept
61  {
62  return data_.end();
63  }
64 
65  auto
66  end() noexcept
67  {
68  return data_.end();
69  }
70 
71  // FIXME: Should remove once we replace this with a mappish thing.
72  void
74  {
75  data_.reserve(sz);
76  }
77 
78  // FIXME: Should replace emplace_back with emplace
79  template <typename... Args>
80  void
81  emplace_back(Args&&... args)
82  {
83  data_.emplace_back(std::forward<Args>(args)...);
84  }
85 
86  void
88  {
89  if (is_valid()) {
91  "An error occurred while calling "
92  "PerScheduleContainer::expand_to_num_schedules"}
93  << "Can only call resize when the container is invalid.\n";
94  }
95  data_.resize(sz);
96  }
97 
98  auto
100  {
101  if (is_valid()) {
103  "An error occurred while calling "
104  "PerScheduleContainer::expand_to_num_schedules"}
105  << "Can only call expand_to_num_schedules when the "
106  "container is invalid.";
107  }
108  auto const n = Globals::instance()->nschedules();
109  data_.resize(n);
110  return n;
111  }
112 
113  T& operator[](ScheduleID const sid) { return data_[sid.id()]; }
114 
115  T const& operator[](ScheduleID const sid) const { return data_[sid.id()]; }
116 
117  T&
118  at(ScheduleID const sid)
119  {
120  return data_.at(sid.id());
121  }
122 
123  T const&
124  at(ScheduleID const sid) const
125  {
126  return data_.at(sid.id());
127  }
128 
129  private:
130  std::vector<T> data_;
131  };
132 
133 } // namespace art
134 
135 #endif /* art_Utilities_PerScheduleContainer_h */
136 
137 // Local Variables:
138 // mode: c++
139 // End:
T const & at(ScheduleID const sid) const
void emplace_back(Args &&...args)
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
static QCString args
Definition: declinfo.cpp:674
auto begin() const noexcept
T & at(ScheduleID const sid)
auto cbegin() const noexcept
ScheduleID::size_type nschedules() const
Definition: Globals.cc:24
std::void_t< T > n
T const & operator[](ScheduleID const sid) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr id_type id() const noexcept
Definition: ScheduleID.h:77
id_type size_type
Definition: ScheduleID.h:25
void reserve(ScheduleID::size_type const sz)
auto end() const noexcept
PerScheduleContainer(ScheduleID::size_type const n)
static Globals * instance()
Definition: Globals.cc:17
void resize(ScheduleID::size_type const sz)
auto cend() const noexcept
T & operator[](ScheduleID const sid)