include/id3/readers.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // $Id: readers.h,v 1.12 2002/06/29 17:43:42 t1mpy 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 "id3/id3lib_streams.h"
00032 #include "id3/reader.h"
00033 
00034 class ID3_CPP_EXPORT ID3_IStreamReader : public ID3_Reader
00035 {
00036   istream& _stream;
00037  protected:
00038   istream& getReader() const { return _stream; }
00039  public:
00040   ID3_IStreamReader(istream& reader) : _stream(reader) { ; }
00041   virtual ~ID3_IStreamReader() { ; }
00042   virtual void close() { ; }
00043   
00044   virtual int_type peekChar() { return _stream.peek(); }
00045     
00049   virtual size_type readChars(char buf[], size_type len)
00050   {
00051     return this->readChars(reinterpret_cast<uchar *>(buf), len);
00052   }
00053   virtual size_type readChars(char_type buf[], size_type len)
00054   {
00055     _stream.read((char *)buf, len);
00056     return _stream.gcount();
00057   }
00058 
00059   virtual pos_type getBeg() { return 0; }
00060   virtual pos_type getCur() { return _stream.tellg(); }
00061   virtual pos_type getEnd() 
00062   { 
00063     pos_type cur = this->getCur();
00064     _stream.seekg(0, ios::end);
00065     pos_type end = this->getCur();
00066     this->setCur(cur);
00067     return end;
00068   }
00069     
00072   virtual pos_type setCur(pos_type pos) { _stream.seekg(pos); return pos; }
00073 };
00074   
00075 class ID3_CPP_EXPORT ID3_IFStreamReader : public ID3_IStreamReader
00076 {
00077   ifstream& _file;
00078  public:
00079   ID3_IFStreamReader(ifstream& reader)
00080     : ID3_IStreamReader(reader), _file(reader) { ; }
00081     
00082   virtual void close() 
00083   { 
00084     _file.close();
00085   }
00086 };
00087   
00088 class ID3_CPP_EXPORT ID3_MemoryReader : public ID3_Reader
00089 {
00090   const char_type* _beg;
00091   const char_type* _cur;
00092   const char_type* _end;
00093  protected:
00094   void setBuffer(const char_type* buf, size_type size)
00095   {
00096     _beg = buf;
00097     _cur = buf;
00098     _end = buf + size;
00099   };
00100  public:
00101   ID3_MemoryReader()
00102   {
00103     this->setBuffer(NULL, 0);
00104   }
00105   ID3_MemoryReader(const char_type* buf, size_type size)
00106   {
00107     this->setBuffer(buf, size);
00108   };
00109   ID3_MemoryReader(const char* buf, size_type size)
00110   {
00111     this->setBuffer(reinterpret_cast<const char_type*>(buf), size);
00112   };
00113   virtual ~ID3_MemoryReader() { ; }
00114   virtual void close() { ; }
00115     
00116   virtual int_type peekChar() 
00117   { 
00118     if (!this->atEnd())
00119     {
00120       return *_cur; 
00121     }
00122     return END_OF_READER;
00123   }
00124     
00128   virtual size_type readChars(char buf[], size_type len)
00129   {
00130     return this->readChars(reinterpret_cast<char_type *>(buf), len);
00131   }
00132   virtual size_type readChars(char_type buf[], size_type len);
00133     
00134   virtual pos_type getCur() 
00135   { 
00136     return _cur - _beg; 
00137   }
00138     
00139   virtual pos_type getBeg()
00140   {
00141     return _beg - _beg;
00142   }
00143     
00144   virtual pos_type getEnd()
00145   {
00146     return _end - _beg;
00147   }
00148     
00151   virtual pos_type setCur(pos_type pos)
00152   {
00153     pos_type end = this->getEnd();
00154     size_type size = (pos < end) ? pos : end;
00155     _cur = _beg + size;
00156     return this->getCur();
00157   }
00158 };
00159 
00160 #endif /* _ID3LIB_READERS_H_ */
00161 

Generated on Mon Aug 20 17:48:46 2007 for id3lib by  doxygen 1.5.2