YesNoNone.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 #include "base/TextException.h"
13 #include "Debug.h"
14 
15 // TODO: generalize / template to non-boolean option types
16 // and make YesNoNone the boolean instance of the template
17 
28 class YesNoNone
29 {
30  enum SetHow : uint8_t { optUnspecified = 0, optImplicitly = 1, optConfigured = 2 };
31 
32 public:
33  // this constructor initializes to 'unspecified' state
36  option(false)
37  {}
38 
39  // this constructor initializes to 'implicit' state
40  explicit YesNoNone(bool beSet):
42  option(beSet)
43  {}
44 
47  explicit operator bool() const {
49  return option;
50  }
51 
53  void configure(bool beSet) {
55  option = beSet;
56  }
57 
59  void defaultTo(bool beSet) {
62  option = beSet;
63  }
64 
67  bool configured() const {return setHow_ == optConfigured;}
68 
69 private:
71  bool option;
72 };
73 
74 #endif /* SQUID_YESNONONE_H_ */
75 
YesNoNone()
Definition: YesNoNone.h:34
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
bool configured() const
Definition: YesNoNone.h:67
bool option
specified yes/no value; meaningless if optUnspecified
Definition: YesNoNone.h:71
void configure(bool beSet)
enables or disables the option; updating to 'configured' state
Definition: YesNoNone.h:53
YesNoNone(bool beSet)
Definition: YesNoNone.h:40
SetHow setHow_
how the option was set
Definition: YesNoNone.h:70
#define false
Definition: GnuRegex.c:233
void defaultTo(bool beSet)
enables or disables the option; updating to 'implicit' state
Definition: YesNoNone.h:59

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors