3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Declares gmx::FlagsTemplate.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_utility
39 #ifndef GMX_UTILITY_FLAGS_H
40 #define GMX_UTILITY_FLAGS_H
46 * Template class for typesafe handling of combination of flags.
48 * \tparam T An enumerated type that holds the possible single flags.
50 * This class is not used publicly, but is present in an installed header
51 * because it is used internally in public template classes.
54 * \ingroup module_utility
60 //! Creates a flags object with no flags set.
61 FlagsTemplate() : flags_(0) {}
62 //! Creates a flags object from a single flag.
63 FlagsTemplate(T flag) : flags_(flag) {}
65 //! Returns true if the given flag is set.
66 bool test(T flag) const { return flags_ & flag; }
68 void clearAll() { flags_ = 0; }
69 //! Sets the given flag.
70 void set(T flag) { flags_ |= flag; }
71 //! Clears the given flag.
72 void clear(T flag) { flags_ &= ~flag; }
73 //! Sets or clears the given flag.
74 void set(T flag, bool bSet)
86 //! Combines flags from two flags objects.
87 FlagsTemplate<T> operator|(const FlagsTemplate<T> &other) const
89 return FlagsTemplate<T>(flags_ | other.flags_);
91 //! Combines flags from another flag object.
92 FlagsTemplate<T> &operator|=(const FlagsTemplate<T> &other)
94 flags_ |= other.flags_;
97 //! Combined flags from two flags objects.
98 FlagsTemplate<T> operator&(const FlagsTemplate<T> &other) const
100 return FlagsTemplate<T>(flags_ & other.flags_);
102 //! Returns an object with all flags flipped.
103 FlagsTemplate<T> operator~() const
105 return FlagsTemplate<T>(~flags_);
109 //! Creates a flags object with the given flags.
110 explicit FlagsTemplate(unsigned long flags) : flags_(flags) {}
112 unsigned long flags_;