LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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
26  (FlagIndex_t flagIndex) const
27  { return flagIndex < This_t::size(); }
28 
29 //------------------------------------------------------------------------------
30 template <unsigned int NFlags, typename Storage>
31 constexpr bool util::flags::FlagSet<NFlags, Storage>::isFlag(Flag_t flag) const
32  { return isFlag(flag.index()); }
33 
34 //------------------------------------------------------------------------------
35 template <unsigned int NFlags, typename Storage>
36 bool util::flags::FlagSet<NFlags, Storage>::test(FlagIndex_t index) const {
37  if (!isFlag(index)) {
38  throw OutOfRangeError
39  ("Invalid flag index was tested: #" + std::to_string(index));
40  }
41  return This_t::testImpl(index);
42 } // util::flags::FlagSet<>::test()
43 
44 //------------------------------------------------------------------------------
45 template <unsigned int NFlags, typename Storage>
46 bool util::flags::FlagSet<NFlags, Storage>::test(Flag_t flag) const {
47  if (!isFlag(flag)) {
48  throw OutOfRangeError
49  ("Invalid flag was tested: #" + util::flags::to_string(flag));
50  }
51  return testImpl(flag);
52 } // util::flags::FlagSet<>::test()
53 
54 
55 //------------------------------------------------------------------------------
56 template <unsigned int NFlags, typename Storage>
57 bool util::flags::FlagSet<NFlags, Storage>::testImpl(Flag_t flag) const {
58  if (!This_t::isDefined(flag)) {
59  throw FlagNotDefinedError
60  ("Undefined flag was tested: #" + util::flags::to_string(flag));
61  }
62  return This_t::get(flag);
63 } // util::flags::FlagSet<>::testImpl()
64 
65 //------------------------------------------------------------------------------
66 
67 
68 #endif // LARDATAOBJ_UTILITIES_FLAGSET_TCC