]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // Copyright 2015-2019 Hans Dembinski |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE_1_0.txt | |
5 | // or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_HISTOGRAM_AXIS_OPTION_HPP | |
8 | #define BOOST_HISTOGRAM_AXIS_OPTION_HPP | |
9 | ||
10 | #include <type_traits> | |
11 | ||
12 | /** | |
13 | \file option.hpp Options for builtin axis types. | |
14 | ||
15 | Options `circular` and `growth` are mutually exclusive. | |
16 | Options `circular` and `underflow` are mutually exclusive. | |
17 | */ | |
18 | ||
19 | namespace boost { | |
20 | namespace histogram { | |
21 | namespace axis { | |
22 | namespace option { | |
23 | ||
24 | /// Holder of axis options. | |
25 | template <unsigned Bits> | |
26 | struct bitset : std::integral_constant<unsigned, Bits> { | |
20effc67 | 27 | |
92f5a8d4 TL |
28 | /// Returns true if all option flags in the argument are set and false otherwise. |
29 | template <unsigned B> | |
30 | static constexpr auto test(bitset<B>) { | |
20effc67 TL |
31 | // B + 0 needed to avoid false positive -Wtautological-compare in gcc-6 |
32 | return std::integral_constant<bool, static_cast<bool>((Bits & B) == (B + 0))>{}; | |
92f5a8d4 TL |
33 | } |
34 | }; | |
35 | ||
36 | /// Set union of the axis option arguments. | |
37 | template <unsigned B1, unsigned B2> | |
38 | constexpr auto operator|(bitset<B1>, bitset<B2>) { | |
39 | return bitset<(B1 | B2)>{}; | |
40 | } | |
41 | ||
42 | /// Set intersection of the option arguments. | |
43 | template <unsigned B1, unsigned B2> | |
44 | constexpr auto operator&(bitset<B1>, bitset<B2>) { | |
45 | return bitset<(B1 & B2)>{}; | |
46 | } | |
47 | ||
48 | /// Set difference of the option arguments. | |
49 | template <unsigned B1, unsigned B2> | |
50 | constexpr auto operator-(bitset<B1>, bitset<B2>) { | |
51 | return bitset<(B1 & ~B2)>{}; | |
52 | } | |
53 | ||
54 | /** | |
55 | Single option flag. | |
56 | ||
57 | @tparam Pos position of the bit in the set. | |
58 | */ | |
59 | template <unsigned Pos> | |
1e59de90 TL |
60 | #ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED |
61 | using bit = bitset<(1 << Pos)>; | |
62 | #else | |
63 | struct bit; | |
64 | #endif | |
92f5a8d4 TL |
65 | |
66 | /// All options off. | |
67 | using none_t = bitset<0>; | |
92f5a8d4 TL |
68 | /// Axis has an underflow bin. Mutually exclusive with `circular`. |
69 | using underflow_t = bit<0>; | |
92f5a8d4 TL |
70 | /// Axis has overflow bin. |
71 | using overflow_t = bit<1>; | |
92f5a8d4 TL |
72 | /// Axis is circular. Mutually exclusive with `growth` and `underflow`. |
73 | using circular_t = bit<2>; | |
92f5a8d4 TL |
74 | /// Axis can grow. Mutually exclusive with `circular`. |
75 | using growth_t = bit<3>; | |
20effc67 TL |
76 | |
77 | constexpr none_t none{}; ///< Instance of `none_t`. | |
78 | constexpr underflow_t underflow{}; ///< Instance of `underflow_t`. | |
79 | constexpr overflow_t overflow{}; ///< Instance of `overflow_t`. | |
80 | constexpr circular_t circular{}; ///< Instance of `circular_t`. | |
81 | constexpr growth_t growth{}; ///< Instance of `growth_t`. | |
92f5a8d4 TL |
82 | |
83 | } // namespace option | |
84 | } // namespace axis | |
85 | } // namespace histogram | |
86 | } // namespace boost | |
87 | ||
88 | #endif |