Panda3D

Loading...
Searching...
No Matches
documentSpec.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file documentSpec.cxx
10 * @author drose
11 * @date 2003-01-28
12 */
13
14#include "documentSpec.h"
15#include "indent.h"
16
17
18/**
19 *
20 */
21 int DocumentSpec::
22compare_to(const DocumentSpec &other) const {
23 if (_flags != other._flags) {
24 return (_flags - other._flags);
25 }
26 int c = _url.compare_to(other._url);
27 if (c != 0) {
28 return c;
29 }
30 if (has_tag()) {
31 c = _tag.compare_to(other._tag);
32 if (c != 0) {
33 return c;
34 }
35 }
36 if (has_date()) {
37 c = _date.compare_to(other._date);
38 if (c != 0) {
39 return c;
40 }
41 }
42
43 // We don't consider _request_mode or _cache_control significant in the
44 // comparison.
45
46 return 0;
47}
48
49/**
50 * Can be used to read in the DocumentSpec from a stream generated either by
51 * output() or write(). Returns true on success, false on failure.
52 */
53 bool DocumentSpec::
54 input(std::istream &in) {
55 // First, clear the spec.
56 (*this) = DocumentSpec();
57
58 char ch;
59 in >> ch;
60 if (ch != '[') {
61 return false;
62 }
63 in >> _url;
64 in >> ch;
65 if (ch == '(') {
66 // Scan the tag, up to but not including the closing paren.
67 std::string tag;
68 in >> ch;
69 while (!in.fail() && ch != ')') {
70 tag += ch;
71 // We want to include embedded whitespace, so we use get().
72 ch = in.get();
73 }
74 set_tag(HTTPEntityTag(tag));
75
76 // Now ch is the close paren following the tag; skip to the next
77 // character.
78 in >> ch;
79 }
80
81 // Scan the date, up to but not including the closing bracket.
82 if (ch != ']') {
83 std::string date;
84 while (!in.fail() && ch != ']') {
85 date += ch;
86 ch = in.get();
87 }
88
89 set_date(HTTPDate(date));
90 if (!get_date().is_valid()) {
91 return false;
92 }
93 }
94
95 return true;
96}
97
98/**
99 *
100 */
101 void DocumentSpec::
102output(std::ostream &out) const {
103 out << "[ " << get_url();
104 if (has_tag()) {
105 out << " (" << get_tag() << ")";
106 }
107 if (has_date()) {
108 out << " " << get_date();
109 }
110 out << " ]";
111}
112
113/**
114 *
115 */
116 void DocumentSpec::
117write(std::ostream &out, int indent_level) const {
118 indent(out, indent_level)
119 << "[ " << get_url();
120 if (has_tag()) {
121 out << "\n";
122 indent(out, indent_level + 2)
123 << "(" << get_tag() << ")";
124 }
125 if (has_date()) {
126 out << "\n";
127 indent(out, indent_level + 2)
128 << get_date();
129 }
130 out << " ]\n";
131}
DocumentSpec
A descriptor that refers to a particular version of a document.
Definition documentSpec.h:30
DocumentSpec::set_date
set_date
Changes the last-modified date associated with the DocumentSpec.
Definition documentSpec.h:82
DocumentSpec::set_tag
set_tag
Changes the identity tag associated with the DocumentSpec.
Definition documentSpec.h:81
DocumentSpec::get_url
get_url
Retrieves the URL of the DocumentSpec.
Definition documentSpec.h:80
DocumentSpec::get_tag
get_tag
Returns the identity tag associated with the DocumentSpec, if there is one.
Definition documentSpec.h:81
DocumentSpec::get_date
get_date
Returns the last-modified date associated with the DocumentSpec, if there is one.
Definition documentSpec.h:82
DocumentSpec::has_date
has_date
Returns true if a last-modified date is associated with the DocumentSpec.
Definition documentSpec.h:82
DocumentSpec::input
bool input(std::istream &in)
Can be used to read in the DocumentSpec from a stream generated either by output() or write().
Definition documentSpec.cxx:54
DocumentSpec::has_tag
has_tag
Returns true if an identity tag is associated with the DocumentSpec.
Definition documentSpec.h:81
HTTPDate
A container for an HTTP-legal time/date indication.
Definition httpDate.h:27
HTTPEntityTag
A container for an "entity tag" from an HTTP server.
Definition httpEntityTag.h:24
documentSpec.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.