home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / htmldrv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-30  |  12.2 KB  |  284 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: htmldrv.h 
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer 
  8. // File Creation Date: 03/09/1999 
  9. // Date Last Modified: 03/31/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. The HyperTextDrv and HyperText class is used to create HTML
  32. documents. The HyperTextDrv class is a base class that uses
  33. the C++ ostream library to write HTML tags and text to a
  34. specified stream. The HyperText class is used to write
  35. HTML document templates to a specified stream,
  36. */
  37. // ----------------------------------------------------------- //   
  38. #ifndef __HTMLDRV_HPP__
  39. #define __HTMLDRV_HPP__
  40.  
  41. #include <fstream.h>
  42.  
  43. // Constants
  44. const int DefaultPrecision = 2; // Default precision for floating points
  45.  
  46. // Define some common HTML colors
  47. const int NumHTMLColors = 16;
  48. enum htmCOLORS { 
  49.   htmBLACK       = 0x000000,
  50.   htmDARKBLUE    = 0x000080,
  51.   htmBLUE        = 0x0000ff,
  52.   htmGREEN       = 0x008000,
  53.   htmTEAL        = 0x008080,
  54.   htmBRIGHTGREEN = 0x00ff00,
  55.   htmTURQUOISE   = 0x00ffff,
  56.   htmDARKRED     = 0x800000,
  57.   htmVIOLET      = 0x800080,
  58.   htmDARKYELLOW  = 0x808000,
  59.   htmDARKGRAY    = 0x808080,
  60.   htmGRAY        = 0xC0C0C0,
  61.   htmRED         = 0xff0000,
  62.   htmPINK        = 0xff00ff,
  63.   htmYELLOW      = 0xffff00,
  64.   htmWHITE       = 0xffffff
  65. };
  66.  
  67. // Define some common HTML fonts
  68. const int NumHTMLFonts = 4;
  69. enum htmFONTS {
  70.   htmARIAL,       // Arial
  71.   htmARIALBLACK,  // Arial Black
  72.   htmARIALNARROW, // Arial Narrow
  73.   htmCOURIER      // Courier New
  74. };
  75.  
  76. // Functions used to print characters with special meaning 
  77. inline ostream& lt(ostream &s)   { return s << "<";  } // Less than sign
  78. inline ostream& gt(ostream &s)   { return s << ">";  } // Greater than sign
  79. inline ostream& amp(ostream &s)  { return s << "&";  } // Ampersand
  80. inline ostream& quot(ostream &s) { return s << "\""; } // Double quote sign
  81.  
  82. // Functions used to print special characters
  83. inline ostream& nbsp(ostream &s) { return s << " "; }   //Non-brk space
  84. inline ostream& hyphen(ostream &s) { return s << "­"; }  // Soft-hyphen
  85. inline ostream& copyright(ostream &s) { return s << "©"; } 
  86. inline ostream& registered(ostream &s) { return s << "®"; }
  87.  
  88. // Functions used to create HMTL tags
  89. inline ostream& stag(ostream &s) { return s << "<";  } // Start tag  
  90. inline ostream& etag(ostream &s) { return s << "</"; } // End tag
  91. inline ostream& ctag(ostream &s) { return s << ">";  } // Close tag 
  92.  
  93. // HTML document formatting functions
  94. inline ostream& anchor(ostream &s) { return s << "<A>"; }
  95. inline ostream& eanchor(ostream &s) { return s << "</A>"; }
  96. inline ostream& comment(ostream &s) { return s << "<!-- "; }
  97. inline ostream& ecomment(ostream &s) { return s << " -->"; }
  98. inline ostream& body(ostream &s) { return s << "<BODY>"; }
  99. inline ostream& ebody(ostream &s) { return s << "</BODY>"; }
  100. inline ostream& br(ostream &s) { return s << "<BR>"; }
  101. inline ostream& head(ostream &s) { return s << "<HEAD>"; }
  102. inline ostream& ehead(ostream &s) { return s << "</HEAD>"; }
  103. inline ostream& html(ostream &s) { return s << "<HTML>"; }
  104. inline ostream& ehtml(ostream &s) { return s << "</HTML>"; }
  105. inline ostream& hr(ostream &s) { return s << "<HR>"; }
  106. inline ostream& par(ostream &s) { return s << "<P>"; }     
  107. inline ostream& epar(ostream &s) { return s << "</P>"; }   
  108. inline ostream& pre(ostream &s) { return s << "<PRE>"; }   
  109. inline ostream& epre(ostream &s) { return s << "</PRE>"; } 
  110. inline ostream& title(ostream &s) { return s << "<TITLE>"; }
  111. inline ostream& etitle(ostream &s) { return s << "</TITLE>"; }
  112.  
  113. // HTML font formatting functions
  114. inline ostream& bold(ostream &s) { return s << "<B>"; } 
  115. inline ostream& ebold(ostream &s) { return s << "</B>"; } 
  116. inline ostream& center(ostream &s) { return s << "<CENTER>"; } 
  117. inline ostream& ecenter(ostream &s) { return s << "</CENTER>"; } 
  118. inline ostream& font(ostream &s) { return s << "<FONT>"; }
  119. inline ostream& efont(ostream &s) { return s << "</FONT>"; }
  120. inline ostream& h1(ostream &s) { return s << "<H1>"; } 
  121. inline ostream& eh1(ostream &s) { return s << "</H1>"; } 
  122. inline ostream& h2(ostream &s) { return s << "<H2>"; } 
  123. inline ostream& eh2(ostream &s) { return s << "</H2>"; } 
  124. inline ostream& h3(ostream &s) { return s << "<H3>"; } 
  125. inline ostream& eh3(ostream &s) { return s << "</H3>"; }
  126. inline ostream& italic(ostream &s) { return s << "<I>"; }
  127. inline ostream& eitalic(ostream &s) { return s << "</I>"; }
  128. inline ostream& underline(ostream &s) { return s << "<U>"; }
  129. inline ostream& eunderline(ostream &s) { return s << "</U>"; }
  130.  
  131. // HTML table functions
  132. inline ostream& table(ostream &s) { return s << "<TABLE>"; } 
  133. inline ostream& otable(ostream &s) { return s << "<TABLE "; } 
  134. inline ostream& etable(ostream &s) { return s << "</TABLE>"; } 
  135. inline ostream& tr(ostream &s) { return s << "<TR>"; } 
  136. inline ostream& etr(ostream &s) { return s << "</TR>"; } 
  137. inline ostream& th(ostream &s) { return s << "<TH>"; } 
  138. inline ostream& eth(ostream &s) { return s << "</TH>"; } 
  139. inline ostream& td(ostream &s) { return s << "<TD>"; } 
  140. inline ostream& etd(ostream &s) { return s << "</TD>"; } 
  141.  
  142. // HTML driver base class
  143. class HyperTextDrv
  144. {
  145. public:
  146.   HyperTextDrv(ostream &s);
  147.   virtual ~HyperTextDrv();
  148.  
  149. protected: // Filtered output functions used to write HTML text 
  150.   virtual void WriteString(const char *s);
  151.   virtual void WriteChar(const unsigned char c) const;
  152.  
  153. public: // Functions used to write built-in data types 
  154.   void Write(const char c) const;
  155.   void Write(const unsigned char c) const;
  156.   void Write(char c);
  157.   void Write(unsigned char c);
  158.   void Write(const char *s);
  159.   void Write(char *s);
  160.   void Write(const unsigned char *s);
  161.   void Write(unsigned char *s);
  162.   void Write(const long val) const;
  163.   void Write(long val);
  164.   void Write(const unsigned long val) const;
  165.   void Write(unsigned long val);
  166.   void Write(const int val) const;
  167.   void Write(int val);
  168.   void Write(const unsigned int val) const;
  169.   void Write(unsigned int val);
  170.   void Write(double val); 
  171.   void Write(const double val) const; 
  172.   void Write(float val); 
  173.   void Write(const float val) const; 
  174.  
  175. public: 
  176.   void precision(int p) { dec_precision = p; } // Floating precision
  177.   void eat_space() { non_breaking_sp = 1; }    // Use non-breaking spaces
  178.   void put_space() { non_breaking_sp = 0; }    // Use breaking spaces
  179.   
  180. public: // Overloaded operators
  181.   ostream &operator<<(ostream & (*_f)(ostream&));
  182.   HyperTextDrv &operator<<(char *s);
  183.   HyperTextDrv &operator<<(const char *s);
  184.   HyperTextDrv &operator<<(unsigned char *s);
  185.   HyperTextDrv &operator<<(const unsigned char *s);
  186.   HyperTextDrv &operator<<(char c);
  187.   const HyperTextDrv &operator<<(const char c) const;
  188.   HyperTextDrv &operator<<(unsigned char c);
  189.   const HyperTextDrv &operator<<(const unsigned char c) const;
  190.   HyperTextDrv &operator<<(long val);
  191.   const HyperTextDrv &operator<<(const long val) const;
  192.   HyperTextDrv &operator<<(unsigned long val);
  193.   const HyperTextDrv &operator<<(const unsigned long val) const;
  194.   HyperTextDrv &operator<<(int val);
  195.   const HyperTextDrv &operator<<(const int val) const;
  196.   HyperTextDrv &operator<<(unsigned int val);
  197.   const HyperTextDrv &operator<<(const unsigned int val) const;
  198.   const HyperTextDrv &operator<<(const float val) const;
  199.   HyperTextDrv &operator<<(float val);
  200.   const HyperTextDrv &operator<<(const double val) const;
  201.   HyperTextDrv &operator<<(double val);
  202.   
  203. public: // HTML document formatting functions
  204.   void ANCHOR(const char *s) { *(stream) << "<A" << s << ">"; }
  205.   void ANCHOR(char *s) { *(stream) << "<A" << s << ">"; }
  206.   void BODY(const char *s) { *(stream) << "<BODY " << s << ">"; }
  207.   void BODY(char *s) { *(stream) << "<BODY " << s << ">"; }
  208.   void COMMENT(const char *s) { *(stream) << "<!-- " << s << " -->"; }
  209.   void COMMENT(char *s) { *(stream) << "<!-- " << s << " -->"; }
  210.   void PAR(const char *s) { *(stream) << "<P " << s << ">"; }
  211.   void PAR(char *s) { *(stream) << "<P " << s << ">"; }
  212.   
  213. public: // HTML font formatting functions
  214.   void BOLD(const char *s) { *(stream) << "<B>" << s << "</B>"; } 
  215.   void BOLD(char *s) { *(stream) << "<B>" << s << "</B>"; } 
  216.   void CENTER(const char *s) { *(stream) << "<CENTER>" << s << "</CENTER>"; } 
  217.   void CENTER(char *s) { *(stream) << "<CENTER>" << s << "</CENTER>"; } 
  218.   void FONT(const char *s) { *(stream) << "<FONT " << s << ">"; }
  219.   void FONT(char *s) { *(stream) << "<FONT " << s << ">"; }
  220.   void H1(const char *s) { *(stream) << "<H1>" << s << "</H1>"; } 
  221.   void H1(char *s) { *(stream) << "<H1>" << s << "</H1>"; } 
  222.   void H2(const char *s) { *(stream) << "<H2>" << s << "</H2>"; } 
  223.   void H2(char *s) { *(stream) << "<H2>" << s << "</H2>"; } 
  224.   void H3(const char *s) { *(stream) << "<H3>" << s << "</H3>"; } 
  225.   void H3(char *s) { *(stream) << "<H3>" << s << "</H3>"; } 
  226.   void ITALIC(const char *s) { *(stream) << "<I>" << s << "</I>"; }
  227.   void ITALIC(char *s) { *(stream) << "<I>" << s << "</I>"; }
  228.   void UNDERLINE(const char *s) { *(stream) << "<U>" << s << "</U>"; }
  229.   void UNDERLINE(char *s) { *(stream) << "<U>" << s << "</U>"; }
  230.   
  231. public: // HTML table functions
  232.   void TABLE(const char *s) { *(stream) << "<TABLE " << s << ">"; } 
  233.   void TABLE(char *s) { *(stream) << "<TABLE " << s << ">"; } 
  234.   void TD(const char *s) { *(stream) << "<TD " << s << ">"; }
  235.   void TD(char *s) { *(stream) << "<TD " << s << ">"; }
  236.   void TH(const char *s) { *(stream) << "<TH " << s << ">"; }
  237.   void TH(char *s) { *(stream) << "<TH " << s << ">"; }
  238.   void TR(const char *s) { *(stream) << "<TR " << s << ">"; }
  239.   void TR(char *s) { *(stream) << "<TR " << s << ">"; }
  240.  
  241. protected:
  242.   ostream *stream;     // Stream to output HTML data
  243.   int dec_precision;   // Decimal point precision for floating points  
  244.   int non_breaking_sp; // True if using non-breaking spaces
  245. };
  246.  
  247. class HyperText : public HyperTextDrv
  248. {
  249. public:
  250.   HyperText(ostream &s) : HyperTextDrv(s) { }
  251.   ~HyperText() { }
  252.   
  253. public: // Functions used to create HTML document templates
  254.   void Prologue(const char *doc_title = 0);
  255.   void StartBody(const char *parameters = 0);
  256.   void StartBody(htmCOLORS color);
  257.   void Epilogue();
  258.   void DocHeader(const char *doc_title = 0);
  259.   void DocTrailer();
  260.   
  261. public: // Table Functions
  262.   void GenTable(int cell_spacing = 1, int cell_padding = 4, int width = 75,
  263.         int border = 1, htmCOLORS bordercolor = htmBLACK); 
  264.   void StartTableRow();
  265.   void EndTableRow() { *(stream) << etr << endl; }
  266.   void TableHeader(char *valign="CENTER", int colspan = 1, int rowspan = 1,
  267.            int width = 10);
  268.   void EndTableHeader() { *(stream) << eth << endl; }
  269.   void TableData(char *valign="TOP", int colspan = 1, int rowspan = 1,
  270.          int width = 10);
  271.   void EndTableData() { *(stream) << etd << endl; }
  272.   void EndTable() { *(stream) << etable << endl; }
  273.   
  274. public: // Reporting functions
  275.   void GetSystemTime(char *s, int full_month_name = 1);
  276. };
  277.  
  278. #endif  // __HTMLDRV_HPP__ 
  279. // ----------------------------------------------------------- // 
  280. // ------------------------------- //
  281. // --------- End of File --------- //
  282. // ------------------------------- //
  283.  
  284.