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
00110 {
00111 myEOF = false;
00112 }
00113 return bytesRead;
00114 }
00115
00116
00117
00118
00119 virtual inline long int tell()
00120 {
00121 if(myUsingBuffer)
00122 {
00123 throw std::runtime_error("IFILE: CANNOT use buffered reads and tell for BGZF files");
00124 }
00125 return bgzf_tell(bgzfHandle);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 virtual inline bool seek(long int offset, int origin)
00137 {
00138 long int returnVal = bgzf_seek(bgzfHandle, offset, origin);
00139
00140 if (returnVal == -1)
00141 {
00142 return false;
00143 }
00144
00145
00146
00147 myEOF = false;
00148 return true;
00149 }
00150
00151
00152
00153 static void setRequireEofBlock(bool requireEofBlock);
00154
00155 protected:
00156
00157 BGZF* bgzfHandle;
00158
00159
00160 bool myEOF;
00161
00162 long int myStartPos;
00163
00164
00165
00166
00167 static bool ourRequireEofBlock;
00168 };
00169
00170 #endif