Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

simple_bitset_optim.h

00001 #ifndef _LCORE_simple_bitset_optim_H_  // -*-c++-*-
00002 
00003 #ifdef __GNUG__
00004 #  pragma interface
00005 #endif
00006 
00007 /* $Header: /home/hopper/src/cvs/C++/LCore/LCore/simple_bitset_optim.h,v 1.3 2002/11/25 05:40:05 hopper Exp $ */
00008 
00009 // For a log, see ../ChangeLog
00010 
00011 #define _LCORE_simple_bitset_optim_H_
00012 
00013 template <size_t Tsize> class _single_int_bitset : private priv::_base_simple_bitset
00014 {
00015  public:
00016    typedef _single_int_bitset<Tsize> self_t;
00017 
00018    inline explicit _single_int_bitset(bool initial_value = false);
00019    inline _single_int_bitset(const _single_int_bitset<Tsize> &rhs);
00020 
00021    inline self_t &operator &=(const self_t &rhs);
00022    inline self_t &operator |=(const self_t &rhs);
00023    inline self_t &operator ^=(const self_t &rhs);
00024    inline self_t &set();
00025    inline self_t &set(size_t pos, bool val = true);
00026    inline self_t &reset();
00027    inline self_t &reset(size_t pos);
00028    inline self_t &flip();
00029    inline self_t &flip(size_t pos);
00030    inline bool operator [](size_t pos) const               { return test(pos); }
00031    inline size_t count() const;
00032    inline size_t size() const                              { return numbits_; }
00033    inline bool operator ==(const self_t &rhs) const;
00034    inline bool operator !=(const self_t &rhs) const;
00035    inline bool test(size_t pos) const;
00036    inline bool any() const;
00037    inline bool none() const;
00038 
00039    inline ::std::string to_string() const;
00040 
00041  private:
00042    static const size_t numbits_ = Tsize;
00043    static const bits_t topmask_ = (Tsize == bits_t_bits) ? allones_ : ((1UL << Tsize) - 1);
00044    bits_t bits_;
00045 };
00046 
00047 //-----------------------------inline functions--------------------------------
00048 
00049 template <size_t Tsize>
00050 inline _single_int_bitset<Tsize>::_single_int_bitset(bool initial_value)
00051 {
00052    bits_ = initial_value ? topmask_ : 0;
00053 }
00054 
00055 template <size_t Tsize>
00056 inline _single_int_bitset<Tsize>::_single_int_bitset(const _single_int_bitset<Tsize> &rhs)
00057 {
00058    bits_ = rhs.bits_;
00059 }
00060 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00061 _single_int_bitset<Tsize>::operator &=(const self_t &rhs)
00062 {
00063    bits_ &= rhs.bits_;
00064    return *this;
00065 }
00066 
00067 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00068 _single_int_bitset<Tsize>::operator |=(const self_t &rhs)
00069 {
00070    bits_ |= rhs.bits_;
00071    return *this;
00072 }
00073 
00074 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00075 _single_int_bitset<Tsize>::operator ^=(const self_t &rhs)
00076 {
00077    bits_ ^= rhs.bits_;
00078    return *this;
00079 }
00080 
00081 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00082 _single_int_bitset<Tsize>::set()
00083 {
00084    bits_ = topmask_;
00085    return *this;
00086 }
00087 
00088 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00089 _single_int_bitset<Tsize>::set(size_t pos, bool val)
00090 {
00091    bits_t bval = bits_t(1) << pos;
00092    bits_ = val ? (bits_ | (bval & topmask_)) : (bits_ & ~bval);
00093    return *this;
00094 }
00095 
00096 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00097 _single_int_bitset<Tsize>::reset()
00098 {
00099    bits_ = 0;
00100    return *this;
00101 }
00102 
00103 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00104 _single_int_bitset<Tsize>::reset(size_t pos)
00105 {
00106    return set(pos, false);
00107 }
00108 
00109 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00110 _single_int_bitset<Tsize>::flip()
00111 {
00112    bits_ ^= topmask_;
00113    return *this;
00114 }
00115 
00116 template <size_t Tsize> inline _single_int_bitset<Tsize> &
00117 _single_int_bitset<Tsize>::flip(size_t pos)
00118 {
00119    bits_t bval = (bits_t(1) << pos) & topmask_;
00120    bits_ ^= bval;
00121    return *this;
00122 }
00123 
00124 template <size_t Tsize> inline size_t
00125 _single_int_bitset<Tsize>::count() const
00126 {
00127    return countbits(&bits_, 1, topmask_);
00128 }
00129 
00130 template <size_t Tsize> inline bool
00131 _single_int_bitset<Tsize>::operator ==(const self_t &rhs) const
00132 {
00133    return bits_ == rhs.bits_;
00134 }
00135 
00136 template <size_t Tsize> inline bool
00137 _single_int_bitset<Tsize>::operator !=(const self_t &rhs) const
00138 {
00139    return !(*this == rhs);
00140 }
00141 
00142 template <size_t Tsize> inline bool
00143 _single_int_bitset<Tsize>::test(size_t pos) const
00144 {
00145    bits_t bval = bits_t(1) << pos;
00146    return (bits_ & bval) != 0;
00147 }
00148 
00149 template <size_t Tsize> inline bool
00150 _single_int_bitset<Tsize>::any() const
00151 {
00152    return !none();
00153 }
00154 
00155 template <size_t Tsize> inline bool
00156 _single_int_bitset<Tsize>::none() const
00157 {
00158    return bits_ == 0;
00159 }
00160 
00161 template <size_t Tsize> inline ::std::string
00162 _single_int_bitset<Tsize>::to_string() const
00163 {
00164    return _base_simple_bitset::to_string(&bits_, 1, topmask_);
00165 }
00166 
00167 //--
00168 
00169 //! Specialized to make the compiler optimize better.
00170 template <> class simple_bitset<1> : public _single_int_bitset<1>
00171 {
00172   public:
00173    explicit simple_bitset(bool initial_value = false)
00174       : _single_int_bitset<1>(initial_value)
00175       {
00176       }
00177 };
00178 //! Specialized to make the compiler optimize better.
00179 template <> class simple_bitset<2> : public _single_int_bitset<2>
00180 {
00181   public:
00182    explicit simple_bitset(bool initial_value = false)
00183       : _single_int_bitset<2>(initial_value)
00184       {
00185       }
00186 };
00187 //! Specialized to make the compiler optimize better.
00188 template <> class simple_bitset<3> : public _single_int_bitset<3>
00189 {
00190   public:
00191    explicit simple_bitset(bool initial_value = false)
00192       : _single_int_bitset<3>(initial_value)
00193       {
00194       }
00195 };
00196 //! Specialized to make the compiler optimize better.
00197 template <> class simple_bitset<4> : public _single_int_bitset<4>
00198 {
00199   public:
00200    explicit simple_bitset(bool initial_value = false)
00201       : _single_int_bitset<4>(initial_value)
00202       {
00203       }
00204 };
00205 //! Specialized to make the compiler optimize better.
00206 template <> class simple_bitset<5> : public _single_int_bitset<5>
00207 {
00208   public:
00209    explicit simple_bitset(bool initial_value = false)
00210       : _single_int_bitset<5>(initial_value)
00211       {
00212       }
00213 };
00214 //! Specialized to make the compiler optimize better.
00215 template <> class simple_bitset<6> : public _single_int_bitset<6>
00216 {
00217   public:
00218    explicit simple_bitset(bool initial_value = false)
00219       : _single_int_bitset<6>(initial_value)
00220       {
00221       }
00222 };
00223 //! Specialized to make the compiler optimize better.
00224 template <> class simple_bitset<7> : public _single_int_bitset<7>
00225 {
00226   public:
00227    explicit simple_bitset(bool initial_value = false)
00228       : _single_int_bitset<7>(initial_value)
00229       {
00230       }
00231 };
00232 //! Specialized to make the compiler optimize better.
00233 template <> class simple_bitset<8> : public _single_int_bitset<8>
00234 {
00235   public:
00236    explicit simple_bitset(bool initial_value = false)
00237       : _single_int_bitset<8>(initial_value)
00238       {
00239       }
00240 };
00241 //! Specialized to make the compiler optimize better.
00242 template <> class simple_bitset<9> : public _single_int_bitset<9>
00243 {
00244   public:
00245    explicit simple_bitset(bool initial_value = false)
00246       : _single_int_bitset<9>(initial_value)
00247       {
00248       }
00249 };
00250 //! Specialized to make the compiler optimize better.
00251 template <> class simple_bitset<10> : public _single_int_bitset<10>
00252 {
00253   public:
00254    explicit simple_bitset(bool initial_value = false)
00255       : _single_int_bitset<10>(initial_value)
00256       {
00257       }
00258 };
00259 //! Specialized to make the compiler optimize better.
00260 template <> class simple_bitset<11> : public _single_int_bitset<11>
00261 {
00262   public:
00263    explicit simple_bitset(bool initial_value = false)
00264       : _single_int_bitset<11>(initial_value)
00265       {
00266       }
00267 };
00268 //! Specialized to make the compiler optimize better.
00269 template <> class simple_bitset<12> : public _single_int_bitset<12>
00270 {
00271   public:
00272    explicit simple_bitset(bool initial_value = false)
00273       : _single_int_bitset<12>(initial_value)
00274       {
00275       }
00276 };
00277 //! Specialized to make the compiler optimize better.
00278 template <> class simple_bitset<13> : public _single_int_bitset<13>
00279 {
00280   public:
00281    explicit simple_bitset(bool initial_value = false)
00282       : _single_int_bitset<13>(initial_value)
00283       {
00284       }
00285 };
00286 //! Specialized to make the compiler optimize better.
00287 template <> class simple_bitset<14> : public _single_int_bitset<14>
00288 {
00289   public:
00290    explicit simple_bitset(bool initial_value = false)
00291       : _single_int_bitset<14>(initial_value)
00292       {
00293       }
00294 };
00295 //! Specialized to make the compiler optimize better.
00296 template <> class simple_bitset<15> : public _single_int_bitset<15>
00297 {
00298   public:
00299    explicit simple_bitset(bool initial_value = false)
00300       : _single_int_bitset<15>(initial_value)
00301       {
00302       }
00303 };
00304 //! Specialized to make the compiler optimize better.
00305 template <> class simple_bitset<16> : public _single_int_bitset<16>
00306 {
00307   public:
00308    explicit simple_bitset(bool initial_value = false)
00309       : _single_int_bitset<16>(initial_value)
00310       {
00311       }
00312 };
00313 //! Specialized to make the compiler optimize better.
00314 template <> class simple_bitset<17> : public _single_int_bitset<17>
00315 {
00316   public:
00317    explicit simple_bitset(bool initial_value = false)
00318       : _single_int_bitset<17>(initial_value)
00319       {
00320       }
00321 };
00322 //! Specialized to make the compiler optimize better.
00323 template <> class simple_bitset<18> : public _single_int_bitset<18>
00324 {
00325   public:
00326    explicit simple_bitset(bool initial_value = false)
00327       : _single_int_bitset<18>(initial_value)
00328       {
00329       }
00330 };
00331 //! Specialized to make the compiler optimize better.
00332 template <> class simple_bitset<19> : public _single_int_bitset<19>
00333 {
00334   public:
00335    explicit simple_bitset(bool initial_value = false)
00336       : _single_int_bitset<19>(initial_value)
00337       {
00338       }
00339 };
00340 //! Specialized to make the compiler optimize better.
00341 template <> class simple_bitset<20> : public _single_int_bitset<20>
00342 {
00343   public:
00344    explicit simple_bitset(bool initial_value = false)
00345       : _single_int_bitset<20>(initial_value)
00346       {
00347       }
00348 };
00349 //! Specialized to make the compiler optimize better.
00350 template <> class simple_bitset<21> : public _single_int_bitset<21>
00351 {
00352   public:
00353    explicit simple_bitset(bool initial_value = false)
00354       : _single_int_bitset<21>(initial_value)
00355       {
00356       }
00357 };
00358 //! Specialized to make the compiler optimize better.
00359 template <> class simple_bitset<22> : public _single_int_bitset<22>
00360 {
00361   public:
00362    explicit simple_bitset(bool initial_value = false)
00363       : _single_int_bitset<22>(initial_value)
00364       {
00365       }
00366 };
00367 //! Specialized to make the compiler optimize better.
00368 template <> class simple_bitset<23> : public _single_int_bitset<23>
00369 {
00370   public:
00371    explicit simple_bitset(bool initial_value = false)
00372       : _single_int_bitset<23>(initial_value)
00373       {
00374       }
00375 };
00376 //! Specialized to make the compiler optimize better.
00377 template <> class simple_bitset<24> : public _single_int_bitset<24>
00378 {
00379   public:
00380    explicit simple_bitset(bool initial_value = false)
00381       : _single_int_bitset<24>(initial_value)
00382       {
00383       }
00384 };
00385 //! Specialized to make the compiler optimize better.
00386 template <> class simple_bitset<25> : public _single_int_bitset<25>
00387 {
00388   public:
00389    explicit simple_bitset(bool initial_value = false)
00390       : _single_int_bitset<25>(initial_value)
00391       {
00392       }
00393 };
00394 //! Specialized to make the compiler optimize better.
00395 template <> class simple_bitset<26> : public _single_int_bitset<26>
00396 {
00397   public:
00398    explicit simple_bitset(bool initial_value = false)
00399       : _single_int_bitset<26>(initial_value)
00400       {
00401       }
00402 };
00403 //! Specialized to make the compiler optimize better.
00404 template <> class simple_bitset<27> : public _single_int_bitset<27>
00405 {
00406   public:
00407    explicit simple_bitset(bool initial_value = false)
00408       : _single_int_bitset<27>(initial_value)
00409       {
00410       }
00411 };
00412 //! Specialized to make the compiler optimize better.
00413 template <> class simple_bitset<28> : public _single_int_bitset<28>
00414 {
00415   public:
00416    explicit simple_bitset(bool initial_value = false)
00417       : _single_int_bitset<28>(initial_value)
00418       {
00419       }
00420 };
00421 //! Specialized to make the compiler optimize better.
00422 template <> class simple_bitset<29> : public _single_int_bitset<29>
00423 {
00424   public:
00425    explicit simple_bitset(bool initial_value = false)
00426       : _single_int_bitset<29>(initial_value)
00427       {
00428       }
00429 };
00430 //! Specialized to make the compiler optimize better.
00431 template <> class simple_bitset<30> : public _single_int_bitset<30>
00432 {
00433   public:
00434    explicit simple_bitset(bool initial_value = false)
00435       : _single_int_bitset<30>(initial_value)
00436       {
00437       }
00438 };
00439 //! Specialized to make the compiler optimize better.
00440 template <> class simple_bitset<31> : public _single_int_bitset<31>
00441 {
00442   public:
00443    explicit simple_bitset(bool initial_value = false)
00444       : _single_int_bitset<31>(initial_value)
00445       {
00446       }
00447 };
00448 
00449 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1