00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_OPTIONS_HH
00021 #define PALUDIS_GUARD_PALUDIS_UTIL_OPTIONS_HH 1
00022
00023 #include <paludis/util/options-fwd.hh>
00024 #include <paludis/util/private_implementation_pattern.hh>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 namespace paludis
00037 {
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class PALUDIS_VISIBLE OptionsStore :
00048 private PrivateImplementationPattern<OptionsStore>
00049 {
00050 public:
00051
00052
00053
00054 OptionsStore();
00055 OptionsStore(const OptionsStore &);
00056 const OptionsStore & operator= (const OptionsStore &);
00057 ~OptionsStore();
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 void add(const unsigned);
00068
00069
00070
00071
00072 void remove(const unsigned);
00073
00074
00075
00076
00077 void combine(const OptionsStore &);
00078
00079
00080
00081
00082 void subtract(const OptionsStore &);
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 bool test(const unsigned) const;
00093
00094
00095
00096
00097 bool any() const;
00098
00099
00100
00101
00102
00103
00104 unsigned highest_bit() const;
00105
00106
00107 };
00108
00109
00110
00111
00112
00113
00114
00115 template <typename E_>
00116 class Options
00117 {
00118 private:
00119 OptionsStore _store;
00120
00121 public:
00122
00123
00124
00125 Options operator+ (const E_ & e) const
00126 {
00127 Options result(*this);
00128 result._store.add(static_cast<unsigned>(e));
00129 return result;
00130 }
00131
00132
00133
00134
00135 Options & operator+= (const E_ & e)
00136 {
00137 _store.add(static_cast<unsigned>(e));
00138 return *this;
00139 }
00140
00141
00142
00143
00144 Options operator- (const E_ & e) const
00145 {
00146 Options result(*this);
00147 result._store.remove(static_cast<unsigned>(e));
00148 return result;
00149 }
00150
00151
00152
00153
00154 Options & operator-= (const E_ & e)
00155 {
00156 _store.remove(static_cast<unsigned>(e));
00157 return *this;
00158 }
00159
00160
00161
00162
00163 Options operator| (const Options<E_> & e) const
00164 {
00165 Options result(*this);
00166 result._store.combine(e._store);
00167 return result;
00168 }
00169
00170
00171
00172
00173 Options & operator|= (const Options<E_> & e)
00174 {
00175 _store.combine(e._store);
00176 return *this;
00177 }
00178
00179
00180
00181
00182 Options & subtract(const Options<E_> & e)
00183 {
00184 _store.subtract(e._store);
00185 return *this;
00186 }
00187
00188
00189
00190
00191 bool operator[] (const E_ & e) const
00192 {
00193 return _store.test(static_cast<unsigned>(e));
00194 }
00195
00196
00197
00198
00199 bool any() const
00200 {
00201 return _store.any();
00202 }
00203
00204
00205
00206
00207 bool none() const
00208 {
00209 return ! _store.any();
00210 }
00211
00212
00213
00214
00215
00216
00217 E_ highest_bit() const
00218 {
00219 return static_cast<E_>(_store.highest_bit());
00220 }
00221 };
00222 }
00223
00224 #endif