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

include/id3/readers.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: readers.h,v 1.10 2001/08/26 23:33:23 dmazzoni Exp $
00003 
00004 // id3lib: a software library for creating and manipulating id3v1/v2 tags
00005 // Copyright 1999, 2000  Scott Thomas Haug
00006 
00007 // This library is free software; you can redistribute it and/or modify it
00008 // under the terms of the GNU Library General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or (at your
00010 // option) any later version.
00011 //
00012 // This library is distributed in the hope that it will be useful, but WITHOUT
00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00015 // License for more details.
00016 //
00017 // You should have received a copy of the GNU Library General Public License
00018 // along with this library; if not, write to the Free Software Foundation,
00019 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 
00021 // The id3lib authors encourage improvements and optimisations to be sent to
00022 // the id3lib coordinator.  Please see the README file for details on where to
00023 // send such submissions.  See the AUTHORS file for a list of people who have
00024 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00025 // id3lib.  These files are distributed with id3lib at
00026 // http://download.sourceforge.net/id3lib/
00027 
00028 #ifndef _ID3LIB_READERS_H_
00029 #define _ID3LIB_READERS_H_
00030 
00031 #include <fstream.h>
00032 #include <iostream.h>
00033 #include <id3/reader.h>
00034 
00035 class ID3_CPP_EXPORT ID3_IStreamReader : public ID3_Reader
00036 {
00037   istream& _stream;
00038  protected:
00039   istream& getReader() const { return _stream; }
00040  public:
00041   ID3_IStreamReader(istream& reader) : _stream(reader) { ; }
00042   virtual ~ID3_IStreamReader() { ; }
00043   virtual void close() { ; }
00044   
00045   virtual int_type peekChar() { return _stream.peek(); }
00046     
00050   virtual size_type readChars(char buf[], size_type len)
00051   {
00052     return this->readChars(reinterpret_cast<uchar *>(buf), len);
00053   }
00054   virtual size_type readChars(char_type buf[], size_type len)
00055   {
00056     _stream.read((char *)buf, len);
00057     return _stream.gcount();
00058   }
00059 
00060   virtual pos_type getBeg() { return 0; }
00061   virtual pos_type getCur() { return _stream.tellg(); }
00062   virtual pos_type getEnd() 
00063   { 
00064     pos_type cur = this->getCur();
00065     _stream.seekg(0, ios::end);
00066     pos_type end = this->getCur();
00067     this->setCur(cur);
00068     return end;
00069   }
00070     
00073   virtual pos_type setCur(pos_type pos) { _stream.seekg(pos); return pos; }
00074 };
00075   
00076 class ID3_CPP_EXPORT ID3_IFStreamReader : public ID3_IStreamReader
00077 {
00078   ifstream& _file;
00079  public:
00080   ID3_IFStreamReader(ifstream& reader)
00081     : ID3_IStreamReader(reader), _file(reader) { ; }
00082     
00083   virtual void close() 
00084   { 
00085     _file.close();
00086   }
00087 };
00088   
00089 class ID3_CPP_EXPORT ID3_MemoryReader : public ID3_Reader
00090 {
00091   const char_type* _beg;
00092   const char_type* _cur;
00093   const char_type* _end;
00094  protected:
00095   void setBuffer(const char_type* buf, size_type size)
00096   {
00097     _beg = buf;
00098     _cur = buf;
00099     _end = buf + size;
00100   };
00101  public:
00102   ID3_MemoryReader()
00103   {
00104     this->setBuffer(NULL, 0);
00105   }
00106   ID3_MemoryReader(const char_type* buf, size_type size)
00107   {
00108     this->setBuffer(buf, size);
00109   };
00110   ID3_MemoryReader(const char* buf, size_type size)
00111   {
00112     this->setBuffer(reinterpret_cast<const char_type*>(buf), size);
00113   };
00114   virtual ~ID3_MemoryReader() { ; }
00115   virtual void close() { ; }
00116     
00117   virtual int_type peekChar() 
00118   { 
00119     if (!this->atEnd())
00120     {
00121       return *_cur; 
00122     }
00123     return END_OF_READER;
00124   }
00125     
00129   virtual size_type readChars(char buf[], size_type len)
00130   {
00131     return this->readChars(reinterpret_cast<char_type *>(buf), len);
00132   }
00133   virtual size_type readChars(char_type buf[], size_type len);
00134     
00135   virtual pos_type getCur() 
00136   { 
00137     return _cur - _beg; 
00138   }
00139     
00140   virtual pos_type getBeg()
00141   {
00142     return _beg - _beg;
00143   }
00144     
00145   virtual pos_type getEnd()
00146   {
00147     return _end - _beg;
00148   }
00149     
00152   virtual pos_type setCur(pos_type pos)
00153   {
00154     pos_type end = this->getEnd();
00155     size_type size = (pos < end) ? pos : end;
00156     _cur = _beg + size;
00157     return this->getCur();
00158   }
00159 };
00160 
00161 #endif /* _ID3LIB_READERS_H_ */

Generated at Sat Sep 8 15:51:08 2001 for id3lib by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001