#ifndef SYSUTILS_H #define SYSUTILS_H ///////////////////////////////////////////////////////////////// // sysUtils.H - utility classes to support Win32 API // // ver 1.1 // // Language: Visual C++, ver 6.0, SP 5 // // Platform: Dell Dimension 8100, Win 2000 Pro, SP 2 // // Application: CSE691/791 - SWM&A Demonstration // // Author: Jim Fawcett, CST 2-187, Syracuse Univ // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////// /* Module Operations: ================== This module provides several classes that provide information and error checking for Win32 operations. Public Interface - sysError: ============================ sysError myErr; // create sysError object string err = myErr.getLastMsg(); // get last system error message Public Interface - procInfo: ============================ procInfo pi; // create procInfo object string path = pi.getSpawnPath(); // process spawned on this path string name = pi.getFileName(); // process spawned from this file Public Interface - file: ======================== file f; // create file bool ok = f.open("temp.dat",file::Read); // open for reading bool ok = f.open("new.dat",file::Write); // open for writing bool ok = f.openStdOut(); // open to stdout f.close(); // close file HANDLE fHan = f.getHandle(); // get file's handle f.setHandle(newHandle); // give file new handle unsigned long int bytes = read(buffer,bufSize); // read into buffer unsigned long int bytes = write(buffer,bufSize);// write from buffer Public Interface - TtoStr and StrToT: ===================================== TtoStr dblStr(3.1415927); // construct convert from double string s = dblStr.convert(); // convert double to string Using a temporary converter object, we can convert in a single expression: StrToT("-17").convert(); // convert string to integer */ // /////////////////////////////////////////////////////////////// // Build Process // /////////////////////////////////////////////////////////////// // Required Files: // // sysUtils.h, sysUtils.cpp // // // // Compiler Command // // cl /GX /DTEST_SYSUTILS sysUtils.cpp // // // /////////////////////////////////////////////////////////////// /* Maintenance History =================== ver 1.1 : 24 Nov 2001 - added file class to support use of low-level Win32 file API. ver 1.0 : 23 Oct 2001 - first release */ // #include #include #include /////////////////////////////////////////////////////////////// // sysError class declaration class sysError { public: sysError() {} ~sysError() {} std::string getLastMsg(); private: std::string _msg; }; /////////////////////////////////////////////////////////////// // procInfo class declaration class procInfo { public: procInfo() { } ~procInfo() { } std::string getSpawnPath(); std::string getFileName(); private: }; /////////////////////////////////////////////////////////////// // file class declaration class file { public: enum fileType { Read, Write }; file(); bool open(const char *fileName, fileType type); bool openStdOut(); void close(); void setHandle(HANDLE fileHandle); HANDLE getHandle(); unsigned long int read(char *buffer, unsigned long int bufferSize); unsigned long int write(char *buffer, unsigned long int bufferSize); private: HANDLE _fileHandle; }; inline void file::setHandle(HANDLE fileHandle) { _fileHandle = fileHandle; } inline HANDLE file::getHandle() { return _fileHandle; } /////////////////////////////////////////////////////////////// // conversion class declarations template class TtoStr { public: TtoStr(T t); std::string convert(); private: T _t; }; template class StrToT { public: StrToT(const std::string &s); T convert(); private: T _t; }; //----< construct T to string converter >---------------------- template TtoStr::TtoStr(T t) : _t(t) { } //----< convert T to string >---------------------------------- template std::string TtoStr::convert() { std::ostringstream temp; temp << _t; return temp.str(); } //----< convert string to T in constructor >------------------- template StrToT::StrToT(const std::string &s) { std::istringstream temp(s); temp >> _t; } //----< return converted value >------------------------------- template T StrToT::convert() { return _t; } #endif