00001 // @(#)root/base:$Name: $:$Id: TBits.h,v 1.6 2001/12/19 15:40:59 brun Exp $ 00002 // Author: Philippe Canal 05/02/01 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TBits 00013 #define ROOT_TBits 00014 00015 //------------------------------------------------------------------------------ 00016 // Copyright(c) 2001,.Canal (FNAL) 00017 // 00018 // Permission to use, copy, modify and distribute this software and its 00019 // documentation for non-commercial purposes is hereby granted without fee, 00020 // provided that the above copyright notice appears in all copies and 00021 // that both the copyright notice and this permission notice appear in 00022 // the supporting documentation. The authors make no claims about the 00023 // suitability of this software for any purpose. 00024 // It is provided "as is" without express or implied warranty. 00025 //------------------------------------------------------------------------------ 00026 00028 // // 00029 // TBits // 00030 // // 00031 // Container of bits. // 00032 // // 00034 00035 #ifndef ROOT_TObject 00036 #include "TObject.h" 00037 #endif 00038 00039 class TBits : public TObject { 00040 00041 protected: 00042 00043 UInt_t fNbits; // Number of bits (around fNbytes*8) 00044 UInt_t fNbytes; // Number of UChars in fAllBits 00045 UChar_t *fAllBits; //[fNbytes] array of UChars 00046 00047 public: 00048 TBits(UInt_t nbits = 8); 00049 TBits(const TBits&); 00050 TBits& operator=(const TBits&); 00051 virtual ~TBits(); 00052 00053 //----- bit manipulation 00054 //----- (note the difference with TObject's bit manipulations) 00055 void ResetAllBits(Bool_t value=kFALSE); // if value=1 set all bits to 1 00056 void ResetBitNumber(UInt_t bitnumber) { SetBitNumber(bitnumber,kFALSE); } 00057 void SetBitNumber(UInt_t bitnumber, Bool_t value = kTRUE); 00058 Bool_t TestBitNumber(UInt_t bitnumber) const; 00059 00060 //----- Utilities 00061 void Compact(); // Reduce the space used. 00062 UInt_t CountBits(UInt_t startBit=0) const ; // return number of bits set to 1 00063 UInt_t FirstNullBit(UInt_t startBit=0) const; 00064 UInt_t FirstSetBit(UInt_t startBit=0) const; 00065 UInt_t GetNbits() const { return fNbits; } 00066 UInt_t GetNbytes() const { return fNbytes; } 00067 00068 void Paint(Option_t *option=""); // to visualize the bits array as an histogram, etc 00069 void Print(Option_t *option="") const; // to show the list of active bits 00070 00071 00072 ClassDef(TBits,1) // Bit container 00073 }; 00074 00075 #endif
1.2.16