InputFile.h File Reference

#include <stdio.h>
#include <iostream>
#include <cstring>
#include "FileType.h"
Include dependency graph for InputFile.h:
This graph shows which files directly or indirectly include this file:

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 InputFileIFILE
 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.

Detailed Description

Definition in file InputFile.h.


Function Documentation

int ifclose ( IFILE  file  )  [inline]

Close the file.

Parameters:
file file to be closed - IFILE is a pointer to an InputFile object
Returns:
status of the close (0 is success).

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.

Parameters:
file file to be checked - IFILE is a pointer to an InputFile object
Returns:
0 if not EOF, any other value means EOF.

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.

Parameters:
file file to be read - IFILE is a pointer to an InputFile object
Returns:
character that was read or EOF.

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.

Parameters:
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).
Returns:
IFILE - pointer to the InputFile object that has been opened.

Definition at line 411 of file InputFile.h.

References InputFile::isOpen().

Referenced by GlfFile::openForRead(), SamFile::OpenForRead(), GlfFile::openForWrite(), SamFile::OpenForWrite(), and BamIndex::readIndex().

00413 {
00414     IFILE file = new InputFile(filename, mode, compressionMode);
00415     if (!file->isOpen())
00416     {
00417 
00418         // Not open, so delete the file, and return null.
00419         delete file;
00420         file = NULL;
00421     }
00422     return file;
00423 }

int ifprintf ( IFILE  output,
char *  format,
  ... 
)

Write to a file using fprintf format.

Parameters:
file file to write to - IFILE is a pointer to an InputFile object
format printf format for writing, followed by parameters.
Returns:
number of bytes written

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.

Parameters:
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
Returns:
number of bytes 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.

Parameters:
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.

Parameters:
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
Returns:
true on successful seek and false on a failed seek.

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.

Parameters:
file file to perform tell on - IFILE is a pointer to an InputFile object
Returns:
current position in the file, -1 indicates an error.

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.

Parameters:
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
Returns:
number of bytes written

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 }

IFILE operator>> ( IFILE  stream,
std::string &  str 
) [inline]

Read a line from a file using streaming.

Parameters:
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 }

Generated on Tue Mar 22 22:50:19 2011 for StatGen Software by  doxygen 1.6.3