• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
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 TENSORFLOW_PYTHON_LIB_IO_PY_RECORD_WRITER_H_
17 #define TENSORFLOW_PYTHON_LIB_IO_PY_RECORD_WRITER_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/c/c_api.h"
22 #include "tensorflow/core/lib/core/stringpiece.h"
23 #include "tensorflow/core/lib/io/record_writer.h"
24 #include "tensorflow/core/platform/macros.h"
25 #include "tensorflow/core/platform/types.h"
26 
27 namespace tensorflow {
28 
29 class WritableFile;
30 
31 namespace io {
32 
33 class RecordWriter;
34 
35 // A wrapper around io::RecordWriter that is more easily SWIG wrapped for
36 // Python.  An instance of this class is not safe for concurrent access
37 // by multiple threads.
38 class PyRecordWriter {
39  public:
40   static PyRecordWriter* New(const string& filename,
41                              const io::RecordWriterOptions& compression_options,
42                              TF_Status* out_status);
43   ~PyRecordWriter();
44 
45   void WriteRecord(tensorflow::StringPiece record, TF_Status* out_status);
46   void Flush(TF_Status* out_status);
47   void Close(TF_Status* out_status);
48 
49  private:
50   PyRecordWriter();
51 
52   std::unique_ptr<io::RecordWriter> writer_;
53   std::unique_ptr<WritableFile> file_;
54   TF_DISALLOW_COPY_AND_ASSIGN(PyRecordWriter);
55 };
56 
57 }  // namespace io
58 }  // namespace tensorflow
59 
60 #endif  // TENSORFLOW_PYTHON_LIB_IO_PY_RECORD_WRITER_H_
61