Fermi Physics Class Libraries Module: Timer Classes

ZOOM ZOOM

Block

Block Class Sub-package

This mini-package provides a simple class, Block, that can serve as a fixed-size container (in the STL sense) and that can also serve as a replacement for a native C++ array.

This package may be obtained from the following sources:


Description
User Interface
Implementation

Walter Brown, Module Coordinator
Fermilab Physics Class Library Task Force

Comments, questions about getting started, feature needs, and bug/annoyance reports may be sent to zoom-support@fnal.gov or zoom@fnal.gov.

Description

This module provides a fixed-size C++ container class that fully supports all operations needed to cooperate smoothly with the standard C++ library algorithms, yet supplies all the operations and benefits of a fixed-size native C++ array.

User Interface

To use the Block facilities, a user simply includes the header file:

The code guard for the mini-module is BLOCK_H; this symbol may also be used as an external code guard.

Subsequently, the user may instantiate and employ one or more Blocks, as in the following simple example:

As demonstrated, the Block template requires two arguments: the data type of the objects to be contained (here, int), and the desired extent of the container (here, 20). Subscripting, the quintessential array operator, is fully supported, as is the full range of STL container operations: size(), max_size(), empty(), and swap(). Comparison operators == and < are also furnished, as are iterator operations begin(), end(), rbegin(), rend(), as well as the full range of typedefs expected of an STL container.

A test program that validates the behavior of the Block<> template is available in the program zmtBlockTest.cc, furnished as part of this module.

Implementation

The sole header file needed by the user is ZMtools/Block.h. This file contains the complete implementation in the form of a template class, Block<>, together with a specialization of this template that handles the case of a zero-sized container.

This class was adapted from Matthew Austern's block class as published in Generic Programming and the STL, ISBN 0-201-30956-4, and a similar class, c_array, published by Bjarne Stroustrup in The C++ Programming Language, 3rd Edition, ISBN 0-201-88954-4. The specialization for the case of a zero-length container was provided by Marc Paterno. Walter Brown edited the result for conformance to Zoom standards.

ZMtools main page - ZOOM Home Page - Fermilab at Work - Fermilab Home


Walter Brown
Last modified: May 16, 2000.