Panda3D
|
00001 // Filename: documentSpec.cxx 00002 // Created by: drose (28Jan03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "documentSpec.h" 00016 #include "indent.h" 00017 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: DocumentSpec::compare_to 00021 // Access: Published 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 int DocumentSpec:: 00025 compare_to(const DocumentSpec &other) const { 00026 if (_flags != other._flags) { 00027 return (_flags - other._flags); 00028 } 00029 int c = _url.compare_to(other._url); 00030 if (c != 0) { 00031 return c; 00032 } 00033 if (has_tag()) { 00034 c = _tag.compare_to(other._tag); 00035 if (c != 0) { 00036 return c; 00037 } 00038 } 00039 if (has_date()) { 00040 c = _date.compare_to(other._date); 00041 if (c != 0) { 00042 return c; 00043 } 00044 } 00045 00046 // We don't consider _request_mode or _cache_control significant in 00047 // the comparison. 00048 00049 return 0; 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: DocumentSpec::input 00054 // Access: Published 00055 // Description: Can be used to read in the DocumentSpec from a stream 00056 // generated either by output() or write(). Returns 00057 // true on success, false on failure. 00058 //////////////////////////////////////////////////////////////////// 00059 bool DocumentSpec:: 00060 input(istream &in) { 00061 // First, clear the spec. 00062 (*this) = DocumentSpec(); 00063 00064 char ch; 00065 in >> ch; 00066 if (ch != '[') { 00067 return false; 00068 } 00069 in >> _url; 00070 in >> ch; 00071 if (ch == '(') { 00072 // Scan the tag, up to but not including the closing paren. 00073 string tag; 00074 in >> ch; 00075 while (!in.fail() && !in.eof() && ch != ')') { 00076 tag += ch; 00077 // We want to include embedded whitespace, so we use get(). 00078 ch = in.get(); 00079 } 00080 set_tag(HTTPEntityTag(tag)); 00081 00082 // Now ch is the close paren following the tag; skip to the next 00083 // character. 00084 in >> ch; 00085 } 00086 00087 // Scan the date, up to but not including the closing bracket. 00088 if (ch != ']') { 00089 string date; 00090 while (!in.fail() && !in.eof() && ch != ']') { 00091 date += ch; 00092 ch = in.get(); 00093 } 00094 00095 set_date(HTTPDate(date)); 00096 if (!get_date().is_valid()) { 00097 return false; 00098 } 00099 } 00100 00101 return true; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: DocumentSpec::output 00106 // Access: Published 00107 // Description: 00108 //////////////////////////////////////////////////////////////////// 00109 void DocumentSpec:: 00110 output(ostream &out) const { 00111 out << "[ " << get_url(); 00112 if (has_tag()) { 00113 out << " (" << get_tag() << ")"; 00114 } 00115 if (has_date()) { 00116 out << " " << get_date(); 00117 } 00118 out << " ]"; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: DocumentSpec::write 00123 // Access: Published 00124 // Description: 00125 //////////////////////////////////////////////////////////////////// 00126 void DocumentSpec:: 00127 write(ostream &out, int indent_level) const { 00128 indent(out, indent_level) 00129 << "[ " << get_url(); 00130 if (has_tag()) { 00131 out << "\n"; 00132 indent(out, indent_level + 2) 00133 << "(" << get_tag() << ")"; 00134 } 00135 if (has_date()) { 00136 out << "\n"; 00137 indent(out, indent_level + 2) 00138 << get_date(); 00139 } 00140 out << " ]\n"; 00141 }