Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Context.hpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2022 Reactive Markets Limited
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#ifndef TOOLBOX_BM_CONTEXT
17#define TOOLBOX_BM_CONTEXT
18
19#include <toolbox/bm/Range.hpp>
21
22namespace toolbox::bm {
23
25 public:
26 explicit Context(Histogram& hist)
27 : hist_{hist}
28 {
29 }
30 ~Context() = default;
31
32 // Copy.
33 Context(const Context&) = delete;
34 Context& operator=(const Context&) = delete;
35
36 // Move.
37 Context(Context&&) = delete;
39
40 explicit operator bool() const noexcept { return !stop_; }
41 BenchmarkRange range(int first, int last) const noexcept { return {hist_, first, last}; }
42 BenchmarkRange range(int count) const noexcept { return {hist_, 0, count}; }
43
44 void stop() noexcept { stop_ = true; }
45
46 private:
47 Histogram& hist_;
48 std::atomic_bool stop_{false};
49};
50
51} // namespace toolbox::bm
52
53#endif // TOOLBOX_BM_CONTEXT
#define TOOLBOX_API
Definition Config.h:39
Context & operator=(const Context &)=delete
Context(Context &&)=delete
Context(const Context &)=delete
BenchmarkRange range(int count) const noexcept
Definition Context.hpp:42
void stop() noexcept
Definition Context.hpp:44
BenchmarkRange range(int first, int last) const noexcept
Definition Context.hpp:41
Context & operator=(Context &&)=delete
Context(Histogram &hist)
Definition Context.hpp:26
A High Dynamic Range (HDR) Histogram.
Definition Histogram.hpp:64