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