Skip to content

Commit

Permalink
libdeng2|BitField: Added assignment operator, method to get all eleme…
Browse files Browse the repository at this point in the history
…nt ids
  • Loading branch information
skyjake committed Apr 23, 2013
1 parent 7c08190 commit b530de6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doomsday/libdeng2/include/de/data/bitfield.h
Expand Up @@ -48,6 +48,8 @@ class DENG2_PUBLIC BitField
BitField(BitField const &other);
BitField(Block const &data);

BitField &operator = (BitField const &other);

/**
* Removes all the elements and the data contained in the bit field.
*/
Expand Down Expand Up @@ -79,6 +81,11 @@ class DENG2_PUBLIC BitField
*/
int bitCount() const;

/**
* Returns the identifiers of all elements.
*/
Ids elementIds() const;

/**
* Returns the packed data as an array of bytes. Only bitCount() bits are
* valid; the highest bits of the last byte may be unused (and zero).
Expand Down
19 changes: 19 additions & 0 deletions doomsday/libdeng2/src/data/bitfield.cpp
Expand Up @@ -128,6 +128,15 @@ BitField::BitField(Block const &data) : d(new Instance(this))
d->packed = data;
}

BitField &BitField::operator = (BitField const &other)
{
d->elements = other.d->elements;
d->totalBits = other.d->totalBits;
d->lookup = other.d->lookup;
d->packed = other.d->packed;
return *this;
}

void BitField::clear()
{
d->packed.clear();
Expand Down Expand Up @@ -200,6 +209,16 @@ int BitField::bitCount() const
return d->totalBits;
}

BitField::Ids BitField::elementIds() const
{
Ids ids;
foreach(Id id, d->elements.keys())
{
ids.insert(id);
}
return ids;
}

Block BitField::data() const
{
return d->packed;
Expand Down

0 comments on commit b530de6

Please sign in to comment.