#ifndef TRACE_H #define TRACE_H ///////////////////////////////////////////////////////////////////// // trace.h - simple display utility functions to trace // // ver 1.0 operation of code in other modules // // // // Lanaguage: Visual C++, ver 6.0, SP 5.0 // // Platform: Dell Dimension 8100, Win2000, SP 2.0 // // Application: general utility routines, Spring 2002 // // Author: Jim Fawcett, CST 2-187, Syracuse University, // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// /* Module Operations: ================== This module provides a few simple utility functions to help create displays on an ostream. Public Interface: ================= trace("some text", 3.14159); trace("some text", 3.14159, out); trace("a message"); string s = toString(3.1415927); title("a title"); title("a subtitle",'-'); */ ///////////////////////////////////////////////////////////////////// // Build Process // ///////////////////////////////////////////////////////////////////// // Required Files: // // trace.h, trace.cpp // // // // Compiler Command: // // cl /GX /DTEST_TRACE trace.cpp // ///////////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 : 24 Feb 02 - first release */ // #include #include using namespace std; //----< display string followed by object value to an ostream >------ template void trace(const char *msg, T t, std::ostream &out = cout) { out << "\n " << msg << t; } //----< display a text message to an ostream >----------------------- inline void trace(const char *msg, std::ostream &out = cout) { out << "\n " << msg; } //----< convert a numeric object's value to a string >--------------- template std::string toString(const T &t) { std::ostringstream temp; temp << t; return temp.str(); } //----< display a title on an ostream >------------------------------ inline void title(const char *msg,char underline = '-',std::ostream &out = cout) { if(underline == '=') out << "\n " << std::string(strlen(msg)+2, underline).c_str() << "\n " << msg << "\n " << std::string(strlen(msg)+2, underline).c_str(); else out << "\n " << msg << "\n " << std::string(strlen(msg)+2, underline).c_str(); } // //----< display string followed by object value to an ostream >------ template std::string strace(const char *msg, T t) { ostringstream out; out << "\n " << msg << t; return out.str(); } //----< display a text message to an ostream >----------------------- inline std::string strace(const char *msg) { std::string retVal = string("\n ") + msg; return retVal; } //----< display a title on an ostream >------------------------------ inline std::string stitle(const char *msg,char underline = '-') { ostringstream out; if(underline == '=') out << "\n " << std::string(strlen(msg)+2, underline).c_str() << "\n " << msg << "\n " << std::string(strlen(msg)+2, underline).c_str(); else out << "\n " << msg << "\n " << std::string(strlen(msg)+2, underline).c_str(); return out.str(); } #endif