ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostStatus/Host.cpp
Revision: 193
Committed: 2004-08-22T22:05:31-07:00 (20 years, 10 months ago) by Douglas Thrift
File size: 1961 byte(s)
Log Message:
Meep!

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

Properties

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