Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/libdar/tronc.hpp
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00031 
00032 #ifndef TRONC_HPP
00033 #define TRONC_HPP
00034 
00035 #include "../my_config.h"
00036 #include "infinint.hpp"
00037 #include "generic_file.hpp"
00038 
00039 namespace libdar
00040 {
00043 
00045 
00046     class tronc : public generic_file
00047     {
00048     public :
00050 
00055         tronc(generic_file *f, const infinint &offset, const infinint &size, bool own_f = false);
00056         tronc(generic_file *f, const infinint &offset, const infinint &size, gf_mode mode, bool own_f = false);
00057 
00060         tronc(generic_file *f, const infinint &offset, bool own_f = false);
00061         tronc(generic_file *f, const infinint &offset, gf_mode mode, bool own_f = false);
00062 
00064         ~tronc()
00065         {
00066             if(own_ref)
00067                 delete ref;
00068         };
00069 
00071         bool skip(const infinint & pos);
00073         bool skip_to_eof();
00075         bool skip_relative(S_I x);
00077         infinint get_position() { return current; };
00078 
00079 #ifdef LIBDAR_SPECIAL_ALLOC
00080         USE_SPECIAL_ALLOC(tronc);
00081 #endif
00082     protected :
00084         U_I inherited_read(char *a, U_I size);
00086         void inherited_write(const char *a, U_I size);
00087         void inherited_sync_write() { ref->sync_write(); }
00088         void inherited_terminate() {if(own_ref) ref->terminate(); };
00089 
00090     private :
00091         infinint start;  //< offset in the global generic file to start at
00092         infinint sz;     //< length of the portion to consider
00093         generic_file *ref; //< global generic file of which to take a piece
00094         infinint current;  //< inside position of the next read or write
00095         bool own_ref;      //< whether we own ref (and must destroy it when no more needed)
00096         bool limited;      //< whether the sz argument is to be considered
00097 
00098         void set_back_current_position();
00099     };
00100 
00102 
00103 } // end of namespace
00104 
00105 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines