BitVect.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2003-2008 greg Landrum and Rational Discovery LLC
00003 //
00004 //  @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef __RD_BITVECT_H__
00011 #define __RD_BITVECT_H__
00012 
00013 #include <vector>
00014 #include <string>
00015 
00016 typedef std::vector<int> IntVect;
00017 typedef IntVect::iterator IntVectIter;
00018 typedef std::vector<double> DoubleVect;
00019 typedef DoubleVect::iterator DoubleVectIter;
00020 const int ci_BITVECT_VERSION=0x0020; //!< version number to use in pickles
00021 
00022 //! Abstract base class for storing BitVectors
00023 class BitVect{
00024 public:
00025   virtual ~BitVect() = 0;
00026   //! sets a particular bit and returns its original value
00027   virtual bool setBit(const unsigned int which) = 0;
00028   //! unsets a particular bit and returns its original value
00029   virtual bool unsetBit(const unsigned int which) = 0;
00030   //! returns the value of a particular bit
00031   virtual bool getBit(const unsigned int which) const = 0;
00032   //! returns the number of bits (the length of the BitVect)
00033   virtual unsigned int getNumBits() const = 0;
00034   //! returns the number of on bits
00035   virtual unsigned int getNumOnBits() const = 0;
00036   //! returns the number of off bits
00037   virtual unsigned int getNumOffBits() const =0;
00038   //! replaces the contents of \c v with indices of our on bits
00039   virtual void getOnBits (IntVect& v) const = 0;
00040   //! clears (sets to off) all of our bits
00041   virtual void clearBits() = 0;
00042 
00043   //! initializes this BitVect from a pickle
00044   /*!
00045     \param data     the raw pickle data
00046     \param dataLen  the length of \c data 
00047     \param isBase64 (optional) if this is set, \c data is assumed to
00048          be base64 encoded.
00049     \param allowOldFormat (optional) allows a very old form of the BitVect
00050          representation to be recognized. This argument disables a large
00051          amount of error checking and it is strongly suggested that it not
00052          be used in client code.
00053    */
00054   void initFromText(const char *data,const unsigned int dataLen,
00055                     bool isBase64=false,bool allowOldFormat=false);
00056                     
00057   //! returns a serialized (pickled) version of this BitVect
00058   virtual std::string toString() const = 0;
00059 
00060   virtual bool operator[] (const unsigned int which) const = 0;
00061 
00062 private:
00063   virtual void _initForSize(const unsigned int size) = 0;
00064 };
00065 
00066 
00067 #endif