multovl  1.3
Multiple overlaps of genomic regions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
multovl::io::Linereader Class Referenceabstract

Base class of parser objects. Linereader objects process one line at a time, and change their internal state according to what they find in it. Parsing a complete data file involves reading it in line-by-line and submitting each line to a parser object for the appropriate format. Upon successful parsing the parser object stores the coordinate information plus additional data that can be read out and used to construct the appropriate region object. More...

#include "linereader.hh"

Inheritance diagram for multovl::io::Linereader:
multovl::io::BedLinereader multovl::io::GffLinereader

Classes

class  Exception
 Linereader's own exception. More...
 

Public Types

enum  Status {
  CLEAN = 0, ERROR = 1, EMPTY = 2, COMMENT = 4,
  DATA = 8
}
 Symbolic constants to signify the result of a parsing operation. More...
 

Public Member Functions

 Linereader (const std::string &commentchars="#")
 
Status parse (const std::string &line)
 
virtual bool read_into (Region &region) const =0
 
Status status () const
 
const std::string & comment () const
 
size_t fieldcnt () const
 
const std::string & error_msg () const
 
const std::string & chrom () const
 
unsigned int first () const
 
unsigned int last () const
 
char strand () const
 
const std::string & name () const
 

Protected Member Functions

virtual void reset ()
 
void set_statusflag (Status flag)
 
virtual void parse_data (const std::string &line)=0
 

Static Protected Member Functions

static bool empty_white (const std::string &str)
 Returns /true/ if /str/ is empty or contains whitespace characters only.
 
static unsigned int str_to_uint (std::string &str) throw (Exception)
 

Protected Attributes

Status _status
 the status after parsing
 
size_t _fieldcnt
 how many column fields have been seen
 
std::string _comment
 store a comment line
 
std::string _err
 stores parsing error messages
 
std::string _chrom
 
std::string _name
 
unsigned int _first
 
unsigned int _last
 
char _strand
 

Detailed Description

Base class of parser objects. Linereader objects process one line at a time, and change their internal state according to what they find in it. Parsing a complete data file involves reading it in line-by-line and submitting each line to a parser object for the appropriate format. Upon successful parsing the parser object stores the coordinate information plus additional data that can be read out and used to construct the appropriate region object.

Member Enumeration Documentation

Symbolic constants to signify the result of a parsing operation.

Enumerator
CLEAN 

state after reset (all bits off)

ERROR 

could not parse line

EMPTY 

empty line (whitespace only) was seen

COMMENT 

comment line was seen

DATA 

data line parsed successfully

Constructor & Destructor Documentation

multovl::io::Linereader::Linereader ( const std::string &  commentchars = "#")
explicit

Sets up a Linereader object.

Parameters
commentcharsthe character(s) that signify the beginning of a comment

Member Function Documentation

const std::string& multovl::io::Linereader::comment ( ) const
inline
Returns
a comment line stripped of all leading whitespace and comment characters or the empty std::string if the parsed line was not a comment
const std::string& multovl::io::Linereader::error_msg ( ) const
inline
Returns
contains parse error messages, empty std::string if the status is not ERROR.
size_t multovl::io::Linereader::fieldcnt ( ) const
inline
Returns
the number of fields seen in the parsed line. Makes sense only if the return status is DATA.
Status multovl::io::Linereader::parse ( const std::string &  line)

Parses a line into the calling object from /line/.

Returns
the status of the parsing operation.
virtual void multovl::io::Linereader::parse_data ( const std::string &  line)
protectedpure virtual

Parse a /line/ assuming it contains coordinate data. Implementations must set _status bits (ERROR and DATA) accordingly.

Implemented in multovl::io::GffLinereader, and multovl::io::BedLinereader.

virtual bool multovl::io::Linereader::read_into ( Region region) const
pure virtual

Updates the contents of a region with what has been parsed. Does nothing if the calling object is not in the DATA state.

Implemented in multovl::io::BedLinereader.

virtual void multovl::io::Linereader::reset ( )
protectedvirtual

Prepares the calling object for parsing by resetting all fields. This method must be invoked by the parse(...) method.

Reimplemented in multovl::io::BedLinereader.

void multovl::io::Linereader::set_statusflag ( Status  flag)
inlineprotected

Sets the given status flag by bitwise OR-ing it with the _status field.

Parameters
flagone or more of the Status enum-s, OR-ed together
Status multovl::io::Linereader::status ( ) const
inline
Returns
the status after the last parsing operation.
static unsigned int multovl::io::Linereader::str_to_uint ( std::string &  str)
throw (Exception
)
staticprotected

Converts /str/ to an unsigned int generates meaningful error messages via Linereader::Exception


The documentation for this class was generated from the following file: