CxxUtils::PackedArray Class Reference

An array of unsigned values of some bit size, packed tightly. More...

#include <PackedArray.h>

List of all members.

Classes

class  proxy
 proxy class for representing an lvalue to an element of PackedArray. More...

Public Types

typedef size_t size_type
typedef unsigned int value_type
typedef basetype::allocator_type allocator_type

Public Member Functions

 PackedArray (int bitsize, const allocator_type &allocator=allocator_type())
 Constructor.
 PackedArray (int bitsize, size_type n, value_type val=0, const allocator_type &allocator=allocator_type())
 Constructor.
void assign (size_type n, value_type u)
 Set the container to multiple copies of the same value.
allocator_type get_allocator () const
 Returns the allocator of the underlying vector.
size_type size () const
 Returns the number of elements in the collection.
size_type max_size () const
 Returns the size() of the largest possible collection.
size_type capacity () const
 Returns the total number of elements that the collection can hold before needing to allocate more memory.
void resize (size_type sz, value_type c=0)
 Resizes the collection to the specified number of elements.
bool empty () const
 Returns true if the collection is empty.
void reserve (size_type n)
 Attempt to preallocate enough memory for a specified number of elements.
value_type get (size_type n) const
 Return the entry at index n.
void set (size_type n, value_type val)
 Set the entry at index n.
value_type operator[] (size_type n) const
 Access an element, as an rvalue.
proxy operator[] (size_type n)
 Access an element, as an lvalue.
value_type at (size_type n) const
 Access an element, as an rvalue.
proxy at (size_type n)
 Access an element, as an lvalue.
value_type front () const
 Access the first element in the collection as an rvalue.
value_type back () const
 Access the last element in the collection as an rvalue.
proxy front ()
 Access the first element in the collection as an lvalue.
proxy back ()
 Access the last element in the collection as an lvalue.
void push_back (value_type x)
 Add an element to the end of the collection.
void pop_back ()
 Remove the last element from the collection.
void swap (PackedArray &other)
 Swap this collection with another.
void clear ()
 Erase all the elements in the collection.
void set_bitsize (int bitsize)
 Change the bitsize of the container.
int bitsize () const
 Return the bitsize of the container.

Detailed Description

An array of unsigned values of some bit size, packed tightly.

When creating an instance of this class, specify the bit size of the entries. The entries will be packed so that each takes exactly that many bits. For example, if the bit size is 10, 16 entries will be packed into 5 32-bit words. The bitsize may be changed, but only if the container is empty.

Any values assigned to the array that are too large to be represented in the specified number of bits will have the high bits silently dropped.

The interface is modeled after std::vector, except that there are no iterators. They could be added if there is a need for them.


Constructor & Destructor Documentation

CxxUtils::PackedArray::PackedArray ( int  bitsize,
const allocator_type &  allocator = allocator_type() 
)

Constructor.

Parameters:
bitsize The size, in bits, of each element. Must be greater than zero, and not larger than the size of an unsigned int.
allocator Allocator for the underlying vector.
CxxUtils::PackedArray::PackedArray ( int  bitsize,
size_type  n,
value_type  val = 0,
const allocator_type &  allocator = allocator_type() 
)

Constructor.

Parameters:
bitsize The size, in bits, of each element. Must be greater than zero, and not larger than the size of an unsigned int.
n Initial number of entries in the container.
val Value to which the initial entries are to be set.
allocator Allocator for the underlying vector.

Member Function Documentation

void CxxUtils::PackedArray::assign ( size_type  n,
value_type  u 
)

Set the container to multiple copies of the same value.

Parameters:
n Number of entries to which the container is to be set.
u Value to which the entries are to be set.
n Number of entries to which the container is to be set.
val Value to which the entries are to be set.
PackedArray::proxy CxxUtils::PackedArray::at ( size_type  n  ) 

Access an element, as an lvalue.

Parameters:
n Array index to access.
Returns:
Proxy to the element at n.

Will raise std::out_of_range if the index is out-of-bounds. Note that we return a proxy object rather than a reference.

PackedArray::value_type CxxUtils::PackedArray::at ( size_type  n  )  const

Access an element, as an rvalue.

Parameters:
n Array index to access.
Returns:
The element at n.

Will raise std::out_of_range if the index is out-of-bounds. Note that we return a value_type rather than a reference.

PackedArray::proxy CxxUtils::PackedArray::back (  ) 

Access the last element in the collection as an lvalue.

Returns:
Proxy to the last element in the collection.

No checking is done to ensure that the container is not empty. Note that we return a proxy object rather than a reference.

PackedArray::value_type CxxUtils::PackedArray::back (  )  const

Access the last element in the collection as an rvalue.

Returns:
The last element in the collection.

No checking is done to ensure that the container is not empty. Note that we return a value_type rather than a reference.

PackedArray::proxy CxxUtils::PackedArray::front (  ) 

Access the first element in the collection as an lvalue.

Returns:
Proxy to the first element in the collection.

No checking is done to ensure that the container is not empty. Note that we return a proxy object rather than a reference.

PackedArray::value_type CxxUtils::PackedArray::front (  )  const

Access the first element in the collection as an rvalue.

Returns:
The first element in the collection.

No checking is done to ensure that the container is not empty. Note that we return a value_type rather than a reference.

PackedArray::value_type CxxUtils::PackedArray::get ( size_type  n  )  const

Return the entry at index n.

Parameters:
n The index of the entry to retrieve.
PackedArray::proxy CxxUtils::PackedArray::operator[] ( size_type  n  ) 

Access an element, as an lvalue.

Parameters:
n Array index to access.
Returns:
Proxy to the element at n.

No bounds checking is done. Note that we return a proxy object rather than a reference.

PackedArray::value_type CxxUtils::PackedArray::operator[] ( size_type  n  )  const

Access an element, as an rvalue.

Parameters:
n Array index to access.
Returns:
The element at n.

No bounds checking is done. Note that we return a value_type rather than a reference.

void CxxUtils::PackedArray::push_back ( value_type  x  ) 

Add an element to the end of the collection.

Parameters:
x The element to add to the collection.
void CxxUtils::PackedArray::reserve ( size_type  n  ) 

Attempt to preallocate enough memory for a specified number of elements.

Parameters:
n Number of elements required.
void CxxUtils::PackedArray::resize ( size_type  sz,
value_type  c = 0 
)

Resizes the collection to the specified number of elements.

Parameters:
sz The new size of the collection.
c Value to which any new elements are to be set.
void CxxUtils::PackedArray::set ( size_type  n,
value_type  val 
)

Set the entry at index n.

Parameters:
n The index of the entry to set.
val The new value for the entry at index n.
void CxxUtils::PackedArray::set_bitsize ( int  bitsize  ) 

Change the bitsize of the container.

bitsize The new bitsize. This method may only be called when the container is empty.

void CxxUtils::PackedArray::swap ( PackedArray other  ) 

Swap this collection with another.

Parameters:
other The collection with which to swap.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 15 Apr 2017 for RootCore Packages by  doxygen 1.6.1