|
|
| html++ objects exist for various HTML page elements. In order to produce useful or interesting documents, the html++ objects must be combined. Combining html++ objects can be much easier than assembling the appropriate <tag></tag> HTML components, especially when producing complex pages that incorporate tables or nested elements.
|
|
|
| html++ objects are inserted into one another using the << insertion operator. The << insertion operation is overloaded for every html++ class to accept String and/or other html++ objects as appropriate. Internally, html++ objects use the virtual Add() method to implement the << insertion operator. Thus, any class that needs to modify the way objects are inserted only has to overload the Add() operator.
|
|
|
| Occasionally, an html++ object overloads the << operator in addition to the Add() method. This is necessary because some classes must restrict the types of objects that can be inserted, depending on the function of the class. An example of such a class is htmlInputCheckBoxGroup, which only accepts htmlInputCheckBox objects. This form of type checking helps protect developers from constructing objects and pages that would violate HTML syntax.
|
|
|
| The html++ class library includes a number of header files, but the only one that's necessary to include in your applications is "htmlpp.h".
|
|
|
| Let's walk through an example of using the << insertion operator to assemble a short page. The code below creates a page that contains the text "Hello World.", but with the twist that all of the text is in a bold font and the word "World." is also italicized.
|
|
|
| First we create the page object, providing the document title in the constructor. Next we create btext, a bold text object using htmlBold. Everything added to btext will appear in boldface when displayed on a browser. After that, we insert the word "Hello " into btext, followed by morre text italicized using htmlItalic. Finally, the btext object is added to the page object, and the entire page object is output using the standard C++ stream object cout.
|
|
|
| |