/[debian]/mimetic/branches/upstream/current/mimetic/os/file_iterator.h
ViewVC logotype

Contents of /mimetic/branches/upstream/current/mimetic/os/file_iterator.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Sat Feb 25 16:49:20 2006 UTC (15 years, 5 months ago) by gregoa
File MIME type: text/plain
File size: 2598 byte(s)
[svn-inject] Installing original source of mimetic
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: file_iterator.h,v 1.9 2005/02/23 10:26:15 tat Exp $
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16 #ifndef _MIMETIC_OS_FILE_ITERATOR_H_
17 #define _MIMETIC_OS_FILE_ITERATOR_H_
18 #include <string>
19 #include <iterator>
20
21 namespace mimetic
22 {
23 struct StdFile;
24
25 struct ifile_iterator: public std::iterator<std::input_iterator_tag, char>
26 {
27 ifile_iterator();
28 ifile_iterator(StdFile* f);
29 ifile_iterator(const ifile_iterator&);
30 ifile_iterator& operator=(const ifile_iterator&);
31 ~ifile_iterator();
32 inline ifile_iterator& operator++();
33 inline ifile_iterator operator++(int);
34 inline reference operator*();
35 inline bool operator!=(const ifile_iterator& right) const;
36 inline bool operator==(const ifile_iterator& right) const;
37 private:
38 void cp(const ifile_iterator&);
39 void setBufsz();
40 enum { defBufsz = 4096 }; // default buffer size(4 missing getpagesize)
41 void underflow();
42 bool m_eof;
43 value_type* m_buf;
44 value_type* m_ptr;
45 int m_count;
46 StdFile* m_pFile;
47 unsigned int m_read; //bytes read so far
48 unsigned int m_bufsz;
49 };
50
51 inline
52 ifile_iterator ifile_iterator::operator++(int) // postfix
53 {
54 ifile_iterator cp = *this;
55 operator++();
56 return cp;
57 }
58
59
60 inline
61 ifile_iterator& ifile_iterator::operator++() // prefix
62 {
63 if(--m_count > 0)
64 ++m_ptr;
65 else
66 underflow();
67 return *this;
68 }
69
70
71 inline
72 ifile_iterator::reference ifile_iterator::operator*()
73 {
74 return *m_ptr;
75 }
76
77 inline
78 bool ifile_iterator::operator!=(const ifile_iterator& right) const
79 {
80 // always different except when both are EOF
81 return !operator==(right);
82 }
83
84
85 inline
86 bool ifile_iterator::operator==(const ifile_iterator& right) const
87 {
88 return m_eof == right.m_eof == 1;
89 }
90
91 }
92
93 #endif

  ViewVC Help
Powered by ViewVC 1.1.26