ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapper/Page.cpp
Revision: 637
Committed: 2005-12-31T21:32:21-08:00 (19 years, 5 months ago) by douglas
File size: 1094 byte(s)
Log Message:
Use ext::RedBlackMap and ext::Vector instead of std::multimap.

File Contents

# User Rev Content
1 Douglas Thrift 128 // Site Mapper
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 635 #include <cxx/standard.hh>
8 douglas 559
9 douglas 635 #include <api/pcre/regex.hpp>
10 douglas 559
11 douglas 328 #include "SiteMapper.hpp"
12 Douglas Thrift 128
13 douglas 637 void Page::SetUrl(const cse::String &url)
14 Douglas Thrift 128 {
15 douglas 559 static api::Pcre::RegEx url_(_B("^http://([^/]+)(/.*)?$"));
16 douglas 330
17 douglas 559 if (api::Pcre::RegEx::Match match = url_(url))
18 Douglas Thrift 128 {
19 douglas 559 address = match[1];
20     path = !match[2].IsEmpty() ? match[2] : cse::String(_B("/"));
21 Douglas Thrift 128 }
22     else
23 douglas 559 throw ext::StringException(url);
24 Douglas Thrift 128 }
25 Douglas Thrift 129
26 douglas 637 bool Page::operator==(const cse::String &thing)
27 Douglas Thrift 129 {
28 douglas 287 return address == thing || path == thing || title == thing;
29 Douglas Thrift 129 }
30    
31 douglas 637 bool Page::operator==(const Page &page) const
32 Douglas Thrift 140 {
33 Douglas Thrift 132 if (address == page.address)
34     {
35 Douglas Thrift 142 return path == page.path || title == page.title;
36 Douglas Thrift 132 }
37 Douglas Thrift 129
38     return false;
39     }
40    
41 douglas 637 xml::TextWriter &operator<<(xml::TextWriter &xml, Page &page)
42 Douglas Thrift 135 {
43 douglas 559 xml::ScopeElement item(xml, _B("item"));
44 Douglas Thrift 135
45 douglas 559 xml.OpenElement(_B("link"));
46     xml.SetAttribute(_B("address"), page.GetUrl());
47 douglas 285 xml.OutputText(page.title);
48     xml.CloseElement();
49 Douglas Thrift 135
50 douglas 285 if (!page.children.IsEmpty())
51 Douglas Thrift 135 {
52 douglas 559 xml::ScopeElement list(xml, _B("list"));
53 Douglas Thrift 135
54 douglas 423 _foreach (ext::Vector<Page>, child, page.children) xml << *child;
55 Douglas Thrift 135 }
56    
57 douglas 285 return xml;
58 Douglas Thrift 135 }

Properties

Name Value
svn:eol-style native
svn:keywords Id