#include <stdio.h>#include <iostream>#include <cstring>#include "FileType.h"

Go to the source code of this file.
Classes | |
| class | InputFile |
| Class for easily reading/writing files without having to worry about file type (uncompressed, gzip, bgzf) when reading. More... | |
Typedefs | |
| typedef InputFile * | IFILE |
| Define IFILE as a pointer to an InputFile object. | |
Functions | |
| IFILE | ifopen (const char *filename, const char *mode, InputFile::ifileCompression compressionMode=InputFile::DEFAULT) |
| Open a file. | |
| int | ifclose (IFILE file) |
| Close the file. | |
| unsigned int | ifread (IFILE file, void *buffer, unsigned int size) |
| Read size bytes from the file into the buffer. | |
| int | ifgetc (IFILE file) |
| Get a character from the file. | |
| void | ifrewind (IFILE file) |
| Reset to the beginning of the file. | |
| int | ifeof (IFILE file) |
| Check to see if we have reached the EOF. | |
| unsigned int | ifwrite (IFILE file, const void *buffer, unsigned int size) |
| Write the specified buffer into the file. | |
| long int | iftell (IFILE file) |
| Get current position in the file. | |
| bool | ifseek (IFILE file, long int offset, int origin) |
| Seek to the specified offset from the origin. | |
| int | ifprintf (IFILE output, char *format,...) |
| Write to a file using fprintf format. | |
| IFILE | operator>> (IFILE stream, std::string &str) |
| Read a line from a file using streaming. | |
Definition in file InputFile.h.
| int ifclose | ( | IFILE | file | ) | [inline] |
Close the file.
| file | file to be closed - IFILE is a pointer to an InputFile object |
Definition at line 429 of file InputFile.h.
References InputFile::ifclose().
Referenced by SamFile::resetFile().
00430 { 00431 int result = file->ifclose(); 00432 delete file; 00433 file = NULL; 00434 return(result); 00435 }
| int ifeof | ( | IFILE | file | ) | [inline] |
Check to see if we have reached the EOF.
| file | file to be checked - IFILE is a pointer to an InputFile object |
Definition at line 468 of file InputFile.h.
References InputFile::ifeof().
Referenced by GlfFile::isEOF(), SamFile::IsEOF(), GlfRefSection::read(), and SamRecord::setBufferFromFile().
00469 { 00470 return(file->ifeof()); 00471 }
| int ifgetc | ( | IFILE | file | ) | [inline] |
Get a character from the file.
Read a character from the internal buffer, or if the end of the buffer has been reached, read from the file into the buffer and return index 0.
| file | file to be read - IFILE is a pointer to an InputFile object |
Definition at line 453 of file InputFile.h.
References InputFile::ifgetc().
00454 { 00455 return(file->ifgetc()); 00456 }
| IFILE ifopen | ( | const char * | filename, | |
| const char * | mode, | |||
| InputFile::ifileCompression | compressionMode = InputFile::DEFAULT | |||
| ) | [inline] |
Open a file.
| filename | file to open | |
| mode | same format as fopen: "r" for read & "w" for write. | |
| compressionMode | set the type of file to open for writing or for reading from stdin (when reading files, the compression type is determined by reading the file). |
Definition at line 411 of file InputFile.h.
References InputFile::isOpen().
Referenced by GlfFile::openForRead(), SamFile::OpenForRead(), GlfFile::openForWrite(), SamFile::OpenForWrite(), and BamIndex::readIndex().
| int ifprintf | ( | IFILE | output, | |
| char * | format, | |||
| ... | ||||
| ) |
Write to a file using fprintf format.
| file | file to write to - IFILE is a pointer to an InputFile object | |
| format | printf format for writing, followed by parameters. |
Definition at line 256 of file InputFile.cpp.
References ifwrite().
00257 { 00258 String buffer; 00259 00260 va_list ap; 00261 va_start(ap, format); 00262 00263 buffer.vprintf(format, ap); 00264 00265 va_end(ap); 00266 00267 return ::ifwrite(output, (const char *) buffer, buffer.Length()); 00268 }
| unsigned int ifread | ( | IFILE | file, | |
| void * | buffer, | |||
| unsigned int | size | |||
| ) | [inline] |
Read size bytes from the file into the buffer.
| file | file to be read - IFILE is a pointer to an InputFile object | |
| buffer | pointer to memory at least size bytes big to write the data into. | |
| size | number of bytes to be read |
Definition at line 443 of file InputFile.h.
References InputFile::ifread().
Referenced by SamFile::OpenForRead(), GlfRefSection::read(), GlfRecord::read(), GlfHeader::read(), BamIndex::readIndex(), and SamRecord::setBufferFromFile().
00444 { 00445 return(file->ifread(buffer, size)); 00446 }
| void ifrewind | ( | IFILE | file | ) | [inline] |
Reset to the beginning of the file.
| file | file to be rewound - IFILE is a pointer to an InputFile object |
Definition at line 460 of file InputFile.h.
References InputFile::ifrewind().
Referenced by SamFile::OpenForRead().
00461 { 00462 file->ifrewind(); 00463 }
| bool ifseek | ( | IFILE | file, | |
| long int | offset, | |||
| int | origin | |||
| ) | [inline] |
Seek to the specified offset from the origin.
| file | file to perform seek on - IFILE is a pointer to an InputFile object | |
| offset | offset into the file to move to (must be from a tell call) | |
| origin | can be any of the following: Note: not all are valid for all filetypes. SEEK_SET - Beginning of file SEEK_CUR - Current position of the file pointer SEEK_END - End of file |
Definition at line 500 of file InputFile.h.
References InputFile::ifseek().
Referenced by SamFile::readIndexedRecord().
00501 { 00502 return (file->ifseek(offset, origin)); 00503 }
| long int iftell | ( | IFILE | file | ) | [inline] |
Get current position in the file.
| file | file to perform tell on - IFILE is a pointer to an InputFile object |
Definition at line 486 of file InputFile.h.
References InputFile::iftell().
Referenced by SamFile::readIndexedRecord().
00487 { 00488 return (file->iftell()); 00489 }
| unsigned int ifwrite | ( | IFILE | file, | |
| const void * | buffer, | |||
| unsigned int | size | |||
| ) | [inline] |
Write the specified buffer into the file.
| file | file to write to - IFILE is a pointer to an InputFile object | |
| buffer | buffer containing size bytes to write to the file. | |
| size | number of bytes to write |
Definition at line 478 of file InputFile.h.
References InputFile::ifwrite().
Referenced by ifprintf(), GlfRefSection::write(), GlfHeader::write(), and SamRecord::writeRecordBuffer().
00479 { 00480 return(file->ifwrite(buffer, size)); 00481 }
Read a line from a file using streaming.
| stream | file to read from - IFILE is a pointer to an InputFile object | |
| str | output string containing the line read from the file. |
Definition at line 514 of file InputFile.h.
References InputFile::ifgetc().
00515 { 00516 str.clear(); 00517 int ch; 00518 // not safe... newline handling? 00519 while ((ch = stream->ifgetc())!=EOF && (ch != '\n')) str.push_back(ch); 00520 return stream; 00521 }
1.6.3