YesNoNone.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
14 // TODO: generalize / template to non-boolean option types
15 // and make YesNoNone the boolean instance of the template
16 
27 class YesNoNone
28 {
29  enum SetHow : uint8_t { optUnspecified = 0, optImplicitly = 1, optConfigured = 2 };
30 
31 public:
32  // this constructor initializes to 'unspecified' state
35  option(false)
36  {}
37 
38  // this constructor initializes to 'implicit' state
39  explicit YesNoNone(bool beSet):
41  option(beSet)
42  {}
43 
46  explicit operator bool() const {
48  return option;
49  }
50 
52  void configure(bool beSet) {
54  option = beSet;
55  }
56 
58  void defaultTo(bool beSet) {
61  option = beSet;
62  }
63 
66  bool configured() const {return setHow_ == optConfigured;}
67 
68 private:
70  bool option;
71 };
72 
73 #endif /* SQUID_YESNONONE_H_ */
74 
YesNoNone()
Definition: YesNoNone.h:33
bool configured() const
Definition: YesNoNone.h:66
bool option
specified yes/no value; meaningless if optUnspecified
Definition: YesNoNone.h:70
void configure(bool beSet)
enables or disables the option; updating to 'configured' state
Definition: YesNoNone.h:52
YesNoNone(bool beSet)
Definition: YesNoNone.h:39
#define Must(cond)
Definition: TextException.h:89
SetHow setHow_
how the option was set
Definition: YesNoNone.h:69
#define false
Definition: GnuRegex.c:233
void defaultTo(bool beSet)
enables or disables the option; updating to 'implicit' state
Definition: YesNoNone.h:58

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors