code::Reader Class Reference
[Reader]

Inheritance diagram for code::Reader:

code::InMemoryReader code::SchemeReader code::LineReader code::ZlibReader code::ZReader code::LBReader code::LocalReader code::ORPGReader code::RshReader code::RSSReader code::WebReader code::WebReaderCurlImpl List of all members.

Detailed Description

Simplifies file reading down to a few lines of code, regardless of whether or not the file is compressed and whether it's read locally or over ftp, http, rssd, etc.

Most of the time users can get by with these code snippets:

Reading a file into a std::string:

 #include <wdssii/code_Reader.h>

 URL url = "http://www.wdsssii.org/index.html";
 std::string content;
 Reader :: read (url, content);
 std::cerr << "Read " << content.size() << " bytes from " << url << std::endl;

Reading a file into a code::Buffer:

 #include <wdssii/code_Reader.h>
 #include <wdssii/code_URL.h>

 URL url = "/tmp/somefile.txt.bz2";
 Buffer buf;
 Reader :: read (url, buf);
 std::cerr << "Read " << buf.size() << " bytes from " << url << std::endl;

Reading a file one line at a time:

 #include <wdssii/code_LineReader.h>
 #include <wdssii/code_URL.h>

 URL url = "/tmp/readme.gz";
 std::string line;
 SmartPtr<LineReader> lineReader = LineReader :: getLineReader (url);
 while (lineReader->readLine (line))
 {
   do_something_with_line (line);
 }

Author:
Charles Kerr
Version:
Id
code_Reader.h,v 1.26 2009/06/02 20:17:40 lakshman Exp


Public Member Functions

virtual int read (Buffer &buf, long offset=0, size_t max_size=0)=0
virtual ~Reader ()

Static Public Member Functions

static int read (const URL &url, Buffer &buffer, long offset=0, size_t max_len=0)
 Convenience function to read `url' into `buf'.
static int read (const URL &url, std::string &s, long offset=0, size_t max_len=0)
 Identical to read(const URL&,Buffer&,long,size_t) except it takes a string instead of a buffer.
static int readRaw (const URL &url, Buffer &b, long offset=0, size_t max_len=0)
 Identical to read() except except it doesn't uncompress files.
static SmartPtr< XML::DocumentreadXMLDocument (const URL &url)
 Returns an XML::Document created by passing the contents of `url' to XML::Parser::parse().
static SmartPtr< ReadergetReader (const URL &url)
 Returns a handle to a reader for the given URL.
static void introduceWDSSIIReaders ()


Constructor & Destructor Documentation

virtual code::Reader::~Reader (  )  [inline, virtual]


Member Function Documentation

static SmartPtr<Reader> code::Reader::getReader ( const URL url  )  [static]

Returns a handle to a reader for the given URL.

This is useful when you want to make iterative calls to read() or LineReader::readLine().

static void code::Reader::introduceWDSSIIReaders (  )  [static]

virtual int code::Reader::read ( Buffer buf,
long  offset = 0,
size_t  max_size = 0 
) [pure virtual]

See also:
static int read (URL, Buffer, offset, long, size_t);

Implemented in code::RshReader, code::LBReader, code::ORPGReader, code::RSSReader, code::InMemoryReader, code::LocalReader, code::WebReader, and code::WebReaderCurlImpl.

static int code::Reader::read ( const URL url,
std::string &  s,
long  offset = 0,
size_t  max_len = 0 
) [static]

Identical to read(const URL&,Buffer&,long,size_t) except it takes a string instead of a buffer.

static int code::Reader::read ( const URL url,
Buffer buffer,
long  offset = 0,
size_t  max_len = 0 
) [static]

Convenience function to read `url' into `buf'.

Handles remote, local, compressed, and uncompressed files transparently.

Parameters:
url the data source.
buffer where source's contents will be stored.
offset number of bytes to skip before read() begins storing.
max_len if nonzero, maximum number of bytes to store in buf.
Returns:
the number of bytes read, or a negative number on error.

static int code::Reader::readRaw ( const URL url,
Buffer b,
long  offset = 0,
size_t  max_len = 0 
) [static]

Identical to read() except except it doesn't uncompress files.

This is useful when mirroring compressed files to avoid decompress / recompress steps.

static SmartPtr<XML::Document> code::Reader::readXMLDocument ( const URL url  )  [static]

Returns an XML::Document created by passing the contents of `url' to XML::Parser::parse().


Generated on Fri May 4 13:40:13 2012 for WDSS-IIw2 by  doxygen 1.4.7