file.hpp

00001 /*
00002 
00003 Copyright (c) 2002-2005, Yauheni Akhotnikau
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009 - Redistributions of source code must retain the above copyright notice, this
00010 list of conditions and the following disclaimer.
00011 
00012 - Redistributions in binary form must reproduce the above copyright notice, this
00013 list of conditions and the following disclaimer in the documentation and/or
00014 other materials provided with the distribution.
00015 
00016 - The name of the author may not be used to endorse or promote products derived
00017 from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00020 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00021 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00022 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00024 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00027 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00028 OF SUCH DAMAGE.
00029 
00030 */
00031 
00032 #if !defined( _OESS_1__FILE__FILE_HPP_ )
00033 #define _OESS_1__FILE__FILE_HPP_
00034 
00035 #include <oess_1/file/h/declspec.hpp>
00036 
00037 #include <auto_ptr_3/h/vect_ptr.hpp>
00038 
00039 #include <oess_1/io/h/binstream.hpp>
00040 
00041 namespace oess_1 {
00042 
00043 namespace file {
00044 
00045 //
00046 // file_t
00047 //
00048 
00052 class OESS_1__FILE__TYPE  file_t :
00053   public oess_1::io::ibinstream_t,
00054   public oess_1::io::obinstream_t
00055 {
00056   public :
00057     file_t();
00058     virtual ~file_t();
00059 
00061     void
00062     open(
00064       const std::string & file_name,
00067       bool is_read_only );
00068 
00071     void
00072     create(
00074       const std::string & file_name );
00075 
00078     void
00079     close();
00080 
00082     oess_1::uint_t
00083     tell();
00084 
00086     void
00087     seek( oess_1::uint_t pos );
00088 
00090     oess_1::uint_t
00091     length();
00092 
00094     virtual bool
00095     eof() const;
00096 
00098     void
00099     chsize(
00100       oess_1::uint_t size );
00101 
00103     static void
00104     remove( const std::string & file_name );
00105 
00113     static bool
00114     is_file_exists(
00115       const std::string & file_name );
00116 
00129     static void
00130     rename_file(
00132       const std::string & what,
00134       const std::string & to,
00136       bool auto_destroy_existing_target = false );
00137 
00138   protected :
00139     /*
00140       ВНИМАНИЕ!
00141       В реализации класса file_t используется
00142       тот факт, что любая операция ввода/вывода
00143       использует парные вызовы in_reserve/in_shift
00144       (out_reserve/out_shift).
00145       Поэтому метод in_reserve осуществляет загрузку
00146       требуемого фрагмента в память. Метод out_shift
00147       осуществляет запись фрагмента в файл.
00148       Т.е. содержимое считываемого/записываемого
00149       фрагмента является актуальным во внутреннем буфере
00150       класса file_t только между вызовами *_reserve/ *_shift.
00151       В остальное время буфер считается незаполненым.
00152     */
00153 
00162     virtual const oess_1::char_t *
00163     in_reserve(
00166       size_t item_count,
00168       size_t item_size,
00171       size_t & item_available );
00172 
00179     virtual void
00180     in_shift(
00182       size_t item_count,
00184       size_t item_size );
00185 
00194     virtual oess_1::char_t *
00195     out_reserve(
00198       size_t item_count,
00200       size_t item_size,
00203       size_t & item_available );
00204 
00211     virtual void
00212     out_shift(
00214       size_t item_count,
00216       size_t item_size );
00217 
00218   private :
00220     auto_ptr_3::vect_ptr_t< oess_1::char_t >  m_buf;
00221 
00223     int m_file;
00225     bool  m_is_read_only;
00226 
00230     void
00231     is_workable(
00235       bool is_read_only_op ) const;
00236 };
00237 
00238 } 
00240 } 
00242 #endif

Документация по ObjESSty. Последние изменения: Fri Oct 13 18:35:36 2006. Создано системой  doxygen 1.4.7
Hosted by uCoz