Home | History | Annotate | Download | only in io
      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/platform/macros.h"
     24 #include "tensorflow/core/platform/types.h"
     25 
     26 namespace tensorflow {
     27 
     28 class WritableFile;
     29 
     30 namespace io {
     31 
     32 class RecordWriter;
     33 
     34 // A wrapper around io::RecordWriter that is more easily SWIG wrapped for
     35 // Python.  An instance of this class is not safe for concurrent access
     36 // by multiple threads.
     37 class PyRecordWriter {
     38  public:
     39   // TODO(vrv): make this take a shared proto to configure
     40   // the compression options.
     41   static PyRecordWriter* New(const string& filename,
     42                              const string& compression_type_string,
     43                              TF_Status* out_status);
     44   ~PyRecordWriter();
     45 
     46   bool WriteRecord(tensorflow::StringPiece record);
     47   void Flush(TF_Status* out_status);
     48   void Close(TF_Status* out_status);
     49 
     50  private:
     51   PyRecordWriter();
     52 
     53   std::unique_ptr<io::RecordWriter> writer_;
     54   std::unique_ptr<WritableFile> file_;
     55   TF_DISALLOW_COPY_AND_ASSIGN(PyRecordWriter);
     56 };
     57 
     58 }  // namespace io
     59 }  // namespace tensorflow
     60 
     61 #endif  // TENSORFLOW_PYTHON_LIB_IO_PY_RECORD_WRITER_H_
     62