kaldi-pipebuf.h
Go to the documentation of this file.
1 // util/kaldi-pipebuf.h
2 
3 // Copyright 2009-2011 Ondrej Glembek
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 
11 // http://www.apache.org/licenses/LICENSE-2.0
12 
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
25 #ifndef KALDI_UTIL_KALDI_PIPEBUF_H_
26 #define KALDI_UTIL_KALDI_PIPEBUF_H_
27 
28 #include<string>
29 #if !defined(_LIBCPP_VERSION) // libc++
30 #include <fstream>
31 #else
32 #include "util/basic-filebuf.h"
33 #endif
34 
35 namespace kaldi {
36 // This class provides a way to initialize a filebuf with a FILE* pointer
37 // directly; it will not close the file pointer when it is deleted.
38 // The C++ standard does not allow implementations of C++ to provide
39 // this constructor within basic_filebuf, which makes it hard to deal
40 // with pipes using completely native C++. This is a workaround
41 
42 #ifdef _MSC_VER
43 #elif defined(_LIBCPP_VERSION) // libc++
44 template<class CharType, class Traits = std::char_traits<CharType> >
45 class basic_pipebuf : public basic_filebuf<CharType, Traits> {
46  public:
47  typedef basic_pipebuf<CharType, Traits> ThisType;
48 
49  public:
50  basic_pipebuf(FILE *fptr, std::ios_base::openmode mode)
51  : basic_filebuf<CharType, Traits>() {
52  this->open(fptr, mode);
53  if (!this->is_open()) {
54  KALDI_WARN << "Error initializing pipebuf"; // probably indicates
55  // code error, if the fptr was good.
56  return;
57  }
58  }
59 }; // class basic_pipebuf
60 #else
61 template<class CharType, class Traits = std::char_traits<CharType> >
62 class basic_pipebuf : public std::basic_filebuf<CharType, Traits> {
63  public:
65 
66  public:
67  basic_pipebuf(FILE *fptr, std::ios_base::openmode mode)
68  : std::basic_filebuf<CharType, Traits>() {
69  this->_M_file.sys_open(fptr, mode);
70  if (!this->is_open()) {
71  KALDI_WARN << "Error initializing pipebuf"; // probably indicates
72  // code error, if the fptr was good.
73  return;
74  }
75  this->_M_mode = mode;
76  this->_M_buf_size = BUFSIZ;
77  this->_M_allocate_internal_buffer();
78  this->_M_reading = false;
79  this->_M_writing = false;
80  this->_M_set_buffer(-1);
81  }
82 }; // class basic_pipebuf
83 #endif // _MSC_VER
84 
85 } // namespace kaldi
86 
87 #endif // KALDI_UTIL_KALDI_PIPEBUF_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
basic_pipebuf(FILE *fptr, std::ios_base::openmode mode)
Definition: kaldi-pipebuf.h:67
#define KALDI_WARN
Definition: kaldi-error.h:150
basic_pipebuf< CharType, Traits > ThisType
Definition: kaldi-pipebuf.h:64