20 #include "GlfException.h" 39 bool openStatus =
true;
54 std::cerr <<
"FAILURE - EXITING!!!" << std::endl;
71 myFilePtr =
ifopen(filename,
"rb");
73 if (myFilePtr == NULL)
75 std::string errorMessage =
"Failed to Open ";
76 errorMessage += filename;
77 errorMessage +=
" for reading";
83 myIsOpenForRead =
true;
123 if (myFilePtr == NULL)
125 std::string errorMessage =
"Failed to Open ";
126 errorMessage += filename;
127 errorMessage +=
" for writing";
133 myIsOpenForWrite =
true;
154 if (myFilePtr != NULL)
157 return(
ifeof(myFilePtr));
167 if(myIsOpenForRead ==
false)
171 "Cannot read header since the file is not open for reading");
176 if(myNextSection != HEADER)
180 "Cannot read header since it has already been read.");
185 if(header.
read(myFilePtr))
188 myNextSection = REF_SECTION;
193 "Failed to read the header.");
202 if(myIsOpenForWrite ==
false)
208 "Cannot write header since the file is not open for writing");
213 if(myNextSection != HEADER)
217 "Cannot write header since it has already been written");
222 if(header.
write(myFilePtr))
225 myNextSection = REF_SECTION;
232 "Failed to write the header.");
242 if(myIsOpenForRead ==
false)
246 "Cannot read reference section since the file is not open for reading");
251 if(myNextSection == HEADER)
256 "Cannot read reference section since the header has not been read.");
262 if(myNextSection == RECORD)
277 if(myNextSection != REF_SECTION)
281 "Failed to get to a reference section.");
287 if(refSection.
read(myFilePtr))
291 myNextSection = RECORD;
301 "Failed reading a reference section from the file.");
310 if(myIsOpenForWrite ==
false)
314 "Cannot write reference section since the file is not open for writing");
319 if(myNextSection == HEADER)
323 "Cannot write reference section since the header has not been written");
328 if(myNextSection == RECORD)
335 "Failed to write end of chromosome/section marker.");
341 if(myNextSection != REF_SECTION)
345 "Not ready for a chromosome/section header.");
350 if(refSection.
write(myFilePtr))
354 myNextSection = RECORD;
360 "Failed writing a reference section to the file.");
370 if(myIsOpenForRead ==
false)
374 "Cannot read reference section since the file is not open for reading");
379 if(myNextSection == HEADER)
383 "Cannot read reference section since the header has not been read.");
388 if(myNextSection == REF_SECTION)
393 "Cannot read record since a reference section has not been read.");
405 if(record.
read(myFilePtr))
416 myNextSection = REF_SECTION;
422 "Failed reading a record from the file.");
431 if(myIsOpenForWrite ==
false)
437 "Cannot write record since the file is not open for writing");
442 if(myNextSection == HEADER)
446 "Cannot write record since the header has not been written");
451 if(myNextSection != RECORD)
455 "Cannot write record since a reference section has not been written");
460 if(record.
write(myFilePtr))
469 myNextSection = REF_SECTION;
476 "Failed writing a record to the file.");
485 return(myRecordCount);
490 void GlfFile::resetFile()
493 if (myFilePtr != NULL)
499 if(myIsOpenForWrite && (myNextSection == RECORD))
505 "Failed to write end of chromosome/section marker.");
513 myIsOpenForRead =
false;
514 myIsOpenForWrite =
false;
517 myNextSection = HEADER;
534 std::cerr <<
"FAILURE - EXITING!!!" << std::endl;
540 GlfFileReader::~GlfFileReader()
558 std::cerr <<
"FAILURE - EXITING!!!" << std::endl;
564 GlfFileWriter::~GlfFileWriter()
bool isEOF()
Returns whether or not the end of the file has been reached.
GlfFileWriter()
Default Constructor.
GlfException objects should be thrown by functions that operate on Glf files for exceptions.
const char * getStatusMessage()
Get the Status of the last call that sets status.
bool write(IFILE filePtr) const
Write the refSection to the specified file.
bool openForWrite(const char *filename, bool compressed=true)
Open a glf file for writing with the specified filename.
uint32_t getCurrentRecordCount()
Return the number of records that have been read/written so far.
This class allows a user to easily get/set the fields in a GLF section/chromosome header...
bool read(IFILE filePtr)
Read the record from the specified file (file MUST be in the correct position for reading a record)...
void close()
Close the file if there is one open, adding an end marker record if there is a previous section and o...
bool write(IFILE filePtr) const
Write the record to the specified file.
bool getNextRecord(GlfRecord &record)
Gets the nextrecord from the file & stores it in the passed in record.
unknown result (default value should never be used)
bool openForRead(const char *filename)
Open a glf file for reading with the specified filename.
This class allows a user to easily get/set the fields in a GLF record.
bool writeRefSection(const GlfRefSection &refSection)
Write the reference section to the file, adding an end marker record if there is a previous section a...
method completed successfully.
bool getNextRefSection(GlfRefSection &refSection)
Gets the next reference section from the file & stores it in the passed in section, consuming records until a new section is found.
GlfFileReader()
Default Constructor.
int getRecordType() const
Return the record type.
OpenType
Enum for indicating whether to open the file for read or write.
virtual ~GlfFile()
Closes the file if there is one open, adding an end marker record if there is a previous section and ...
method failed due to an I/O issue.
method failed because it was called out of order, like trying to read a file without opening it for r...
bool read(IFILE filePtr)
Read the refSection from the specified file (file MUST be in the correct position for reading a refSe...
bool readHeader(GlfHeader &header)
Reads the header section from the file and stores it in the passed in header.
GlfFile()
Default Constructor.
bool writeHeader(GlfHeader &header)
Writes the specified header into the file.
void setStatus(Status newStatus, const char *newMessage)
Set the status with the specified values.
bool writeRecord(const GlfRecord &record)
Writes the specified record into the file.