00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MIMETIC_OS_FILE_ITERATOR_H_
00017 #define _MIMETIC_OS_FILE_ITERATOR_H_
00018 #include <string>
00019 #include <iterator>
00020
00021 namespace mimetic
00022 {
00023 struct StdFile;
00024
00025 struct ifile_iterator: public std::iterator<std::input_iterator_tag, char>
00026 {
00027 ifile_iterator();
00028 ifile_iterator(StdFile* f);
00029 ifile_iterator(const ifile_iterator&);
00030 ifile_iterator& operator=(const ifile_iterator&);
00031 ~ifile_iterator();
00032 inline ifile_iterator& operator++();
00033 inline ifile_iterator operator++(int);
00034 inline reference operator*();
00035 inline bool operator!=(const ifile_iterator& right) const;
00036 inline bool operator==(const ifile_iterator& right) const;
00037 private:
00038 void cp(const ifile_iterator&);
00039 void setBufsz();
00040 enum { defBufsz = 4096 };
00041 void underflow();
00042 bool m_eof;
00043 value_type* m_buf;
00044 value_type* m_ptr;
00045 int m_count;
00046 StdFile* m_pFile;
00047 unsigned int m_read;
00048 unsigned int m_bufsz;
00049 };
00050
00051 inline
00052 ifile_iterator ifile_iterator::operator++(int)
00053 {
00054 ifile_iterator cp = *this;
00055 operator++();
00056 return cp;
00057 }
00058
00059
00060 inline
00061 ifile_iterator& ifile_iterator::operator++()
00062 {
00063 if(--m_count > 0)
00064 ++m_ptr;
00065 else
00066 underflow();
00067 return *this;
00068 }
00069
00070
00071 inline
00072 ifile_iterator::reference ifile_iterator::operator*()
00073 {
00074 return *m_ptr;
00075 }
00076
00077 inline
00078 bool ifile_iterator::operator!=(const ifile_iterator& right) const
00079 {
00080
00081 return !operator==(right);
00082 }
00083
00084
00085 inline
00086 bool ifile_iterator::operator==(const ifile_iterator& right) const
00087 {
00088 return m_eof == right.m_eof == 1;
00089 }
00090
00091 }
00092
00093 #endif