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