]> git.ipfire.org Git - thirdparty/squid.git/blob - src/YesNoNone.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / YesNoNone.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_YESNONONE_H_
10 #define SQUID_YESNONONE_H_
11
12 /// Used for boolean enabled/disabled options with complex default logic.
13 /// Allows Squid to compute the right default after configuration.
14 /// Checks that not-yet-defined option values are not used.
15 class YesNoNone
16 {
17 // TODO: generalize to non-boolean option types
18 public:
19 YesNoNone(): option(0) {}
20
21 /// returns true iff enabled; asserts if the option has not been configured
22 operator void *() const; // TODO: use a fancy/safer version of the operator
23
24 /// enables or disables the option;
25 void configure(bool beSet);
26
27 /// whether the option was enabled or disabled, by user or Squid
28 bool configured() const { return option != 0; }
29
30 private:
31 enum { optUnspecified = -1, optDisabled = 0, optEnabled = 1 };
32 int option; ///< configured value or zero
33 };
34
35 #endif /* SQUID_YESNONONE_H_ */
36