Xport Interface: formatter::option
Sets or retrieves specific formatting options for the called formatter.
bool formatter::option(1st Retrieval Variety
formatter_boolean_option bool_opt
);
int formatter::option(2st Retrieval Variety
formatter_integer_option int_opt
);
std::string formatter::option(3rd Retrieval Variety
formatter_string_option string_opt
);
bool formatter::option(1st Setting Variety
formatter_boolean_option opt,
bool bool_value
);
bool formatter::option(2st Setting Variety
formatter_integer_option int_opt,
int int_value
);
bool formatter::option(3rd Setting Variety
formatter_string_option string_opt,
const std::string& string_value
);
Parameters
bool_opt
A formatter_boolean_option
enumerator which specifies the boolean option to set or retrieve.
int_opt
An formatter_integer_option
enumerator which specifies the integer option to set or retrieve.
string_opt
A formatter_string_option
enumerator which specifies the string option to set or retrieve.
bool_value
A boolean value which will set the specified boolean option.
int_opt
An integer value which will set the specified boolean option.
string_value
A string value which will set the specified boolean option.
Returns
In the first setting variety, returns a boolean value disclosing the state of the specified option.
In the second setting variety, returns an integer disclosing the integer value of the specified option.
In the third setting variety, returns a string disclosing the string value of the specified option.
Remarks
This operation is used to set and retrieve various formatting options of the called formatter
object. The various options are described
below. Many more options will be added to the list below, allowing more control of the formatted xhtml output.
All options in formatter
are distinguished, set, and retrieved, by enumerations. The table below lists the various options now available
in formatter
, and their default values. As more options are added, they will be added to the list.
Option enumerator |
Option type |
Default |
Description |
attributes_double_quoted |
boolean |
false |
Determines if attributes are single quoted (false ), or double quoted (true ). |
attributes_spaced |
boolean |
false |
Determines if attributes will be spaced judiciously (spaces around '=') or if there will be no spaces around the '='. |
max_line_length |
integer |
0 |
Determines the maximum line length for any line in the xhtml content. Lines which span greater than the max will wrap to the appropriate column.
Zero = no max. |
nesting_indent |
integer |
2 |
Determines the indentation of all nested levels in the document tree. |
Complexity
Constant
Examples
attributes_double_quoted example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
tdocument doc(root_doc);
doc.body()->attribute(attribute::title, "content container");
tmarkup::iterator it = doc.body()->insert(telement(ul, "list1"));
tmarkup::iterator lit = it->insert(telement(li, "", "litem") << "List item 1");
lit->attribute(attribute::type, "square");
*it << (telement(li, "", "litem") << "List item 2");
lit->attribute(type, "circle");
*it << (telement(li, "", "litem") << "List item 3");
lit->attribute(type, "disc");
tformatter fmtr(std::cout);
std::cout << "The formatter object writes attributes by default as " << (fmtr.option(
attributes_double_quoted) ? "double" : "single") << " quoted.\n\n";
fmtr << doc;
std::cout << "\n\n";
std::cout << "Changing the formatter option to write attributes as double quoted.\n\n";
fmtr.option(attributes_double_quoted, true);
fmtr << doc;
std::cout << "\n\n";
return 0;
}
attrubutes_spaced example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
tdocument doc(root_doc);
doc.body()->attribute(attribute::title, "content container");
tmarkup::iterator it = doc.body()->insert(telement(ul, "list1"));
tmarkup::iterator lit = it->insert(telement(li, "", "litem") << "List item 1");
lit->attribute(attribute::type, "square");
*it << (telement(li, "", "litem") << "List item 2");
lit->attribute(type, "circle");
*it << (telement(li, "", "litem") << "List item 3");
lit->attribute(type, "disc");
tformatter fmtr(std::cout);
std::cout << "The default spacing for attributes is " << (fmtr.option
(attributes_spaced) ? "spaced" : " unspaced") << "\n\n";
fmtr << doc;
std::cout << "\n\n";
std::cout << "Changing the attribute spacing option to spaced.\n\n";
fmtr.option(attributes_spaced, true);
fmtr << doc;
std::cout << "\n\n";
return 0;
}
max_line_length example
#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);
int max_len = fmtr.option(max_line_length);
std::cout << "The max line length of the formatter object is " << max_len;
if (max_len == 0) {
std::cout << " indicating there is no max line length.\n\n";
}
fmtr << doc;
std::cout << "\n\n";
std::cout << "Setting the max line length to 70, and writing the document again.\n\n";
fmtr.option(max_line_length, 70);
fmtr << doc;
return 0;
}
nesting_indent example
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
markup::iterator it = doc.body()->insert(element(ul));
*it << (element(li) << "List item 1");
*it << (element(li) << "List item 2");
*it << (element(li) << "List itme 3");
formatter fmtr(std::cout);
std::cout << "The formatter's default nesting indent is " << fmtr.option(nesting_indent) << "\n\n";
fmtr << doc;
std::cout << "\n\n";
std::cout << "Changing the nesting indent to 5.\n\n";
fmtr.option(nesting_indent, 1);
fmtr << doc;
std::cout << "\n\n";
return 0;
}