This mini-package provides a set of header files, itemized below, designed to encapsulate certain environment-specific adaptations. By centralizing environment dependencies in this way, other ZOOM packages can be expressed via a single set of source files, without need for internal variants (typically #ifdef'd code). ZOOM packages freely use these headers as front ends to the environment-supplied headers, thereby ensuring a uniform interface. Users are encouraged to utilize these same header files where appropriate.
This package may be obtained from the following sources:
fsgi02.fnal.gov
),
in directories rooted at
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.
A part of the ZMutility package provides header files to ease coding in an environment in which not all compilers are fully standards-compliant. In particular, KCC (the KAI compiler) does support namespaces and the latest standard names for header files, while gcc (the GNU compiler) has no namespace support and provides only older header file names.
The intent is to provide a set of universal headers, each usable in either environment described above. These would be #include'd in user source code in lieu of their respective standard library equivalents.
We have encapsulated the necessary details among the following ZOOM headers:
our header | replacement for |
---|---|
"ZMutility/algorithm" |
<algorithm> |
"ZMutility/cmath" |
<cmath> |
"ZMutility/ctime" |
<ctime> |
"ZMutility/iomanip" |
<iomanip> |
"ZMutility/iosfwd" |
<iosfwd> |
"ZMutility/iostream" |
<iostream> |
"ZMutility/fstream" |
<fstream> |
"ZMutility/sstream" |
<sstream> |
"ZMutility/map" |
<map> |
Note that our file names follow a predictable pattern: we use the standard name of the header we are encompassing/replacing, prefaced by the name of the containing package, ZMutility.
To use these compatibility headers, the user simply #include's the desired file, per the above table, as illustrated below:
#include "ZMutility/iostream"
Each of these headers begins by (transparently) #include'ing
"ZMutility/ZMenvironment.h"
as a source of common #define's.
The header then performs needed adaptations so as to make it appear
that the appropriate standard header has been provided.
Additionally, if the environment supports namespaces,
all identifiers from the std::
namespace
are made globally available
(via a using
statement),
so that a single style of user code will suffice for either environment.
If the environment does not support namespaces,
the using
keyword is disabled.
This is done via the mechanism:
#define using #define NOTusing
std
is treated as a keyword in such contexts,
and is ignored.
This turns such constructs as
std::string
into ::string
.
The drawback is that std
is no longer available
for use as a valid (non-namespace) identifier.
The following program, a development version of a test program for this package, exemplifies the use of some of the compatibility headers.
// ---------------------------------------------------------------------- // // util.cc // // Validate selected ZMutility header files. // // History: // 28-Oct-1997 WEB Initial draft. // 04-Nov-1997 WEB Updated to correspond to new file names, etc. // // ---------------------------------------------------------------------- // [0] #include "ZMutility/ZMenvironment.h" // [1] #include "ZMutility/iosfwd" #include "ZMutility/iostream" using std::cout; using std::endl; // [2] #includeusing std::string; // [3] #include "ZMutility/iomanip" using std::setw; // [4] #include "ZMutility/ostringstream" using std::ostringstream; int main() { // [0] Precautionary // [1] Validate iosfwd and iostream: cout << "iosfwd and iostream appear to work" << endl; // [2] Validate string: string s = "string appears to work"; cout << s << endl; // [3] Validate iomanip: cout << setw(3) << 9 << " iomanip appears to work if the '9' has 2 spaces before it" << endl; // [4] Validate ostream: ostringstream * o = new ostringstream; (*o) << "ostringstream appears to work"; cout << o->str() << endl; delete o; // [5] Go home: return 0; } // main()