Arman Uguray | ccbd1ac | 2013-01-10 13:03:19 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_FILE_READER_H_ |
| 6 | #define SHILL_FILE_READER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/basictypes.h> |
| 11 | #include <base/file_path.h> |
| 12 | #include <base/file_util.h> |
| 13 | |
| 14 | namespace shill { |
| 15 | |
| 16 | // A helper class for reading a file line-by-line, which is expected to |
| 17 | // be a substitute for std::getline() as the Google C++ style guide disallows |
| 18 | // the use of stream. |
| 19 | class FileReader { |
| 20 | public: |
| 21 | FileReader(); |
| 22 | ~FileReader(); |
| 23 | |
| 24 | // Closes the file. |
| 25 | void Close(); |
| 26 | |
| 27 | // Opens the file of a given path. Returns true on success. |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 28 | bool Open(const base::FilePath &file_path); |
Arman Uguray | ccbd1ac | 2013-01-10 13:03:19 -0800 | [diff] [blame] | 29 | |
| 30 | // Reads a line, terminated by either LF or EOF, from the file into |
| 31 | // a given string, with LF excluded. Returns false if no more line |
| 32 | // can be read from the file. |
| 33 | bool ReadLine(std::string *line); |
| 34 | |
| 35 | private: |
| 36 | // The file to read. |
| 37 | file_util::ScopedFILE file_; |
| 38 | |
| 39 | DISALLOW_COPY_AND_ASSIGN(FileReader); |
| 40 | }; |
| 41 | |
| 42 | } // namespace shill |
| 43 | |
| 44 | #endif // SHILL_FILE_READER_H_ |