Xport Interface: formatter::operator <<
Writes the passed document or markup object to the output.
friend formatter& operator <<(1st Variety
formatter& fmtr,
document& doc
);
friend formatter& operator <<( 2nd Variety
formatter& fmtr,
markup& mkup
);
Parameters
fmtr
The formatter
object which will format and write the document
or markup
object on the rhs.
doc
A reference to the rhs document
object, which will be formatted and written to the output.
mkup
A reference to the rhs markup
object, which will be formatted and written to the output.
Returns
Returns a reference to the formatter
object, which allows the chaining of the operation, which is most useful when inserting multiple document
or markup
objects.
Remarks
These operations offer a convenient way to format and write a document
or markup
object. The result of these operations are
equivalent to the operations document::write() and markup::write(). These two
operations do not allow chaining, however, and do not convey the intention as well as this operation.
The first variety formats and writes a document
object. The second variety formats and writes a markup
object. Where these
objects are written is determined by the output stream or file which was specified in the formatter's
constructor.
Complexity
Logarithmic
Example
1st Variety
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
*doc.title() << "Test Document";
*doc.body() << (element(h1) << "Formatter Test Document");
markup::iterator it = doc.body()->push_back(element(p));
*it << "This document displays the use of formatter's insertion operator. "
<< "Formatter's insertion operator allows a intuitive way to format and send "
<< "markup and documents to a specified output. To use this operation "
<< "first create a formatter object and specify the output in it's constructor. "
<< "Then set any desired options on the format object. Then, simply use the "
<< "insertion operator (<<) to format and send document objects or "
<< "markup objects to the output.";
formatter fmtr(std::cout);
fmtr.option(max_line_length, 70);
fmtr << doc;
std::cout << "\n\n";
return 0;
}
2nd Variety
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
*doc.title() << "Test Document";
*doc.body() << (element(h1) << "Formatter Test Document");
markup::iterator it = doc.body()->push_back(element(ul));
*it << (element(li) << "List item 1");
*it << (element(li) << "List item 2");
*it << (element(li) << "List item 3");
formatter fmtr(std::cout);
fmtr.option(max_line_length, 70);
fmtr << *doc.title();
std::cout << "\n\n";
fmtr << *it;
std::cout << "\n\n";
return 0;
}