Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. // Wrapper of C-language FILE struct -*- C++ -*-
  2.  
  3. // Copyright (C) 1999, 2000, 2001 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 2, 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. // You should have received a copy of the GNU General Public License along
  17. // with this library; see the file COPYING.  If not, write to the Free
  18. // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  19. // USA.
  20.  
  21. // As a special exception, you may use this file as part of a free software
  22. // library without restriction.  Specifically, if other files instantiate
  23. // templates or use macros or inline functions from this file, or you compile
  24. // this file and link it with other files to produce an executable, this
  25. // file does not by itself cause the resulting executable to be covered by
  26. // the GNU General Public License.  This exception does not however
  27. // invalidate any other reasons why the executable file might be covered by
  28. // the GNU General Public License.
  29.  
  30. //
  31. // ISO C++ 14882: 27.8  File-based streams
  32. //
  33.  
  34. #ifndef _CPP_BASIC_FILE
  35. #define _CPP_BASIC_FILE         1
  36.  
  37. #pragma GCC system_header
  38.  
  39. #include <bits/c++config.h>
  40. #include <bits/std_ios.h>
  41.  
  42. namespace std
  43. {
  44.   // Ulrich is going to make some detailed comment here, explaining
  45.   // all this unpleasantness, providing detailed performance analysis
  46.   // as to why we have to do all this lame vtable hacking instead of a
  47.   // sane, function-based approach. This verbiage will provide a clear
  48.   // and detailed description of the whole object-layout,
  49.   // vtable-swapping, sordid history of this hack.
  50.   template<typename _CharT>
  51.     struct __basic_file_base: public __c_file_type
  52.     {
  53.       virtual
  54.       ~__basic_file_base() { };
  55.  
  56.       virtual int
  57.       overflow(int __c = EOF) = 0;
  58.  
  59.       virtual int
  60.       underflow() = 0;
  61.  
  62.       virtual int
  63.       uflow() = 0;
  64.  
  65.       virtual int
  66.       pbackfail(int __c) = 0;
  67.  
  68.       virtual streamsize
  69.       xsputn(const _CharT* __s, streamsize __n) = 0;
  70.  
  71.       virtual streamsize
  72.       xsgetn(_CharT* __s, streamsize __n) = 0;
  73.  
  74.       virtual streamoff
  75.       seekoff(streamoff __off, ios_base::seekdir __way,
  76.               ios_base::openmode __mode = ios_base::in | ios_base::out) = 0;
  77.  
  78.       virtual streamoff
  79.       seekpos(streamoff __pos,
  80.               ios_base::openmode __mode = ios_base::in | ios_base::out) = 0;
  81.  
  82.       virtual streambuf*
  83.       setbuf(_CharT* __b, int __len) = 0;
  84.  
  85.       virtual int
  86.       sync() = 0;
  87.  
  88.       virtual int
  89.       doallocate() = 0;
  90.  
  91.       virtual streamsize
  92.       sys_read(_CharT* __s, streamsize __n) = 0;
  93.  
  94.       virtual streamsize
  95.       sys_write(const _CharT* __s, streamsize __n) = 0;
  96.  
  97.       virtual streamoff
  98.       sys_seek(streamoff __off, ios_base::seekdir __way) = 0;
  99.  
  100.       virtual int
  101.       sys_close() = 0;
  102.  
  103.       virtual int
  104.       sys_stat(void* __v) = 0;
  105.  
  106.       virtual int
  107.       showmanyc() = 0;
  108.  
  109.       virtual void
  110.       imbue(void* __v) = 0;
  111.     };
  112.  
  113.   // Some of these member functions are based on libio/filebuf.cc.
  114.   // Also note that the order and number of virtual functions has to precisely
  115.   // match the order and number in the _IO_jump_t struct defined in libioP.h.
  116.   template<typename _CharT>
  117. #ifdef _GLIBCPP_BASIC_FILE_INHERITANCE
  118.     class __basic_file: public __basic_file_base<_CharT>
  119. #else
  120.     class __basic_file
  121. #endif
  122.     {
  123. #if _GLIBCPP_BASIC_FILE_ENCAPSULATION
  124.       __c_file_type*    _M_cfile;
  125.       bool              _M_cfile_created;
  126. #else
  127. # ifdef _GLIBCPP_USE_WCHAR_T
  128.       __c_wfile_type    _M_wfile;
  129. # endif
  130. #endif
  131.  
  132.     public:
  133.       __basic_file(__c_lock* __lock = 0);
  134.      
  135.       void
  136.       _M_open_mode(ios_base::openmode __mode, int& __p_mode, int& __rw_mode,
  137.                    char* __c_mode);
  138.      
  139.       // Equivalent to the normal fopen function.
  140.       __basic_file*
  141.       open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
  142.  
  143.       // Used for opening the standard streams, cin, cout, cerr, clog,
  144.       // and their wide-stream equivalents. Instead of calling open, it
  145.       // just sets __c_file_type->_fileno and the respective _flags bits, and
  146.       // returns.
  147.       __basic_file*
  148.       sys_open(__c_file_type* __file, ios_base::openmode __mode);
  149.  
  150.       _CharT
  151.       sys_getc();
  152.  
  153.       _CharT
  154.       sys_ungetc(_CharT);
  155.  
  156.       __basic_file*
  157.       close();
  158.  
  159.       bool
  160.       is_open();
  161.  
  162.       // NB: Must match FILE specific jump table starting here--this
  163.       // means all virtual functions starting with the dtor must match,
  164.       // slot by slot. For glibc-based dystems, this means the _IO_FILE
  165.       // as the FILE struct and _IO_jump_t as the jump table.
  166.       virtual
  167.       ~__basic_file(); // Takes the place of __finish.
  168.  
  169.       virtual int
  170.       overflow(int __c = EOF);
  171.  
  172.       virtual int
  173.       underflow();
  174.  
  175.       virtual int
  176.       uflow();
  177.  
  178.       virtual int
  179.       pbackfail(int __c);
  180.  
  181.       // A complex "write" function that sets all of __c_file_type's
  182.       // pointers and associated data members correctly and manages its
  183.       // relation to the external byte sequence.
  184.       virtual streamsize
  185.       xsputn(const _CharT* __s, streamsize __n);
  186.  
  187.       // A complex "read" function that sets all of __c_file_type's
  188.       // pointers and associated data members correctly and manages its
  189.       // relation to the external byte sequence.
  190.       virtual streamsize
  191.       xsgetn(_CharT* __s, streamsize __n);
  192.  
  193.       // A complex "seekoff" function that sets all of __c_file_type's
  194.       // pointers and associated data members correctly and manages its
  195.       // relation to the external byte sequence.
  196.       virtual streamoff
  197.       seekoff(streamoff __off, ios_base::seekdir __way,
  198.               ios_base::openmode __mode = ios_base::in | ios_base::out);
  199.  
  200.       // A complex "seekpos" function that sets all of __c_file_type's
  201.       // pointers and associated data members correctly and manages its
  202.       // relation to the external byte sequence.
  203.       virtual streamoff
  204.       seekpos(streamoff __pos,
  205.               ios_base::openmode __mode = ios_base::in | ios_base::out);
  206.  
  207.       virtual streambuf*
  208.       setbuf(_CharT* __b, int __len);
  209.  
  210.       virtual int
  211.       sync();
  212.  
  213.       virtual int
  214.       doallocate();
  215.  
  216.       // A simple read function for the external byte sequence, that
  217.       // does no mucking around with or setting of the pointers or flags
  218.       // in __c_file_type.
  219.       virtual streamsize
  220.       sys_read(_CharT* __s, streamsize __n);
  221.  
  222.       // A simple write function for the external byte sequence, that
  223.       // does no mucking around with or setting of the pointers or flags
  224.       // in __c_file_type.
  225.       virtual streamsize
  226.       sys_write(const _CharT* __s, streamsize __n);
  227.  
  228.       // A simple seek function for the external byte sequence, that
  229.       // does no mucking around with or setting of the pointers or flags
  230.       // in __c_file_type.
  231.       virtual streamoff
  232.       sys_seek(streamoff __off, ios_base::seekdir __way);
  233.  
  234.       virtual int
  235.       sys_close();
  236.  
  237.       virtual int
  238.       sys_stat(void* __v);
  239.  
  240.       virtual int
  241.       showmanyc();
  242.  
  243.       virtual void
  244.       imbue(void* __v);
  245.     };
  246. } // namespace std
  247.  
  248. // Now include the bits that are dependant on the underlying I/O
  249. // model chosen at configure time.
  250. #include <bits/basic_file_model.h>
  251.  
  252. #endif  // _CPP_BASIC_FILE
  253.