1 | #ifndef BITVECTOR_H_SEEN
|
---|
2 | #define BITVECTOR_H_SEEN
|
---|
3 |
|
---|
4 | #include "machdefs.h"
|
---|
5 | #include <vector>
|
---|
6 |
|
---|
7 | #include "ndatablock.h"
|
---|
8 | #include "ppersist.h"
|
---|
9 | #include "objfio.h"
|
---|
10 |
|
---|
11 | namespace SOPHYA {
|
---|
12 |
|
---|
13 | // type d'element et nombre de bits dans un element du vecteur
|
---|
14 | typedef uint_8 BitVec_Type;
|
---|
15 | #define BitVec_BITPERWORD_ 64ULL
|
---|
16 | ////typedef uint_1 BitVec_Type;
|
---|
17 | ////#define BitVec_BITPERWORD_ 8ULL
|
---|
18 |
|
---|
19 | class BitVector : public AnyDataObj {
|
---|
20 | friend class ObjFileIO<BitVector>; // Pour la gestion de persistance
|
---|
21 |
|
---|
22 | public:
|
---|
23 | BitVector(uint_8 nbits,uint_4 vecsize=128);
|
---|
24 | BitVector(BitVector const& bv);
|
---|
25 | BitVector(void);
|
---|
26 | virtual ~BitVector(void);
|
---|
27 |
|
---|
28 | BitVector& operator = (const BitVector& bv);
|
---|
29 | BitVector& operator = (bool v);
|
---|
30 | BitVector& Negate(void);
|
---|
31 | //! make AND (without changing extra bits if any)
|
---|
32 | BitVector& operator &= (const BitVector& bv) {return AND(bv,0);}
|
---|
33 | BitVector& AND(const BitVector& bv,int putextra=0);
|
---|
34 | //! make OR (without changing extra bits if any)
|
---|
35 | BitVector& operator |= (const BitVector& bv) {return OR(bv,0);}
|
---|
36 | BitVector& OR(const BitVector& bv,int putextra=0);
|
---|
37 |
|
---|
38 | inline uint_8 Size(void) const {return nbits_;}
|
---|
39 | bool operator()(uint_8 k) const;
|
---|
40 | void Set(uint_8 k,bool v=true);
|
---|
41 | void Set(uint_8 k1,uint_8 k2,bool v=true);
|
---|
42 |
|
---|
43 | uint_8 NValues(bool v=true);
|
---|
44 |
|
---|
45 | void Print(uint_8 k1=0,int_8 dk=0);
|
---|
46 |
|
---|
47 | private:
|
---|
48 | void extend_(uint_8 nbitsnew);
|
---|
49 | void delete_(void);
|
---|
50 |
|
---|
51 | uint_8 nbits_;
|
---|
52 | uint_4 vecsize_;
|
---|
53 | uint_8 bitpervec_;
|
---|
54 | uint_8 nvector_;
|
---|
55 | std::vector< NDataBlock<BitVec_Type> > vv_;
|
---|
56 | };
|
---|
57 |
|
---|
58 | /*! Writes the object in the POutPersist stream \b os */
|
---|
59 | inline POutPersist& operator << (POutPersist& os, BitVector & obj)
|
---|
60 | { ObjFileIO<BitVector> fio(&obj); fio.Write(os); return(os); }
|
---|
61 | /*! Reads the object from the PInPersist stream \b is */
|
---|
62 | inline PInPersist& operator >> (PInPersist& is, BitVector & obj)
|
---|
63 | { ObjFileIO<BitVector> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
64 |
|
---|
65 | } // namespace SOPHYA
|
---|
66 |
|
---|
67 | #endif
|
---|