@@ -44,35 +44,43 @@ File::File(const std::string& fn) {
4444 stream.seekg (0 ,std::ios_base::end);
4545 size = (unsigned int ) stream.tellg ();
4646 stream.seekg (0 ,std::ios_base::beg);
47+ #ifdef BUF_SIZE
48+ offset = 0 ;
4749 paging = size > BUF_SIZE;
4850 buffer = new char [size < BUF_SIZE ? size : BUF_SIZE];
51+ #else
52+ buffer = new char [size];
53+ #endif
4954 ptr = 0 ;
50- len = 0 ;
51- offset = 0 ;
55+ len = 0 ;
5256 ReadBuffer (false );
5357}
5458
5559File::File (std::istream& f, int l) {
5660 eof = false ;
5761 size = l;
62+ #ifdef BUF_SIZE
5863 paging = false ;
64+ offset = 0 ;
65+ #endif
5966 buffer = new char [size];
6067 f.read (buffer,size);
6168 valid = f.gcount () == size;
6269 ptr = 0 ;
63- len = l;
64- offset = 0 ;
70+ len = l;
6571}
6672
6773File::File (void * data, int l) {
6874 eof = false ;
6975 size = l;
76+ #ifdef BUF_SIZE
7077 paging = false ;
78+ offset = 0 ;
79+ #endif
7180 buffer = (char *) data;
7281 valid = true ;
7382 ptr = 0 ;
74- len = l;
75- offset = 0 ;
83+ len = l;
7684}
7785
7886void File::Close () {
@@ -84,13 +92,19 @@ void File::Close() {
8492// Reads a chunk of BUF_SIZE in memory and increments cursor if requested
8593//
8694void File::ReadBuffer (bool inc) {
95+ #ifdef BUF_SIZE
8796 if ( inc ) {
8897 offset += len;
8998 stream.seekg (offset,std::ios_base::beg);
9099 }
100+ #endif
91101 eof = stream.eof ();
92102 if ( eof ) return ;
103+ #ifdef BUF_SIZE
93104 stream.read (buffer,size < BUF_SIZE ? size : BUF_SIZE);
105+ #else
106+ stream.read (buffer,size);
107+ #endif
94108 len = (unsigned int ) stream.gcount ();
95109 eof = len == 0 ;
96110 ptr = 0 ;
@@ -100,10 +114,13 @@ void File::ReadBuffer(bool inc) {
100114// Seeks an arbitrary position in the file
101115//
102116void File::Seek (unsigned int o) {
117+ #ifdef BUF_SIZE
103118 if ( !paging ) {
119+ #endif
104120 ptr = o;
105121 if (ptr >= len) throw IfcException (" Reading outside of file limits" );
106122 eof = false ;
123+ #ifdef BUF_SIZE
107124 } else if ( o >= offset && (o < (offset+len)) ) {
108125 ptr = o - offset;
109126 } else {
@@ -112,6 +129,7 @@ void File::Seek(unsigned int o) {
112129 stream.seekg (o,std::ios_base::beg);
113130 ReadBuffer (false );
114131 }
132+ #endif
115133}
116134
117135//
@@ -125,34 +143,46 @@ char File::Peek() {
125143// Returns the character at specified offset
126144//
127145char File::Read (unsigned int o) {
146+ #ifdef BUF_SIZE
128147 if ( ! paging ) {
148+ #endif
129149 return buffer[o];
150+ #ifdef BUF_SIZE
130151 } else if ( o >= offset && (o < (offset+len)) ) {
131152 return buffer[o-offset];
132153 } else {
133154 stream.clear ();
134155 stream.seekg (o,std::ios_base::beg);
135156 return stream.peek ();
136157 }
158+ #endif
137159}
138160
139161//
140162// Returns the cursor position
141163//
142164unsigned int File::Tell () {
165+ #ifdef BUF_SIZE
143166 return offset + ptr;
167+ #else
168+ return ptr;
169+ #endif
144170}
145171
146172//
147173// Increments cursor and reads new chunk if necessary
148174//
149175void File::Inc () {
150176 if ( ++ptr == len ) {
177+ #ifdef BUF_SIZE
151178 if ( paging ) ReadBuffer ();
152179 else {
180+ #endif
153181 eof = true ;
154182 return ;
183+ #ifdef BUF_SIZE
155184 }
185+ #endif
156186 }
157187 const char current = File::Peek ();
158188 if ( current == ' \n ' || current == ' \r ' ) File::Inc ();
0 commit comments