// Site Mapper // // Douglas Thrift // // $Id$ #include "Matcher.hpp" #include "Page.hpp" Page::Page(const string& address, const string& path, const string& title) { setAddress(address); setPath(path); setTitle(title); tab = 0; } Page::Page(const string& url, const string& title) { setUrl(url); setTitle(title); tab = 0; } void Page::setUrl(const string& url) { Matcher matcher("^http://(.+)(/.*)?$"); if (url == matcher) { address = matcher[1]; if (matcher.size() > 2) { path = matcher[2]; } else { path = '/'; } } else { cerr << program << ": Page.setUrl(" << url << ") failure.\n"; exit(1); } } bool Page::operator==(const 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) { if (path == page.path || title == page.title) return true; } return false; } bool Page::operator<(const Page& page) const { if (address == page.address) { return path < page.path; } return address < page.address; } bool Page::operator>(const Page& page) const { if (address == page.address) { return path > page.path; } return address > page.address; } ostream& operator<<(ostream& output, Page& page) { 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 + 1) << '\n'; } output << tab << "\t\n"; } output << tab << ""; return output; }