RDKit
Open-source cheminformatics and machine learning.
BitVect.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2003-2008 greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef __RD_BITVECT_H__
11 #define __RD_BITVECT_H__
12 
13 #include <vector>
14 #include <string>
15 
16 typedef std::vector<int> IntVect;
17 typedef IntVect::iterator IntVectIter;
18 typedef std::vector<double> DoubleVect;
19 typedef DoubleVect::iterator DoubleVectIter;
20 const int ci_BITVECT_VERSION = 0x0020; //!< version number to use in pickles
21 
22 //! Abstract base class for storing BitVectors
23 class BitVect {
24  public:
25  virtual ~BitVect() = 0;
26  //! sets a particular bit and returns its original value
27  virtual bool setBit(const unsigned int which) = 0;
28  //! unsets a particular bit and returns its original value
29  virtual bool unsetBit(const unsigned int which) = 0;
30  //! returns the value of a particular bit
31  virtual bool getBit(const unsigned int which) const = 0;
32  //! returns the number of bits (the length of the BitVect)
33  virtual unsigned int getNumBits() const = 0;
34  //! returns the number of on bits
35  virtual unsigned int getNumOnBits() const = 0;
36  //! returns the number of off bits
37  virtual unsigned int getNumOffBits() const = 0;
38  //! replaces the contents of \c v with indices of our on bits
39  virtual void getOnBits(IntVect& v) const = 0;
40  //! clears (sets to off) all of our bits
41  virtual void clearBits() = 0;
42 
43  //! initializes this BitVect from a pickle
44  /*!
45  \param data the raw pickle data
46  \param dataLen the length of \c data
47  \param isBase64 (optional) if this is set, \c data is assumed to
48  be base64 encoded.
49  \param allowOldFormat (optional) allows a very old form of the BitVect
50  representation to be recognized. This argument disables a large
51  amount of error checking and it is strongly suggested that it not
52  be used in client code.
53  */
54  void initFromText(const char* data, const unsigned int dataLen,
55  bool isBase64 = false, bool allowOldFormat = false);
56 
57  //! returns a serialized (pickled) version of this BitVect
58  virtual std::string toString() const = 0;
59 
60  virtual bool operator[](const unsigned int which) const = 0;
61  unsigned int size() const { return getNumBits(); }
62 
63  private:
64  virtual void _initForSize(const unsigned int size) = 0;
65 };
66 
67 #endif
DoubleVect::iterator DoubleVectIter
Definition: BitVect.h:19
virtual ~BitVect()=0
IntVect::iterator IntVectIter
Definition: BitVect.h:17
virtual void clearBits()=0
clears (sets to off) all of our bits
virtual unsigned int getNumBits() const =0
returns the number of bits (the length of the BitVect)
const int ci_BITVECT_VERSION
version number to use in pickles
Definition: BitVect.h:20
virtual bool unsetBit(const unsigned int which)=0
unsets a particular bit and returns its original value
virtual bool operator[](const unsigned int which) const =0
void initFromText(const char *data, const unsigned int dataLen, bool isBase64=false, bool allowOldFormat=false)
initializes this BitVect from a pickle
virtual unsigned int getNumOffBits() const =0
returns the number of off bits
virtual bool getBit(const unsigned int which) const =0
returns the value of a particular bit
std::vector< double > DoubleVect
Definition: BitVect.h:18
unsigned int size() const
Definition: BitVect.h:61
virtual void getOnBits(IntVect &v) const =0
replaces the contents of v with indices of our on bits
std::vector< int > IntVect
Definition: BitVect.h:16
virtual std::string toString() const =0
returns a serialized (pickled) version of this BitVect
Abstract base class for storing BitVectors.
Definition: BitVect.h:23
virtual unsigned int getNumOnBits() const =0
returns the number of on bits
virtual bool setBit(const unsigned int which)=0
sets a particular bit and returns its original value