An introduction to the ZMutility compatibility headers W E Brown, 31-Oct-1997 Last revised 22-May-1998 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 FPCL headers: our header replacement for --------------------- --------------- "ZMutility/algorithm" "ZMutility/cmath" "ZMutility/ctime" "ZMutility/iomanip" "ZMutility/iosfwd" "ZMutility/iostream" "ZMutility/fstream" "ZMutility/map" "ZMutility/sstream" 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 our package, ZMutility. Each of these headers begins by (transparently) #include'ing ZMenvironment.h as a source of common #define's. The header then #include's the header appropriate for the current compilation 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 thus making the compiler subsequently ignore the line in non-namespace environments. Further, "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] #include using 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()