ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/SiteMapperOld/Page.cpp
Revision: 140
Committed: 2004-03-25T18:04:04-08:00 (21 years, 2 months ago) by Douglas Thrift
Original Path: SiteMapper/Page.cpp
File size: 1995 byte(s)
Log Message:
There!

File Contents

# User Rev Content
1 Douglas Thrift 128 // Site Mapper
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 Douglas Thrift 129 #include "Matcher.hpp"
8 Douglas Thrift 128 #include "Page.hpp"
9    
10     Page::Page(const string& address, const string& path, const string& title)
11     {
12     setAddress(address);
13     setPath(path);
14     setTitle(title);
15 Douglas Thrift 135
16     tab = 0;
17 Douglas Thrift 128 }
18    
19 Douglas Thrift 135 Page::Page(const string& url, const string& title)
20 Douglas Thrift 128 {
21     setUrl(url);
22 Douglas Thrift 135 setTitle(title);
23    
24     tab = 0;
25 Douglas Thrift 128 }
26    
27     void Page::setUrl(const string& url)
28     {
29     Matcher matcher("^http://(.+)(/.*)?$");
30    
31     if (url == matcher)
32     {
33     address = matcher[1];
34    
35     if (matcher.size() > 2)
36     {
37     path = matcher[2];
38     }
39     else
40     {
41     path = '/';
42     }
43     }
44     else
45     {
46     cerr << program << ": Page.setUrl(" << url << ") failure.\n";
47 Douglas Thrift 129
48     exit(1);
49 Douglas Thrift 128 }
50     }
51 Douglas Thrift 129
52     bool Page::operator==(const string& thing)
53     {
54 Douglas Thrift 132 if (address == thing)
55     {
56     return true;
57     }
58     else if (path == thing)
59     {
60     return true;
61     }
62     else if (title == thing)
63     {
64     return true;
65     }
66 Douglas Thrift 129
67     return false;
68     }
69    
70 Douglas Thrift 140 bool Page::operator==(Matcher& matcher)
71 Douglas Thrift 129 {
72 Douglas Thrift 140 if (address == matcher)
73     {
74     return true;
75     }
76     else if (path == matcher)
77     {
78     return true;
79     }
80     else if (title == matcher)
81     {
82     return true;
83     }
84    
85     return false;
86     }
87    
88     bool Page::operator==(const Page& page) const
89     {
90 Douglas Thrift 132 if (address == page.address)
91     {
92     if (path == page.path || title == page.title) return true;
93     }
94 Douglas Thrift 129
95     return false;
96     }
97    
98 Douglas Thrift 140 bool Page::operator<(const Page& page) const
99 Douglas Thrift 129 {
100 Douglas Thrift 140 if (address == page.address)
101     {
102     return path < page.path;
103     }
104 Douglas Thrift 129
105 Douglas Thrift 140 return address < page.address;
106 Douglas Thrift 129 }
107    
108 Douglas Thrift 140 bool Page::operator>(const Page& page) const
109 Douglas Thrift 129 {
110 Douglas Thrift 140 if (address == page.address)
111     {
112     return path > page.path;
113     }
114 Douglas Thrift 129
115 Douglas Thrift 140 return address > page.address;
116 Douglas Thrift 129 }
117 Douglas Thrift 135
118     ostream& operator<<(ostream& output, Page& page)
119     {
120     string tab(page.tab, '\t');
121    
122 Douglas Thrift 136 output << tab << "<item><link address=\"" << page.getUrl() << "\">"
123 Douglas Thrift 135 << page.title << "</link>\n";
124    
125     if (!page.children.empty())
126     {
127     output << tab << "\t<list>\n";
128    
129 Douglas Thrift 140 for (list<Page>::iterator itor = page.children.begin(); itor !=
130     page.children.end(); itor++)
131 Douglas Thrift 135 {
132 Douglas Thrift 140 output << (*itor)(page.tab + 1) << '\n';
133 Douglas Thrift 135 }
134    
135     output << tab << "\t</list>\n";
136     }
137    
138     output << tab << "</item>";
139    
140     return output;
141     }

Properties

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