BgzfFileTypeRecovery.h

00001 /*
00002  *  Copyright (C) 2010  Regents of the University of Michigan
00003  *
00004  *   This program is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef __BGZFFILETYPERECOVERY_H__
00019 #define __BGZFFILETYPERECOVERY_H__
00020 
00021 #include "FileType.h"
00022 #include <stdio.h>  // for NULL
00023 
00024 class BGZFReader;
00025 
00026 class BgzfFileTypeRecovery : public FileType
00027 {
00028 public:
00029     BgzfFileTypeRecovery()
00030     {
00031         bgzfReader = NULL;
00032     }
00033 
00034     ~BgzfFileTypeRecovery()
00035     {
00036         close();
00037     }
00038 
00039     BgzfFileTypeRecovery(const char * filename, const char * mode);
00040 
00041     // these methods should not be used.  They are
00042     // misleading because the rhs could be anything,
00043     // (specifically not a BgzfFileTypeRecover object).
00044     bool operator == (void * rhs);
00045 
00046     bool operator != (void * rhs);
00047 
00048     // Close the file.
00049     int close();
00050 
00051     // Reset to the beginning of the file.
00052     inline void rewind()
00053     {
00054         // Just call rewind to move to the beginning of the file.
00055         seek(0LL, SEEK_SET);
00056     }
00057 
00058     // Check to see if we have reached the EOF.
00059     int eof();
00060 
00061     // Check to see if the file is open.
00062     bool isOpen()
00063     {
00064         return (bgzfReader != NULL);
00065     }
00066 
00067     // Write to the file
00068     unsigned int write(const void * buffer, unsigned int size);
00069 
00070     // Read into a buffer from the file.  Since the buffer is passed in and
00071     // this would bypass the fileBuffer used by this class, this method must
00072     // be protected.
00073     int read(void * buffer, unsigned int size);
00074 
00075     // Get current position in the file.
00076     // -1 return value indicates an error.
00077     int64_t tell();
00078 
00079     // Seek to the specified offset from the origin.
00080     // origin can be any of the following:
00081     // Note: not all are valid for all filetypes.
00082     //   SEEK_SET - Beginning of file
00083     //   SEEK_CUR - Current position of the file pointer
00084     //   SEEK_END - End of file
00085     // Returns true on successful seek and false on a failed seek.
00086     bool seek(int64_t offset, int origin);
00087 
00088     bool attemptRecoverySync(bool (*checkSignature)(void *data) , int length);
00089 
00090 protected:
00091     // Read via BGZFReader
00092     BGZFReader* bgzfReader;
00093 
00094 };
00095 
00096 #endif
Generated on Tue Sep 6 17:52:00 2011 for libStatGen Software by  doxygen 1.6.3