A stylesheet iterator which points to the stylesheet item to be erased. User must insure the iterator position is valid.
beg_pos
A stylesheet iterator which points to the first stylesheet item in the range to be erased. User must insure the iterator position is valid.
end_pos
A stylesheet iterator which points just past the last stylesheet item in the range to be erased. User must insure the iterator position is valid.
selector
A string which specifies a selector for the rule to be erased.
Returns
In the first 2 varieties, a stylesheet iterator which points just past the erased stylesheet item, or range of erased items. In the 3rd variety,
returns true if the rule was found and erased, false otherwise.
Remarks
This operation is used to remove stylesheet items from the called stylesheet. In the first variety, a single stylesheet item which is pointed to by
the passed stylesheet iterator is erased. In the second variety, a range of items can be erased, determined by the passed stylesheet iterators. In
the third variety, only a stylesheet rule can be erased, which is determined by the passed selector. This variety is handy for deleting a specific
rule in the stylesheet, if you know the rule's selector.
Complexity
Logarithmic
Examples
1st Variety
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
struct compare_selector_functor
{
compare_selector_functor(const std::string& s) : sel(s) {}
bool operator() (const Xport::stylesheet_item& item) { return item.selector() == sel; }
std::string sel;
};
int main(int argc, char* argv[])
{
using namespace Xport;
// create an xhtml strict root document
document doc(root_doc);
stylesheet ss;
// populate document
std::cout << "Creating Xport Brochure.\n\n";
xport_brochure broch;
broch.create(doc, ss);
// print the stylesheet to cout
std::cout << "Xport Brochure stylesheet.\n\n";
stylesheet_formatter fmtr(std::cout);
ss.write(fmtr);
// find rule for h4 using std::find
stylesheet::iterator it = std::find_if(ss.begin(), ss.end(), compare_selector_functor("h4"));
if (it != ss.end()) {
// erase the h4 rule
std::cout << "\n\nErasing the h4 rule.\n\n";
ss.erase(it);
}
std::cout << "Stylesheet with the h4 rule erased.\n\n";
ss.write(fmtr);
}
2nd Variety
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
struct compare_selector_functor
{
compare_selector_functor(const std::string& s) : sel(s) {}
bool operator() (const Xport::stylesheet_item& item) { return item.selector() == sel; }
std::string sel;
};
int main(int argc, char* argv[])
{
using namespace Xport;
// create an xhtml strict root document
document doc(root_doc);
stylesheet ss;
// populate document
std::cout << "Creating Xport Brochure.\n\n";
xport_brochure broch;
broch.create(doc, ss);
// print the stylesheet to cout
std::cout << "Xport Brochure stylesheet.\n\n";
stylesheet_formatter fmtr(std::cout);
ss.write(fmtr);
// find rule for #class_categories using std::find
stylesheet::iterator it = std::find_if(ss.begin(), ss.end(), compare_selector_functor("#class_categories"));
if (it != ss.end()) {
// erase all rules at and after #class_categories
std::cout << "\n\nErasing the #class_categories rule and all rules after.\n\n";
ss.erase(it, ss.end());
}
std::cout << "Stylesheet with all rules #class_categories and after erased.\n\n";
ss.write(fmtr);
}
Datasoft Solutions is proud to present their landmark product, Work Time Studio. Utilizing the tree container library, Work Time Studio provides
unparalleled features in personal time, project and task management
software. If you're looking for a way to increase your productivity,
visit Work Time Studio's product website, and start being more productive
today.