#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdint.h>
#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. | |
int64_t | iftell (IFILE file) |
Get current position in the file. | |
bool | ifseek (IFILE file, int64_t offset, int origin) |
Seek to the specified offset from the origin. | |
int | ifprintf (IFILE output, const 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 511 of file InputFile.h.
References InputFile::ifclose().
Referenced by SamFile::resetFile().
00512 { 00513 if(file == NULL) 00514 { 00515 // NULL Pointer passed in, so return 0, since no file is open, so 00516 // does not need to be closed. 00517 return(0); 00518 } 00519 int result = file->ifclose(); 00520 delete file; 00521 file = NULL; 00522 return(result); 00523 }
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 570 of file InputFile.h.
References InputFile::ifeof().
Referenced by GlfFile::isEOF(), SamFile::IsEOF(), GlfRefSection::read(), and SamRecord::setBufferFromFile().
00571 { 00572 if(file == NULL) 00573 { 00574 // No file, so that is considered to be EOF, so return 1. 00575 return(1); 00576 } 00577 return(file->ifeof()); 00578 }
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 546 of file InputFile.h.
References InputFile::ifgetc().
00547 { 00548 if(file == NULL) 00549 { 00550 // return eof since there is no file. 00551 return(EOF); 00552 } 00553 return(file->ifgetc()); 00554 }
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 493 of file InputFile.h.
References InputFile::isOpen().
Referenced by GlfFile::openForRead(), SamFile::OpenForRead(), GlfFile::openForWrite(), SamFile::OpenForWrite(), and BamIndex::readIndex().
int ifprintf | ( | IFILE | output, | |
const 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 282 of file InputFile.cpp.
References ifwrite().
00283 { 00284 String buffer; 00285 00286 va_list ap; 00287 va_start(ap, format); 00288 00289 buffer.vprintf(format, ap); 00290 00291 va_end(ap); 00292 00293 return ::ifwrite(output, (const char *) buffer, buffer.Length()); 00294 }
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 531 of file InputFile.h.
References InputFile::ifread().
Referenced by SamFile::OpenForRead(), GlfRefSection::read(), GlfRecord::read(), GlfHeader::read(), BamIndex::readIndex(), and SamRecord::setBufferFromFile().
00532 { 00533 if(file == NULL) 00534 { 00535 // No file was passed in, so 0 bytes were read. 00536 return(0); 00537 } 00538 return(file->ifread(buffer, size)); 00539 }
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 558 of file InputFile.h.
References InputFile::ifrewind().
Referenced by SamFile::OpenForRead().
00559 { 00560 if(file == NULL) 00561 { 00562 return; 00563 } 00564 file->ifrewind(); 00565 }
bool ifseek | ( | IFILE | file, | |
int64_t | 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 616 of file InputFile.h.
References InputFile::ifseek().
Referenced by SamFile::readIndexedRecord().
00617 { 00618 if(file == NULL) 00619 { 00620 // Could not see since no file was specified. 00621 return(false); 00622 } 00623 return (file->ifseek(offset, origin)); 00624 }
int64_t 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 598 of file InputFile.h.
References InputFile::iftell().
Referenced by SamFile::GetCurrentPosition(), and SamFile::readIndexedRecord().
00599 { 00600 if(file == NULL) 00601 { 00602 return(-1); 00603 } 00604 return (file->iftell()); 00605 }
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 585 of file InputFile.h.
References InputFile::ifwrite().
Referenced by ifprintf(), GlfRefSection::write(), GlfHeader::write(), and SamRecord::writeRecordBuffer().
00586 { 00587 if(file == NULL) 00588 { 00589 // No file specified, so retun 0 bytes written. 00590 return(0); 00591 } 00592 return(file->ifwrite(buffer, size)); 00593 }
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 635 of file InputFile.h.
References InputFile::ifgetc().
00636 { 00637 str.clear(); 00638 int ch; 00639 // not safe... newline handling? 00640 while ((ch = stream->ifgetc())!=EOF && (ch != '\n')) str.push_back(ch); 00641 return stream; 00642 }