1 // Copyright 2015 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 CHROMIUMOS_WIDE_PROFILING_FILE_READER_H_ 6 #define CHROMIUMOS_WIDE_PROFILING_FILE_READER_H_ 7 8 #include <stdio.h> 9 10 #include "data_reader.h" 11 12 namespace quipper { 13 14 // Read from an input file. Must be a normal file. Does not support pipe inputs. 15 class FileReader : public DataReader { 16 public: 17 explicit FileReader(const string& filename); 18 virtual ~FileReader(); 19 20 bool IsOpen() const { return infile_; } 21 22 void SeekSet(size_t offset) override { fseek(infile_, offset, SEEK_SET); } 23 24 size_t Tell() const override { return ftell(infile_); } 25 26 bool ReadData(const size_t size, void* dest) override; 27 28 // If there is a failure reading the data from file, |*str| will not be 29 // modified. 30 bool ReadString(const size_t size, string* str) override; 31 32 private: 33 // File input handle. 34 FILE* infile_; 35 }; 36 37 } // namespace quipper 38 39 #endif // CHROMIUMOS_WIDE_PROFILING_FILE_READER_H_ 40