BgzfFileType.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __BGZFFILETYPE_H__
00019 #define __BGZFFILETYPE_H__
00020
00021 #ifdef __ZLIB_AVAILABLE__
00022
00023 #include <stdexcept>
00024 #include "bgzf.h"
00025 #include "FileType.h"
00026
00027 class BgzfFileType : public FileType
00028 {
00029 public:
00030 BgzfFileType()
00031 {
00032 bgzfHandle = NULL;
00033 myEOF = false;
00034 }
00035
00036 virtual ~BgzfFileType()
00037 {
00038 bgzfHandle = NULL;
00039 }
00040
00041 BgzfFileType(const char * filename, const char * mode);
00042
00043 virtual bool operator == (void * rhs)
00044 {
00045
00046
00047 if (rhs != NULL)
00048 return false;
00049 return (bgzfHandle == rhs);
00050 }
00051
00052 virtual bool operator != (void * rhs)
00053 {
00054
00055
00056 if (rhs != NULL)
00057 return true;
00058 return (bgzfHandle != rhs);
00059 }
00060
00061
00062 virtual inline int close()
00063 {
00064 int result = bgzf_close(bgzfHandle);
00065 bgzfHandle = NULL;
00066 return result;
00067 }
00068
00069
00070
00071 virtual inline void rewind()
00072 {
00073
00074 seek(myStartPos, SEEK_SET);
00075 }
00076
00077
00078 virtual inline int eof()
00079 {
00080
00081 return myEOF;
00082 }
00083
00084
00085 virtual inline bool isOpen()
00086 {
00087 if (bgzfHandle != NULL)
00088 {
00089
00090 return(true);
00091 }
00092 return(false);
00093 }
00094
00095
00096 virtual inline unsigned int write(const void * buffer, unsigned int size)
00097 {
00098 return bgzf_write(bgzfHandle, buffer, size);
00099 }
00100
00101
00102
00103
00104 virtual inline int read(void * buffer, unsigned int size)
00105 {
00106 int bytesRead = bgzf_read(bgzfHandle, buffer, size);
00107 if ((bytesRead == 0) && (size != 0))
00108 {
00109 myEOF = true;
00110 }
00111 else if((bytesRead != (int)size) & (bytesRead >= 0))
00112 {
00113
00114
00115 myEOF = true;
00116 }
00117 else
00118 {
00119 myEOF = false;
00120 }
00121 return bytesRead;
00122 }
00123
00124
00125
00126
00127 virtual inline int64_t tell()
00128 {
00129 if(myUsingBuffer)
00130 {
00131 throw std::runtime_error("IFILE: CANNOT use buffered reads and tell for BGZF files");
00132 }
00133 return bgzf_tell(bgzfHandle);
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 virtual inline bool seek(int64_t offset, int origin)
00145 {
00146 int64_t returnVal = bgzf_seek(bgzfHandle, offset, origin);
00147
00148 if (returnVal == -1)
00149 {
00150 return false;
00151 }
00152
00153
00154
00155 myEOF = false;
00156 return true;
00157 }
00158
00159
00160
00161 static void setRequireEofBlock(bool requireEofBlock);
00162
00163 protected:
00164
00165 BGZF* bgzfHandle;
00166
00167
00168 bool myEOF;
00169
00170 int64_t myStartPos;
00171
00172
00173
00174
00175 static bool ourRequireEofBlock;
00176 };
00177
00178 #endif
00179 #endif