~dominik-burgdoerfer/webplodder/0.4

« back to all changes in this revision

Viewing changes to src/wesl/utils/citerator.hpp

  • Committer: Dominik Burgdörfer
  • Date: 2010-07-07 14:35:20 UTC
  • Revision ID: dominik@domachine-20100707143520-wpywl29fsg9quz54
restructured sources

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// =======================================================================
2
 
// 
3
 
//       Filename:  citerator.hpp
4
 
// 
5
 
//    Description:  
6
 
// 
7
 
//        Version:  1.0
8
 
//        Created:  25.03.2010 21:46:26
9
 
//       Revision:  none
10
 
//       Compiler:  g++
11
 
// 
12
 
//         Author:  Dominik 'domachine' Burgdörfer (-), dominik.burgdoerfer@googlemail.com
13
 
//        Company:  -
14
 
// 
15
 
// =======================================================================
16
 
 
17
 
 
18
 
#ifndef  CITERATOR_INC
19
 
#define  CITERATOR_INC
20
 
#include <stdexcept>
21
 
#include <vector>
22
 
#include <iostream>
23
 
//#ifdef DEBUG
24
 
//    #define DBG(msg) std::cerr << __FILE__ << ":"
25
 
//        << __LINE__ << ": "
26
 
//        << msg << std::endl;
27
 
//#else
28
 
//    #define DBG
29
 
//#endif
30
 
 
31
 
namespace wesl {
32
 
    namespace utils {
33
 
        /**
34
 
         * @brief This class provides an interface
35
 
         * to read files and having access to the previous
36
 
         * read and the following character.
37
 
         */
38
 
        class CIterator {
39
 
            public:
40
 
                /**
41
 
                 * @brief Constructs default CIterator.
42
 
                 */
43
 
                CIterator();
44
 
 
45
 
                /**
46
 
                 * @brief Constructs a CIterator that operates on <i>stream</i>
47
 
                 */
48
 
                CIterator(std::istream& stream);
49
 
 
50
 
                /**
51
 
                 * @brief Move the file pointer forward.
52
 
                 */
53
 
                CIterator& moveForward();
54
 
 
55
 
                /**
56
 
                 * @brief Returns the current char in the
57
 
                 * middle of the buffer.
58
 
                 */
59
 
                char currentChar();
60
 
 
61
 
                /**
62
 
                 * @brief Returns the char which will be
63
 
                 * the next under the file pointer.
64
 
                 */
65
 
                char nextChar();
66
 
 
67
 
                /**
68
 
                 * @brief Returns the char before the
69
 
                 * current char.
70
 
                 */
71
 
                char lastChar();
72
 
 
73
 
                /**
74
 
                 * @brief Delegates the good() method
75
 
                 * of the underlaying std::istream.
76
 
                 */
77
 
                bool good() const;
78
 
 
79
 
                /**
80
 
                 * @brief Delegates the eof() method
81
 
                 * of the underlaying std::istream.
82
 
                 */
83
 
                bool eof() const;
84
 
 
85
 
                /**
86
 
                 * @brief Returns the current position
87
 
                 * of the file pointer.
88
 
                 */
89
 
                long position() const;
90
 
 
91
 
                /**
92
 
                 * @brief Rewinds the underlaying std::istream.
93
 
                 */
94
 
                void rewind();
95
 
 
96
 
                /**
97
 
                 * @brief Sets the underlaying stream.
98
 
                 */
99
 
                void setStream(std::istream& stream);
100
 
 
101
 
                /**
102
 
                 * @brief Returns the underlaying stream
103
 
                 */
104
 
                std::istream& stream();
105
 
 
106
 
            private:
107
 
                void readNextChar();
108
 
                void updateCache(char ch);
109
 
                void resetCache();
110
 
 
111
 
                std::istream* mStream;
112
 
                long mPosition;
113
 
                char mCache[3];
114
 
                long mCachePos[3];
115
 
        };
116
 
    }
117
 
}
118
 
#endif   // ----- #ifndef CITERATOR_INC  -----