Skip to content
Snippets Groups Projects
Commit 2de2a21f authored by Oliver Sander's avatar Oliver Sander
Browse files

An array of booleans. Inherits from std::vector<bool>

[[Imported from SVN: r1132]]
parent 8606759c
Branches
Tags
No related merge requests found
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_BITFIELD_HH
#define DUNE_BITFIELD_HH
#include <vector>
namespace Dune {
/** \brief A dynamic array of booleans
* \ingroup Common
*
* This class is basically std::vector<bool>, but with a few added
* methods.
*/
class BitField : public std::vector<bool> {
public:
//! Sets all entries to <tt> true </tt>
void setAll() {
for (int i=0; i<size(); i++)
(*this)[i] = true;
}
//! Sets all entries to <tt> false </tt>
void unsetAll() {
for (int i=0; i<size(); i++)
(*this)[i] = false;
}
//! Returns the number of set bits
int nSetBits() const {
int n = 0;
for (int i=0; i<size(); i++)
n += ((*this)[i]) ? 1 : 0;
return n;
}
//! Send bitfield to an output stream
friend std::ostream& operator<< (std::ostream& s, const BitField& v)
{
for (int i=0; i<v.size(); i++)
s << v[i] << " ";
s << std::endl;
return s;
}
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment