00001 //*************************************************************************** 00002 // This source code is copyrighted 2002 by Google Inc. All rights 00003 // reserved. You are given a limited license to use this source code for 00004 // purposes of participating in the Google programming contest. If you 00005 // choose to use or distribute the source code for any other purpose, you 00006 // must either (1) first obtain written approval from Google, or (2) 00007 // prominently display the foregoing copyright notice and the following 00008 // warranty and liability disclaimer on each copy used or distributed. 00009 // 00010 // The source code and repository (the "Software") is provided "AS IS", 00011 // with no warranty, express or implied, including but not limited to the 00012 // implied warranties of merchantability and fitness for a particular 00013 // use. In no event shall Google Inc. be liable for any damages, direct 00014 // or indirect, even if advised of the possibility of such damages. 00015 //*************************************************************************** 00016 00017 00018 #ifndef _DOCUMENT_H_ 00019 #define _DOCUMENT_H_ 00020 00021 #include <netinet/in.h> // for struct in_addr 00022 #include "content-type.h" 00023 #include "lang_enc.h" 00024 #include "basictypes.h" 00025 #include <string> 00026 00027 // The Document class just consists of setters and accessors. 00028 // Each setter takes some other sort of object that actually sets. 00029 // We don't make copies of anything, so keep that in mind when 00030 // passing in strings, etc. 00031 00032 class Document { 00033 public: 00034 Document() { Clear(); } 00035 00036 void set_url(const char* url) { url_ = url; } 00037 const char* url() const { return url_; } 00038 // void set_date(const char* date) {date_ = date; } 00039 // const char* date() const { return date_; } 00040 00041 void set_url_after_redirects(const char* url) { 00042 url_after_redirects_ = url; 00043 } 00044 const char* url_after_redirects() const { return url_after_redirects_; } 00045 00046 void set_ip_addr(struct in_addr ip_addr) { 00047 memcpy(&ip_addr_, &ip_addr, sizeof(ip_addr_)); 00048 } 00049 const struct in_addr& ip_addr() const { return ip_addr_; } 00050 00051 void set_content_type(ContentType ct) { content_type_ = ct; } 00052 ContentType content_type() const { return content_type_; } 00053 00054 void set_content_len(uint32 len) { content_len_ = len; } 00055 uint32 content_len() const { return content_len_; } 00056 00057 void set_language(Language lang) { language_ = lang; } 00058 Language language() const { return language_; } 00059 00060 void set_encoding(Encoding enc) { encoding_ = enc; } 00061 Encoding encoding() const { return encoding_; } 00062 00063 // Gets everything ready for the next document 00064 void Clear() { 00065 url_ = NULL; 00066 url_after_redirects_ = NULL; 00067 content_type_ = CONTENT_GOOGLE_ERROR; 00068 language_ = kDefaultLanguage; 00069 encoding_ = kDefaultEncoding; 00070 memset(&ip_addr_, 0, sizeof(ip_addr_)); 00071 } 00072 00073 private: 00074 const char* url_; 00075 // const char* date_; 00076 const char* url_after_redirects_; 00077 ContentType content_type_; 00078 Language language_; 00079 Encoding encoding_; 00080 struct in_addr ip_addr_; 00081 uint32 content_len_; 00082 }; 00083 00084 #endif