Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/downloader/documentSpec.cxx

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

Generated on Fri May 2 00:36:44 2003 for Panda by doxygen1.3