bool_array Class Reference

Class to represent a packed boolean array. More...

#include <bool_array.h>

Collaboration diagram for bool_array:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 bool_array ()
 bool_array (unsigned long __size)
 Constructs the packed boolean array with a specific size.
 ~bool_array ()
bool create (unsigned long __size)
 Creates the packed boolean array with a specific size.
void initialize (bool __value)
 Initializes all array elements to a specific value optimally.
_Element operator[] (unsigned long __idx)
 Creates a reference to an array element.
bool at (unsigned long __idx) const
 Reads the boolean value of an array element via an index.
void reset (unsigned long __idx)
 Resets an array element to false via an index.
void set (unsigned long __idx)
 Sets an array element to true via an index.
unsigned long size () const
unsigned long count () const
 Counts elements with a true value.
unsigned long count (unsigned long __beg, unsigned long __end) const
 Counts elements with a true value in a specified range.
void flip ()
 Changes all true elements to false, and false ones to true.

Classes

class  _Element
 Class to represent a reference to an array element.

Detailed Description

Class to represent a packed boolean array.

This was first written in April 1995, before I knew of any existing implementation of this kind of classes. Of course, the C++ Standard Template Library now demands an implementation of packed boolean array as `vector<bool>', but the code here should still be useful for the following three reasons: (1) STL support of MSVC 6 did not implement this specialization (nor did it have a `bit_vector'); (2) I incorporated some useful member functions from the STL bitset into this `bool_array', including `reset', `set', `flip', and `count'; (3) In my tests under MSVC 6 and GCC 2.95.3/3.2.3 my code is really FASTER than vector<bool> or the normal boolean array.


Constructor & Destructor Documentation

bool_array::bool_array (  )  [inline]

bool_array::bool_array ( unsigned long  __size  )  [inline, explicit]

Constructs the packed boolean array with a specific size.

Parameters:
__size size of the array
Exceptions:
std::out_of_range if __size equals 0
std::bad_alloc if memory is insufficient

bool_array::~bool_array (  )  [inline]


Member Function Documentation

bool bool_array::create ( unsigned long  __size  ) 

Creates the packed boolean array with a specific size.

Parameters:
__size size of the array
Returns:
false if __size equals 0 or is too big, or if memory is insufficient; true if __size has a suitable value and memory allocation is successful.

void bool_array::initialize ( bool  __value  ) 

Initializes all array elements to a specific value optimally.

Parameters:
__value the boolean value to assign to all elements

bool_array::_Element bool_array::operator[] ( unsigned long  __idx  )  [inline]

Creates a reference to an array element.

Parameters:
__idx index of the array element to access

bool bool_array::at ( unsigned long  __idx  )  const [inline]

Reads the boolean value of an array element via an index.

Parameters:
__idx index of the array element to access
Returns:
the boolean value of the accessed array element
Exceptions:
std::out_of_range when the index is too big

void bool_array::reset ( unsigned long  __idx  )  [inline]

Resets an array element to false via an index.

Parameters:
__idx index of the array element to access
Exceptions:
std::out_of_range when the index is too big

void bool_array::set ( unsigned long  __idx  )  [inline]

Sets an array element to true via an index.

Parameters:
__idx index of the array element to access
Exceptions:
std::out_of_range when the index is too big

unsigned long bool_array::size (  )  const [inline]

unsigned long bool_array::count (  )  const

Counts elements with a true value.

Returns:
the count of true elements

unsigned long bool_array::count ( unsigned long  __beg,
unsigned long  __end 
) const

Counts elements with a true value in a specified range.

Parameters:
__beg beginning of the range
__end end of the range (exclusive)
Returns:
the count of true elements

void bool_array::flip (  ) 

Changes all true elements to false, and false ones to true.


The documentation for this class was generated from the following files:
Generated on Mon Dec 31 15:07:33 2007 for Nvwa by  doxygen 1.5.1