/[debian]/mimetic/trunk/mimetic/os/file_iterator.h
ViewVC logotype

Annotation of /mimetic/trunk/mimetic/os/file_iterator.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1731 - (hide annotations)
Fri May 15 15:35:42 2009 UTC (12 years, 2 months ago) by gregoa
File MIME type: text/plain
File size: 2629 byte(s)
New upstream release.
1 gregoa 128 /***************************************************************************
2 gregoa 1444 copyright : (C) 2002-2008 by Stefano Barbato
3 gregoa 128 email : stefano@codesink.org
4    
5 gregoa 1731 $Id: file_iterator.h,v 1.11 2008-10-27 18:30:42 tat Exp $
6 gregoa 128 ***************************************************************************/
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 gregoa 1731 // are equal if both are EOF
89     return (m_eof && right.m_eof);
90 gregoa 128 }
91    
92     }
93    
94     #endif

  ViewVC Help
Powered by ViewVC 1.1.26