libStatGen Software  1
FileType.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 __FILETYPE_H__
00019 #define __FILETYPE_H__
00020 
00021 #include <stdint.h>
00022 
00023 class FileType
00024 {
00025 public:
00026     FileType();
00027     virtual ~FileType();
00028 
00029     virtual bool operator == (void * rhs) = 0;
00030 
00031     virtual bool operator != (void * rhs) = 0;
00032 
00033     // Close the file.
00034     virtual int close() = 0;
00035 
00036     // Reset to the beginning of the file.
00037     virtual void rewind() = 0;
00038 
00039     // Check to see if we have reached the EOF.
00040     virtual int eof() = 0;
00041 
00042     // Check to see if the file is open.
00043     virtual bool isOpen() = 0;
00044 
00045     // Write to the file.
00046     virtual unsigned int write(const void * buffer, unsigned int size) = 0;
00047 
00048     // Read into a buffer from the file.
00049     virtual int read(void * buffer, unsigned int size) = 0;
00050 
00051     // Get current position in the file.
00052     // -1 return value indicates an error.
00053     virtual int64_t tell() = 0;
00054 
00055     // Seek to the specified offset from the origin.
00056     // origin can be any of the following:
00057     // Note: not all are valid for all filetypes.
00058     //   SEEK_SET - Beginning of file
00059     //   SEEK_CUR - Current position of the file pointer
00060     //   SEEK_END - End of file
00061     // Returns true on successful seek and false on a failed seek.
00062     virtual bool seek(int64_t offset, int origin) = 0;
00063 
00064     // Set by the InputFile to inform this class if buffering
00065     // is used.  Maybe used by child clases (bgzf) to disable 
00066     // tell.  NOTE: this class does no buffering, the
00067     // buffering is handled by the calling class.
00068     void setBuffered(bool buffered);
00069 
00070     //
00071     // When caller catches an exception, it may call this method.
00072     // It is implemented only in BgzfFileTypeRecovery.
00073     //
00074     virtual bool attemptRecoverySync(bool (*checkSignature)(void *data) , int length);
00075 
00076 protected:
00077     // Set by the InputFile to inform this class if buffering
00078     // is used.  Maybe used by child clases (bgzf) to disable 
00079     // tell.
00080     bool myUsingBuffer;
00081 };
00082 
00083 #endif
00084 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends