LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FlagSet.tcc
Go to the documentation of this file.
1 /**
2  * @file FlagSet.tcc
3  * @brief Class holding flags.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date January 25, 2017
6  * @see FlagSet.h
7  *
8  */
9 
10 #ifndef LARDATAOBJ_UTILITIES_FLAGSET_TCC
11 #define LARDATAOBJ_UTILITIES_FLAGSET_TCC
12 
13 #ifndef LARDATAOBJ_UTILITIES_FLAGSET_H
14 #error "Do not include FlagSet.tcc directly: include FlagSet.h instead."
15 #endif // !LARDATAOBJ_UTILITIES_FLAGSET_H
16 
17 #include <stdexcept>
18 
19 //------------------------------------------------------------------------------
20 //--- FlagSet<>
21 //---
22 
23 //------------------------------------------------------------------------------
24 template <unsigned int NFlags, typename Storage>
25 constexpr bool util::flags::FlagSet<NFlags, Storage>::isFlag(FlagIndex_t flagIndex) const
26 {
27  return flagIndex < This_t::size();
28 }
29 
30 //------------------------------------------------------------------------------
31 template <unsigned int NFlags, typename Storage>
32 constexpr bool util::flags::FlagSet<NFlags, Storage>::isFlag(Flag_t flag) const
33 {
34  return isFlag(flag.index());
35 }
36 
37 //------------------------------------------------------------------------------
38 template <unsigned int NFlags, typename Storage>
39 bool util::flags::FlagSet<NFlags, Storage>::test(FlagIndex_t index) const
40 {
41  if (!isFlag(index)) {
42  throw OutOfRangeError("Invalid flag index was tested: #" + std::to_string(index));
43  }
44  return This_t::testImpl(index);
45 } // util::flags::FlagSet<>::test()
46 
47 //------------------------------------------------------------------------------
48 template <unsigned int NFlags, typename Storage>
49 bool util::flags::FlagSet<NFlags, Storage>::test(Flag_t flag) const
50 {
51  if (!isFlag(flag)) {
52  throw OutOfRangeError("Invalid flag was tested: #" + util::flags::to_string(flag));
53  }
54  return testImpl(flag);
55 } // util::flags::FlagSet<>::test()
56 
57 //------------------------------------------------------------------------------
58 template <unsigned int NFlags, typename Storage>
59 bool util::flags::FlagSet<NFlags, Storage>::testImpl(Flag_t flag) const
60 {
61  if (!This_t::isDefined(flag)) {
62  throw FlagNotDefinedError("Undefined flag was tested: #" + util::flags::to_string(flag));
63  }
64  return This_t::get(flag);
65 } // util::flags::FlagSet<>::testImpl()
66 
67 //------------------------------------------------------------------------------
68 
69 #endif // LARDATAOBJ_UTILITIES_FLAGSET_TCC