libStatGen Software  1
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 #ifdef __ZLIB_AVAILABLE__
00022 
00023 #include "FileType.h"
00024 #include <stdio.h>  // for NULL
00025 
00026 class BGZFReader;
00027 
00028 class BgzfFileTypeRecovery : public FileType
00029 {
00030 public:
00031     BgzfFileTypeRecovery()
00032     {
00033         bgzfReader = NULL;
00034     }
00035 
00036     ~BgzfFileTypeRecovery()
00037     {
00038         close();
00039     }
00040 
00041     BgzfFileTypeRecovery(const char * filename, const char * mode);
00042 
00043     // these methods should not be used.  They are
00044     // misleading because the rhs could be anything,
00045     // (specifically not a BgzfFileTypeRecover object).
00046     bool operator == (void * rhs);
00047 
00048     bool operator != (void * rhs);
00049 
00050     // Close the file.
00051     int close();
00052 
00053     // Reset to the beginning of the file.
00054     inline void rewind()
00055     {
00056         // Just call rewind to move to the beginning of the file.
00057         seek(0LL, SEEK_SET);
00058     }
00059 
00060     // Check to see if we have reached the EOF.
00061     int eof();
00062 
00063     // Check to see if the file is open.
00064     bool isOpen()
00065     {
00066         return (bgzfReader != NULL);
00067     }
00068 
00069     // Write to the file
00070     unsigned int write(const void * buffer, unsigned int size);
00071 
00072     // Read into a buffer from the file.  Since the buffer is passed in and
00073     // this would bypass the fileBuffer used by this class, this method must
00074     // be protected.
00075     int read(void * buffer, unsigned int size);
00076 
00077     // Get current position in the file.
00078     // -1 return value indicates an error.
00079     int64_t tell();
00080 
00081     // Seek to the specified offset from the origin.
00082     // origin can be any of the following:
00083     // Note: not all are valid for all filetypes.
00084     //   SEEK_SET - Beginning of file
00085     //   SEEK_CUR - Current position of the file pointer
00086     //   SEEK_END - End of file
00087     // Returns true on successful seek and false on a failed seek.
00088     bool seek(int64_t offset, int origin);
00089 
00090     bool attemptRecoverySync(bool (*checkSignature)(void *data) , int length);
00091 
00092 protected:
00093     // Read via BGZFReader
00094     BGZFReader* bgzfReader;
00095 
00096 };
00097 
00098 #endif
00099 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends