]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/base/YesNoNone.h
e9f1cf953e8a990732646b3ac03313c7f73e7071
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_YESNONONE_H_
10 #define SQUID_YESNONONE_H_
12 #include "base/TextException.h"
14 // TODO: generalize / template to non-boolean option types
15 // and make YesNoNone the boolean instance of the template
18 * Used for boolean enabled/disabled options with complex default logic.
19 * Allows Squid to compute the right default after configuration.
20 * Checks that not-yet-defined option values are not used.
21 * Allows for implicit default Yes/No values to be used by initialization
22 * without configure() being called, but not dumped as squid.conf content.
24 * Use x.configure(bool) when the value is configured.
25 * Use x.defaultTo(bool) to assign defaults.
29 enum SetHow
: uint8_t { optUnspecified
= 0, optImplicitly
= 1, optConfigured
= 2 };
32 // this constructor initializes to 'unspecified' state
34 setHow_(optUnspecified
),
38 // this constructor initializes to 'implicit' state
39 explicit YesNoNone(bool beSet
):
40 setHow_(optImplicitly
),
44 /// the boolean equivalent of the value stored.
45 /// asserts if the value has not been set.
46 explicit operator bool() const {
47 Must(setHow_
!= optUnspecified
);
51 /// enables or disables the option; updating to 'configured' state
52 void configure(bool beSet
) {
53 setHow_
= optConfigured
;
57 /// enables or disables the option; updating to 'implicit' state
58 void defaultTo(bool beSet
) {
59 Must(setHow_
!= optConfigured
);
60 setHow_
= optImplicitly
;
64 /// whether the option was enabled or disabled,
65 /// by squid.conf values resulting in explicit configure() usage.
66 bool configured() const {return setHow_
== optConfigured
;}
69 SetHow setHow_
; ///< how the option was set
70 bool option
; ///< specified yes/no value; meaningless if optUnspecified
73 #endif /* SQUID_YESNONONE_H_ */