# HTML Driver

Topics

:

Overview
Constants
Enumerations
C++ ostream Functions
Hypertext Base Class
Hypertext Class

Overview

The hypertext driver classes are used to generate HTML documents from within a C++ program. The hypertext driver class is a base class that uses the C++ ostream library to write HTML tags and text to a specified stream. The hypertext class is used to write HTML document templates to a specified stream.

Constants

    const int DefaultPrecision = 2; // Default precision for floating points

Enumerations

    // Define some common HTML colors
    const int NumHTMLColors = 16;
    enum htmCOLORS {
      htmBLACK       = 0x000000,
      htmDARKBLUE    = 0x000080,
      htmBLUE        = 0x0000ff,
      htmGREEN       = 0x008000,
      htmTEAL        = 0x008080,
      htmBRIGHTGREEN = 0x00ff00,
      htmTURQUOISE   = 0x00ffff,
      htmDARKRED     = 0x800000,
      htmVIOLET      = 0x800080,
      htmDARKYELLOW  = 0x808000,
      htmDARKGRAY    = 0x808080,
      htmGRAY        = 0xC0C0C0,
      htmRED         = 0xff0000,
      htmPINK        = 0xff00ff,
      htmYELLOW      = 0xffff00,
      htmWHITE       = 0xffffff
    };

    // Define some common HTML fonts
    const int NumHTMLFonts = 4;
    enum htmFONTS {
      htmARIAL,       // Arial
      htmARIALBLACK,  // Arial Black
      htmARIALNARROW, // Arial Narrow
      htmCOURIER      // Courier New
    };

C++ ostream Functions

The ostream functions are inline functions that operate the same way that the standard I/O manipulators do in C++. This allows you to format the I/O within an I/O statement relative to the text that has special meaning in an HTML document, for example:

    stream << center << "Mytext Document" << ecenter << endl;

In this example the line of text will be centered in the document. Each HTML manipulator is named after its respective tag in lower case letters and will always end with the letter "e". The following is a list of all the HTML manipulators provided:

Manipulators used to print characters with special meaning
Manipulators used to print special characters
Manipulators used to create HMTL tags
HTML document formatting manipulators
HTML font formatting manipulators
HTML table manipulators

Manipulators used to print characters with special meaning:

lt

- Outputs a less then sign
gt - Outputs a greater then sign
amp - Outputs an ampersand
quot - Outputs a double quotation mark

Manipulators used to print special characters:

nbsp

- Outputs a non-breaking space
hyphen - Outputs a soft hyphen
copyright - Outputs a copyright symbol ©
registered - Outputs a registered symbol ®

Manipulators used to create HMTL tags:

stag

- Starts an HTML tag
etag - Ends an HTML tag
ctag - Closes an HTML tag

HTML document formatting manipulators:

anchor

- Start anchor with no parameters
eanchor - End anchor
comment - Start comment
ecomment - End comment
body - Start body with no parameters
ebody - End body
br - Insert a line break
head - Start head
ehead - End head
html - Start html
ehtml - End html
hr - Insert a horizontal rule
par - Start paragraph
epar - End paragraph
pre - Start preformatted text
epre - End preformatted text
title - Start title
etitle - End title

HTML font formatting manipulators:

bold

- Start bold
ebold - End bold
center - Start center
ecenter - End center
font - Start font with no parameters
efont - End font
h1 - Start heading
eh1 - End heading
h2 - Start heading
eh2 - End heading
h3 - Start heading
eh3 - End heading
italic - Start italic
eitalic - End italic
underline - Start underline
eunderline - End underline

HTML table manipulators:

table

- Start table with no parameters
otable - Open a table tag
etable - End table
tr - Start table row with no parameters
etr - End table row
th - Start table header row with no parameters
eth - End table header
td - Start table data with no parameters
etd - End table data

Hyper Text Base Class

The hypertext driver class is a base class that uses the C++ ostream library to write HTML tags and text to a specified stream. It has several overloads of the left shift operator relative to the standard C++ I/O and manipulators and the HTML manipulators, as well the C++ built-in data types: char, char *, int, long, float, and double. The hypertext driver base class also includes several HTML tag functions that allows you to specific parameters within the tag. All the tag functions are named after their respective tag in upper case letters.

Hypertext driver base class functions
Functions used to write built-in data types
Overloaded operators
HTML document formatting functions
HTML font formatting functions
HTML table functions

Hypertext driver base class functions:

HyperTextDrv::HyperTextDrv(ostream &s)

- Class constructor responsible for setting a pointer the specified output stream. Also sets the default precision for floating point values and the interpretation of spaces.

void HyperTextDrv::WriteString(const char *s)

- Used to write a single line of text to the stream, filtering all the characters that have special meaning in HTML documents. This function is implemented as a virtual function so that a derived class can define its own version if needed.

void HyperTextDrv::WriteChar(const unsigned char c) const

- Used to write a single character to the stream, filtering all the characters that have special meaning in HTML documents. This function is implemented as a virtual function so that a derived class can define its own version if needed.

Functions used to write built-in data types:

void HyperTextDrv::Write

- There are several overloads of the Write() function used to write any of the C++ built-in data types to the output stream. Overloads of the Write() function include signed and unsigned, constant and non-constant versions for: char, char *, int, long, float, and double.

void HyperTextDrv::precision(int p)

- This function is used to set the decimal precision for floating point values. By default a decimal precision of two is used.

void HyperTextDrv::eat_space()

- This function set the space interpretation which will cause all spaces to be treated a non-breaking spaces.

void HyperTextDrv::put_space()

- This function is used to reset the space interpretation which will cause all spaces to be treated as normal. By default all spaces are treated as normal.

Overloaded operators:

Several overloads of the left shift operator relative to the standard C++ I/O manipulators and the HTML manipulators, as well the C++ built-in data types are provided. The overloaded left shift operator allows you to use hypertext text objects just like ostream objects:

    HyperTextDrv htm(stream);
    htm << center << "Some document text" << ecenter << endl;
    htm << par << endl;
    htm << "First Amount = " << 1.28 << endl;

HTML document formatting functions:

void HyperTextDrv::ANCHOR(const char *s)

- Write anchor tag with parameters.

void HyperTextDrv::BODY(const char *s)

- Write body tag with parameters.

void HyperTextDrv::COMMENT(const char *s)

- Write a comment.

void HyperTextDrv::PAR(const char *s)

- Write paragraph tag with parameters.

HTML font formatting functions:

void HyperTextDrv::BOLD(const char *s)

- Write string in bold letters.

void HyperTextDrv::CENTER(const char *s)

- Center a string.

void HyperTextDrv::FONT(const char *s)

- Write a font tag with parameters.

void HyperTextDrv::H1(const char *s)

- Write a text heading.

void HyperTextDrv::H2(const char *s)

- Write a text heading.

void HyperTextDrv::H3(const char *s)

- Write a text heading.

void HyperTextDrv::ITALIC(const char *s)

- Write a string in italics.

void HyperTextDrv::UNDERLINE(const char *s)

- Under line a string.

HTML table functions:

void HyperTextDrv::TABLE(const char *s)

- Write a table tag with parameters.

void HyperTextDrv::TD(const char *s)

- Start a table data tag with parameters.

void HyperTextDrv::TH(const char *s)

- Start a table header with parameters.

void HyperTextDrv::TR(const char *s)

- Start a table row with parameters.

Hyper Text Class

The hypertext class is used to write HTML document templates to a specified stream. This class inherits all the functionality of the hypertext drive class and adds additional functions to create HTML documents.

Hypertext driver class functions
Functions used to create HTML document templates
Table Functions
Reporting functions

Hypertext driver class functions:

HyperText::HyperText(ostream &s) - Class constructor responsible for setting a pointer the specified output stream.

Functions used to create HTML document templates:

void HyperText::Prologue(const char *doc_title = 0)

- Used to create an HTML document prologue. If no document title is specified a default on will be provided.

void HyperText::StartBody(const char *parameters = 0)

- Used to start the body of an HTML document. You can specify body parameters such as a background color or image.

void HyperText::StartBody(htmCOLORS color)

- Used to start the body of an HTML document specifying a specific background color. htmCOLORS is an enumeration used to set the background to one of several standard colors.

void HyperText::Epilogue()

- Used to end the HTML document.

void HyperText::DocHeader(const char *doc_title = 0)

- Used to write a document header. If no document title is specified a default one will be provided.

void HyperText::DocTrailer()

- Used to write a document trailer.

Table Functions:

void HyperText::GenTable(int cell_spacing = 1, int cell_padding = 4, int width = 75, int border = 1, htmCOLORS bordercolor = htmBLACK)

- Used to start an HTML table specifying the cell spacing, cell padding, table width, border size and color. htmCOLORS is an enumeration used to set the border to one of several standard colors.

void HyperText::StartTableRow()

- Used to start a table row.

void HyperText::EndTableRow()

- Used to end a table row.

void HyperText::TableHeader(char *valign="CENTER", int colspan = 1, int rowspan = 1, int width = 10)

- Used to start a table header specifying the vertical alignment, row span, and width.

void HyperText::EndTableHeader()

- Used to end a table header.

void HyperText::TableData(char *valign="TOP", int colspan = 1, int rowspan = 1, int width = 10)

- Used to start a table data tag specifying the vertical alignment, row span, and width.

void HyperText::EndTableData()

- Used to end a table data tag.

void HyperText::EndTable()

- Used to end the table.

Reporting functions:

void HyperText::GetSystemTime(char *s, int full_month_name = 1)

- This function is used to generate a time and date stamp passed back in the "s" variable. By default a full month name will be used. If the "full_month_name" variable is false an abbreviated month name will be used.

End Of Document