no message
[xbmc:xbmc-antiquated.git] / xbmc / XIStreamReader.h
1 #pragma once
2
3 class ID3_XIStreamReader : public ID3_Reader  
4 {
5  
6 public:
7                 ID3_XIStreamReader(CFile& reader) : _stream( reader ) { ; }
8                 virtual ~ID3_XIStreamReader() { ; }
9                 
10                 /** Close the reader.  Any further actions on the reader should fail.**/
11         virtual void close() 
12                 { 
13                         ; 
14                 }
15   
16                 /**
17                 ** Return the next character to be read without advancing the internal 
18                 ** position.  Returns END_OF_READER if there isn't a character to read.
19                 **/
20         virtual int_type peekChar() 
21                 {
22                         if (this->atEnd())
23                         { 
24                                 return END_OF_READER; 
25                         }
26                         int_type buf = 0;
27                         offset_t i = _stream.GetPosition();
28
29                         buf = (int_type)this->readChar();
30                         _stream.Seek( i );
31                         return buf ; 
32                 }
33     
34                 /** Read up to \c len chars into buf and advance the internal position
35                 ** accordingly.  Returns the number of characters read into buf.
36                 **/
37         
38                 virtual size_type readChars(char_type buf[], size_type len)
39                 {
40                         if (this->atEnd())
41                         { 
42                                 return END_OF_READER; 
43                         }
44                         offset_t pt = _stream.GetPosition();
45                         size_type st = (_stream.Read((void*) buf, (int) len));
46                         _stream.Seek( pt + st );
47                         return st;
48                 }
49
50                 /** Return the beginning position in the reader */
51                 virtual pos_type getBeg() { return 0; }
52                 
53                 /** Return the current position in the reader */
54                 virtual pos_type getCur() { return pos_type(_stream.GetPosition()); }
55                 
56                 /** Return the ending position in the reader */
57                 virtual pos_type getEnd() 
58                 {
59                         return (ID3_Reader::pos_type)_stream.GetLength();
60                 }
61     
62                 /** Set the value of the current position for reading.**/
63                 virtual pos_type setCur(pos_type pos) 
64                 { 
65                         _stream.Seek(pos); 
66                         return pos_type(pos); 
67                 }
68         
69                 /** Skip up to \c len chars in the stream and advance the internal position
70    ** accordingly.  Returns the number of characters actually skipped (may be 
71    ** less than requested).
72    
73                 virtual size_type skipChars(size_type len)
74                 {
75                         const size_type SIZE = 1024;
76                         char_type* bytes;
77                         size_type remaining = len;
78                         if ( getCur() + len > getEnd() ) 
79                         {
80                                 bytes = new char_type[getEnd() - getCur()];
81                                 this->readChars(bytes, getEnd() - getCur() );
82                                 delete bytes;
83                                 return (getCur() + len) - getEnd();
84                         }
85                         else 
86                         {
87                                 bytes = new char_type[len];
88                                 this->readChars(bytes, len );
89                                 delete bytes;
90                                 return 0;
91                         }
92                         return len - remaining;
93                 }**/
94
95  protected:
96                 CFile& _stream;
97                 CFile& getReader() const { return _stream; }
98
99 };