Xport Interface: stylesheet_rule::insert
Inserts a stylesheet rule, comment, or import rule into the called stylesheet.
virtual stylesheet_item::iterator stylesheet_item::insert(1st Variety
const declaration& decl
);
virtual stylesheet_item::iterator stylesheet_rule::insert(2nd Variety
const const stylesheet_item::const_iterator& pos,
const declaration& decl
);
Parameters
decl
A declaration object.
pos
A stylesheet_item iterator which points to the position
where the declaration is to be inserted.
Returns
Returns a stylesheet_item iterator which points to the inserted declaration.
Remarks
This operation is used to insert declarations into the called stylesheet_rule. The 2nd variety allows you to specify where the declaration item is
inserted.
Complexity
Logarithmic
Examples
1st Variety
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
stylesheet ss;
ss.insert(stylesheet_comment("Sample stylesheet"));
stylesheet::iterator it = ss.insert(stylesheet_rule("h1"));
it->insert(declaration(text_align, "center"));
it->insert(declaration(css::color, "red"));
it = ss.insert(stylesheet_rule("p"));
it->insert(declaration(margin_left, "10px"));
it->insert(declaration(font_size, "10pt"));
stylesheet_formatter fmtr(std::cout);
ss.write(fmtr);
}
2nd Variety
#include "xhtml_doc.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
stylesheet ss;
ss.insert(stylesheet_comment("Sample stylesheet"));
stylesheet::iterator it = ss.insert(stylesheet_rule("h1"));
it->insert(declaration(text_align, "center"));
it->insert(declaration(css::color, "red"));
it->insert(declaration(margin_left, "10px"));
stylesheet_formatter fmtr(std::cout);
ss.write(fmtr);
std::cout << "\n\nInserting a font-size declaration between text-align and color.\n\n";
it = ss.begin();
++it;
stylesheet_item::const_iterator rule_it = it->begin();
++rule_it;
assert(rule_it->property() == css::color);
it->insert(rule_it, declaration(font_size, "12pt"));
ss.write(fmtr);
}