ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/Host.cpp
Revision: 33
Committed: 2003-11-15T00:38:48-08:00 (21 years, 7 months ago) by Douglas Thrift
File size: 1867 byte(s)
Log Message:
Input and output of stuff.

File Contents

# User Rev Content
1 Douglas Thrift 31 // Host Update
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include "Host.hpp"
8    
9     void Host::setSince(const string& since)
10     {
11 Douglas Thrift 32 struct tm when;
12    
13     strptime(since.c_str(), "%m/%d/%Y %H:%M:%S %Z", &when);
14    
15     time_t time = mktime(&when);
16    
17     localtime_r(&time, &when);
18    
19     char then[45];
20    
21     strftime(then, 45, "%A %B %e, %Y %l:%M:%S %p %Z", &when);
22    
23     this->since = then;
24 Douglas Thrift 31 }
25    
26     ostream& operator<<(ostream& output, Host& host)
27     {
28 Douglas Thrift 33 output << "<tr>\n";
29 Douglas Thrift 31
30 Douglas Thrift 33 if (host.host != "") output << "<td>" << host.host << "</td>\n";
31     if (host.name != "") output << "<td>" << host.name << "</td>\n";
32     if (host.address != "") output << "<td>" << host.address << "</td>\n";
33     if (host.platform != "") output << "<td>" << host.platform << "</td>\n";
34     if (host.since != "") output << "<td>" << host.since << "</td>\n";
35    
36     output << "</tr>\n";
37    
38 Douglas Thrift 31 return output;
39     }
40    
41     istream& operator>>(istream& input, Host& host)
42     {
43 Douglas Thrift 33 bool done = false;
44    
45     do
46     {
47     switch (input.peek())
48     {
49     case 'h':
50     if (host.host != "")
51     {
52     done = true;
53 Douglas Thrift 31
54 Douglas Thrift 33 continue;
55     }
56     break;
57     case 'n':
58     if (host.name != "")
59     {
60     done = true;
61    
62     continue;
63     }
64     break;
65     case 'a':
66     if (host.address != "")
67     {
68     done = true;
69    
70     continue;
71     }
72     break;
73     case 'p':
74     if (host.platform != "")
75     {
76     done = true;
77    
78     continue;
79     }
80     break;
81     case 's':
82     if (host.since != "")
83     {
84     done = true;
85    
86     continue;
87     }
88     break;
89     default:
90     done = true;
91     continue;
92     }
93    
94     string name, value;
95    
96     getline(input, name, '=');
97     getline(input, value);
98    
99     if (name == "host")
100     {
101     host.host = value;
102     }
103     else if (name == "name")
104     {
105     host.name = value != "" ? value : "&nbsp;";
106     }
107     else if (name == "address")
108     {
109     host.address = value;
110     }
111     else if (name == "platform")
112     {
113     host.platform = value;
114     }
115     else if (name == "since")
116     {
117     host.setSince(value);
118     }
119     }
120     while (!done && input.good());
121    
122 Douglas Thrift 31 return input;
123     }

Properties

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