Program Listing for File bitSet.h

Return to documentation for file (src/misc/pv/bitSet.h)

/* bitSet.h */
/*
 * Copyright information and license terms for this software can be
 * found in the file LICENSE that is included with the distribution
 */
#ifndef BITSET_H
#define BITSET_H

#if __cplusplus>=201103L
#  include <initializer_list>
#endif

#include <vector>

#include <pv/pvType.h>
#include <pv/serialize.h>
#include <pv/sharedPtr.h>

#include <shareLib.h>

namespace epics { namespace pvData {

    class BitSet;
    typedef std::tr1::shared_ptr<BitSet> BitSetPtr;

    class epicsShareClass BitSet : public Serializable {
    public:
        POINTER_DEFINITIONS(BitSet);
        static BitSetPtr create(uint32 nbits);
        BitSet();

        BitSet(uint32 nbits);

#if __cplusplus>=201103L

        BitSet(std::initializer_list<uint32> I);
#endif

        virtual ~BitSet();

        BitSet& flip(uint32 bitIndex);

        BitSet& set(uint32 bitIndex);

        BitSet& clear(uint32 bitIndex);

        void set(uint32 bitIndex, bool value);

        bool get(uint32 bitIndex) const;

        void clear();

        int32 nextSetBit(uint32 fromIndex) const;

        int32 nextClearBit(uint32 fromIndex) const;

        bool isEmpty() const;

        uint32 cardinality() const;

        uint32 size() const;

        bool logical_and(const BitSet& other) const;
        bool logical_or(const BitSet& other) const;

        BitSet& operator&=(const BitSet& set);

        BitSet& operator|=(const BitSet& set);

        BitSet& operator^=(const BitSet& set);

        BitSet& operator=(const BitSet &set);

        void swap(BitSet& set);

        void or_and(const BitSet& set1, const BitSet& set2);

        bool operator==(const BitSet &set) const;

        bool operator!=(const BitSet &set) const;

        virtual void serialize(ByteBuffer *buffer,
            SerializableControl *flusher) const;
        virtual void deserialize(ByteBuffer *buffer,
            DeserializableControl *flusher);

    private:

        typedef std::vector<uint64> words_t;
        words_t words;

    private:
        void recalculateWordsInUse();

        void ensureCapacity(uint32 wordsRequired);

        void expandTo(uint32 wordIndex);

        static uint32 numberOfTrailingZeros(uint64 i);

         static uint32 bitCount(uint64 i);

    };

    epicsShareExtern std::ostream& operator<<(std::ostream& o, const BitSet& b);

}}
#endif  /* BITSET_H */