OLD | NEW |
| (Empty) |
1 // Copyright 2003-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #ifndef OMAHA_COMMON_FILE_READER_H_ | |
17 #define OMAHA_COMMON_FILE_READER_H_ | |
18 | |
19 #include <windows.h> | |
20 #include <tchar.h> | |
21 #include "base/basictypes.h" | |
22 #include "base/scoped_ptr.h" | |
23 #include "omaha/base/file.h" | |
24 | |
25 namespace omaha { | |
26 | |
27 // Allows one to read files quickly and easily line by line. | |
28 class FileReader { | |
29 public: | |
30 FileReader(); | |
31 ~FileReader(); | |
32 | |
33 // Specifies the underlying file name and the size of internal read buffer. | |
34 HRESULT Init(const TCHAR* file_name, size_t buffer_size); | |
35 | |
36 // Reads one line of text from the file, taking advantage of the internal | |
37 // file buffer to optimize I/O reads. It reads at most max_len - 1 characters | |
38 // and it always terminates the line. | |
39 HRESULT ReadLineAnsi(size_t max_len, char* line); | |
40 HRESULT ReadLineString(CString* line); | |
41 | |
42 private: | |
43 HRESULT GetNextChar(bool peek, CString* next_char); | |
44 size_t file_buffer_size() const { return file_buffer_size_; } | |
45 | |
46 File file_; | |
47 bool file_is_open_; | |
48 size_t buffered_byte_count_; // How many bytes are in the buffer. | |
49 size_t current_position_; // An index into the buffer. | |
50 scoped_array<byte> file_buffer_; // A buffer (cache) of the file. | |
51 size_t file_buffer_size_; // How much of the file to slurp | |
52 // in on each read. | |
53 bool is_unicode_; | |
54 | |
55 DISALLOW_EVIL_CONSTRUCTORS(FileReader); | |
56 }; | |
57 | |
58 } // namespace omaha | |
59 | |
60 #endif // OMAHA_COMMON_FILE_READER_H_ | |
OLD | NEW |