blob: 63ee0130100897312ee0a2b31ffcd18fd18bd1df [file] [log] [blame]
Arman Ugurayccbd1ac2013-01-10 13:03:19 -08001// 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
Ben Chancc67c522014-09-03 07:19:18 -070010#include <base/macros.h>
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/files/file_path.h>
Ben Chan6fbf64f2014-05-21 18:07:01 -070012#include <base/files/scoped_file.h>
Arman Ugurayccbd1ac2013-01-10 13:03:19 -080013
14namespace 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.
19class 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.
Paul Stewart8ae18742015-06-16 13:13:10 -070028 bool Open(const base::FilePath& file_path);
Arman Ugurayccbd1ac2013-01-10 13:03:19 -080029
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.
Paul Stewart8ae18742015-06-16 13:13:10 -070033 bool ReadLine(std::string* line);
Arman Ugurayccbd1ac2013-01-10 13:03:19 -080034
35 private:
36 // The file to read.
Ben Chan6fbf64f2014-05-21 18:07:01 -070037 base::ScopedFILE file_;
Arman Ugurayccbd1ac2013-01-10 13:03:19 -080038
39 DISALLOW_COPY_AND_ASSIGN(FileReader);
40};
41
42} // namespace shill
43
44#endif // SHILL_FILE_READER_H_