Shaka Packager SDK
text_readers.h
1 // Copyright 2017 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #ifndef PACKAGER_MEDIA_FORMATS_WEBVTT_TEXT_READERS_H_
8 #define PACKAGER_MEDIA_FORMATS_WEBVTT_TEXT_READERS_H_
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 #include "packager/file/file_closer.h"
15 #include "packager/status.h"
16 
17 namespace shaka {
18 class File;
19 
20 namespace media {
21 
23 class FileReader {
24  public:
29  static Status Open(const std::string& filename,
30  std::unique_ptr<FileReader>* out);
31 
35  bool Next(char* out);
36 
37  private:
38  explicit FileReader(std::unique_ptr<File, FileCloser> file);
39 
40  FileReader(const FileReader& reader) = delete;
41  FileReader operator=(const FileReader& reader) = delete;
42 
43  std::unique_ptr<File, FileCloser> file_;
44 };
45 
47  public:
48  explicit PeekingReader(std::unique_ptr<FileReader> source);
49 
50  bool Peek(char* out);
51  bool Next(char* out);
52 
53  private:
54  PeekingReader(const PeekingReader&) = delete;
55  PeekingReader operator=(const PeekingReader&) = delete;
56 
57  std::unique_ptr<FileReader> source_;
58  char cached_next_ = 0;
59  bool has_cached_next_ = false;
60 };
61 
62 class LineReader {
63  public:
64  explicit LineReader(std::unique_ptr<FileReader> source);
65 
66  bool Next(std::string* out);
67 
68  private:
69  LineReader(const LineReader&) = delete;
70  LineReader operator=(const LineReader&) = delete;
71 
72  PeekingReader source_;
73 };
74 
75 class BlockReader {
76  public:
77  explicit BlockReader(std::unique_ptr<FileReader> source);
78 
79  bool Next(std::vector<std::string>* out);
80 
81  private:
82  BlockReader(const BlockReader&) = delete;
83  BlockReader operator=(const BlockReader&) = delete;
84 
85  LineReader source_;
86 };
87 
88 } // namespace media
89 } // namespace shaka
90 
91 #endif // MEDIA_FORMATS_WEBVTT_TEXT_READERS_H_
All the methods that are virtual are virtual for mocking.
bool Next(char *out)
Definition: text_readers.cc:32
Class to read character-by-character from a file.
Definition: text_readers.h:23
static Status Open(const std::string &filename, std::unique_ptr< FileReader > *out)
Definition: text_readers.cc:15