//***************************************************************************
// This source code is copyrighted 2002 by Google Inc.  All rights
// reserved.  You are given a limited license to use this source code for
// purposes of participating in the Google programming contest.  If you
// choose to use or distribute the source code for any other purpose, you
// must either (1) first obtain written approval from Google, or (2)
// prominently display the foregoing copyright notice and the following
// warranty and liability disclaimer on each copy used or distributed.
// 
// The source code and repository (the "Software") is provided "AS IS",
// with no warranty, express or implied, including but not limited to the
// implied warranties of merchantability and fitness for a particular
// use.  In no event shall Google Inc. be liable for any damages, direct
// or indirect, even if advised of the possibility of such damages.
//***************************************************************************


#ifndef _DOCUMENT_H_
#define _DOCUMENT_H_

#include <netinet/in.h>       // for struct in_addr
#include "goo-content-type.h"
#include "goo-lang_enc.h"
#include "goo-basictypes.h"
#include <string>

// The Document class just consists of setters and accessors.
// Each setter takes some other sort of object that actually sets.
// We don't make copies of anything, so keep that in mind when
// passing in strings, etc.

class Document {
 public:
  Document() { Clear(); }

  void set_url(const char* url) { url_ = url; }
  const char* url() const { return url_; }

  void set_url_after_redirects(const char* url) {
    url_after_redirects_ = url;
  }
  const char* url_after_redirects() const { return url_after_redirects_; }

  void set_ip_addr(struct in_addr ip_addr) {
    memcpy(&ip_addr_, &ip_addr, sizeof(ip_addr_));
  }
  const struct in_addr& ip_addr() const { return ip_addr_; }

  void set_content_type(ContentType ct) { content_type_ = ct; }
  ContentType content_type() const { return content_type_; }

  void set_content_len(uint32 len) { content_len_ = len; }
  uint32 content_len() const { return content_len_; }

  void set_language(Language lang) { language_ = lang; }
  Language language() const { return language_; }

  void set_encoding(Encoding enc) { encoding_ = enc; }
  Encoding encoding() const { return encoding_; }
  
  // Gets everything ready for the next document
  void Clear() {
    url_ = NULL;
    url_after_redirects_ = NULL;
    content_type_ = CONTENT_GOOGLE_ERROR;
    language_ = kDefaultLanguage;
    encoding_ = kDefaultEncoding; 
    memset(&ip_addr_, 0, sizeof(ip_addr_));
  }

 private:
  const char* url_;
  const char* url_after_redirects_;
  ContentType content_type_;
  Language language_;
  Encoding encoding_;
  struct in_addr ip_addr_;
  uint32 content_len_;
};

#endif
