/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include "bitmask.h" #include "pvaproto.h" #include "utilpvt.h" namespace pvxs { BitMask::BitMask(BitMask&& o) noexcept :_words(std::move(o._words)) ,_size(o._size) { o._size = 0u; } BitMask& BitMask::operator=(BitMask&& o) noexcept { _words = std::move(o._words); _size = o._size; o._size = 0u; return *this; } BitMask::BitMask(std::initializer_list bits, size_t nbits) { if(bits.size()>0u) { auto it_max = std::max_element(bits.begin(), bits.end()); resize(std::max(nbits, 1u+*it_max)); for(auto bit : bits) { (*this)[bit] = true; } } else { resize(nbits); } } void BitMask::resize(size_t bits) { // round up to multiple of 64 size_t storebits = ((bits-1u)|0x3f)+1u; _words.resize(storebits/64u, 0u); _size = uint16_t(bits); } size_t BitMask::findSet(size_t start) const { while(start < _size) { size_t word = start/64u, bit = start%64u; // first see if we can skip to next word uint64_t mask = ~((1ull<>(8u*i))); } } } PVXS_API void from_wire(Buffer& buf, BitMask& mask) { Size nbytes{0u}; from_wire(buf, nbytes); mask.resize(8u*nbytes.size); size_t nwords = nbytes.size / 8u; size_t extra = nbytes.size % 8u; // trailing single bytes for(auto i : range(nwords)) { from_wire(buf, mask.word(i)); } if(extra) { uint64_t& last = mask.word(nwords); for(auto i : range(extra)) { uint8_t b=0; from_wire(buf, b); last |= uint64_t(b)<<(8u*i); } } } } // namespace impl } // namespace pvxs