// Site Mapper // // Douglas Thrift // // $Id$ #include "Matcher/Matcher.hpp" #include "SiteMapper.hpp" Page::Page(const std::string& address, const std::string& path, const std::string& title) : address(address), path(path), title(title), tab(0) {} Page::Page(const std::string& url, const std::string& title) : title(title), tab(0) { setUrl(url); } void Page::setUrl(const std::string& url) { Matcher matcher("^http://(.+)(/.*)?$"); if (url == matcher) { address = matcher[1]; if (matcher.size() > 2) { path = matcher[2]; } else { path = '/'; } } else { std::cerr << program << ": Page.setUrl(" << url << ") failure.\n"; exit(1); } } bool Page::operator==(const std::string& thing) { if (address == thing) { return true; } else if (path == thing) { return true; } else if (title == thing) { return true; } return false; } bool Page::operator==(Matcher& matcher) { if (address == matcher) { return true; } else if (path == matcher) { return true; } else if (title == matcher) { return true; } return false; } bool Page::operator==(const Page& page) const { if (address == page.address) { return path == page.path || title == page.title; } return false; } std::ostream& operator<<(std::ostream& output, Page& page) { std::string tab(page.tab, '\t'); output << tab << "" << page.title << "\n"; if (!page.children.empty()) { output << tab << "\t\n"; for (unsigned index(0); index < page.children.size(); ++index) { output << page.children[index](page.tab + 2) << '\n'; } output << tab << "\t\n"; } output << tab << ""; return output; }