STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stdio_filebuf.h
Go to the documentation of this file.
1 // File descriptor layer for filebuf -*- C++ -*-
2 
3 // Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
19 
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
24 
29 #ifndef _STDIO_FILEBUF_H
30 #define _STDIO_FILEBUF_H 1
31 
32 #pragma GCC system_header
33 
34 #include <fstream>
35 
36 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
37 {
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
39 
49  template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
50  class stdio_filebuf : public std::basic_filebuf<_CharT, _Traits>
51  {
52  public:
53  // Types:
54  typedef _CharT char_type;
55  typedef _Traits traits_type;
56  typedef typename traits_type::int_type int_type;
57  typedef typename traits_type::pos_type pos_type;
58  typedef typename traits_type::off_type off_type;
59  typedef std::size_t size_t;
60 
61  public:
65  stdio_filebuf() : std::basic_filebuf<_CharT, _Traits>() {}
66 
77  stdio_filebuf(int __fd, std::ios_base::openmode __mode,
78  size_t __size = static_cast<size_t>(BUFSIZ));
79 
90  stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode,
91  size_t __size = static_cast<size_t>(BUFSIZ));
92 
97  virtual
98  ~stdio_filebuf();
99 
108  int
109  fd() { return this->_M_file.fd(); }
110 
118  std::__c_file*
119  file() { return this->_M_file.file(); }
120  };
121 
122  template<typename _CharT, typename _Traits>
123  stdio_filebuf<_CharT, _Traits>::~stdio_filebuf()
124  { }
125 
126  template<typename _CharT, typename _Traits>
127  stdio_filebuf<_CharT, _Traits>::
128  stdio_filebuf(int __fd, std::ios_base::openmode __mode, size_t __size)
129  {
130  this->_M_file.sys_open(__fd, __mode);
131  if (this->is_open())
132  {
133  this->_M_mode = __mode;
134  this->_M_buf_size = __size;
135  this->_M_allocate_internal_buffer();
136  this->_M_reading = false;
137  this->_M_writing = false;
138  this->_M_set_buffer(-1);
139  }
140  }
141 
142  template<typename _CharT, typename _Traits>
143  stdio_filebuf<_CharT, _Traits>::
144  stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode,
145  size_t __size)
146  {
147  this->_M_file.sys_open(__f, __mode);
148  if (this->is_open())
149  {
150  this->_M_mode = __mode;
151  this->_M_buf_size = __size;
152  this->_M_allocate_internal_buffer();
153  this->_M_reading = false;
154  this->_M_writing = false;
155  this->_M_set_buffer(-1);
156  }
157  }
158 
159 _GLIBCXX_END_NAMESPACE_VERSION
160 } // namespace
161 
162 #endif
std::size_t __size(__stack_t __stack)
Definition: profiler_node.h:68
namespace std _GLIBCXX_VISIBILITY(default)
Definition: auto_ptr.h:36
__SIZE_TYPE__ size_t
Definition: stddef.h:212