StarParser Class Reference

parser for the STAR file format More...

#include <star_parser.hh>

Inherited by ChemdictParser, ChemdictParser, MMCifReader, and MMCifReader.

Public Member Functions

 StarParser (std::istream &stream, bool items_as_row=false)
 StarParser (const String &filename, bool items_as_row=false)
virtual ~StarParser ()
virtual bool OnBeginLoop (const StarLoopDesc &header)
virtual void OnEndLoop ()
virtual void OnDataRow (const StarLoopDesc &header, const std::vector< StringRef > &columns)
virtual void OnDataItem (const StarDataItem &item)
virtual bool OnBeginData (const StringRef &data_name)
virtual void OnEndData ()
Real TryGetReal (const StringRef &data, const String &name) const
float TryGetFloat (const StringRef &data, const String &name) const
std::pair< bool, float > TryGetFloat (const StringRef &data, const String &name, bool may_fail) const
int TryGetInt (const StringRef &data, const String &name) const
std::pair< bool, int > TryGetInt (const StringRef &data, const String &name, bool may_fail) const
bool TryGetBool (const StringRef &data, const String &name) const
String FormatDiagnostic (StarDiagType type, const String &message, int line=-1) const
void SetFilename (const String &filename)
int GetCurrentLinenum () const
void Parse ()
 StarParser (std::istream &stream, bool items_as_row=false)
 StarParser (const String &filename, bool items_as_row=false)
virtual ~StarParser ()
virtual bool OnBeginLoop (const StarLoopDesc &header)
virtual void OnEndLoop ()
virtual void OnDataRow (const StarLoopDesc &header, const std::vector< StringRef > &columns)
virtual void OnDataItem (const StarDataItem &item)
virtual bool OnBeginData (const StringRef &data_name)
virtual void OnEndData ()
Real TryGetReal (const StringRef &data, const String &name) const
float TryGetFloat (const StringRef &data, const String &name) const
std::pair< bool, float > TryGetFloat (const StringRef &data, const String &name, bool may_fail) const
int TryGetInt (const StringRef &data, const String &name) const
std::pair< bool, int > TryGetInt (const StringRef &data, const String &name, bool may_fail) const
bool TryGetBool (const StringRef &data, const String &name) const
String FormatDiagnostic (StarDiagType type, const String &message, int line=-1) const
void SetFilename (const String &filename)
int GetCurrentLinenum () const
void Parse ()

Static Public Member Functions

static bool SplitLine (const StringRef &line, std::vector< StringRef > &parts, bool clear=true)
static bool SplitLine (const StringRef &line, std::vector< StringRef > &parts, bool clear=true)

Detailed Description

parser for the STAR file format

STAR format description

In essence, STAR files are structured text files. A few simple control structures control the interpretation of the content.

Definition at line 112 of file star_parser.hh.


Constructor & Destructor Documentation

StarParser ( std::istream &  stream,
bool  items_as_row = false 
) [explicit]

create a StarParser

Parameters:
stream input stream
items_as_row if true, data-items are first gathered (identifier as header, values as row) and then parsed like a loop (OnBeginLoop(), OnDataRow(), OnEndLoop())
StarParser ( const String filename,
bool  items_as_row = false 
) [explicit]
virtual ~StarParser (  )  [inline, virtual]

Definition at line 122 of file star_parser.hh.

StarParser ( std::istream &  stream,
bool  items_as_row = false 
) [explicit]

create a StarParser

Parameters:
stream input stream
items_as_row if true, data-items are first gathered (identifier as header, values as row) and then parsed like a loop (OnBeginLoop(), OnDataRow(), OnEndLoop())
StarParser ( const String filename,
bool  items_as_row = false 
) [explicit]
virtual ~StarParser (  )  [inline, virtual]

Definition at line 122 of file star_parser.hh.


Member Function Documentation

String FormatDiagnostic ( StarDiagType  type,
const String message,
int  line = -1 
) const

format diagnostic and returns it as a string.

String FormatDiagnostic ( StarDiagType  type,
const String message,
int  line = -1 
) const

format diagnostic and returns it as a string.

int GetCurrentLinenum (  )  const [inline]

retrieve the line, the parser is currently working on

Definition at line 217 of file star_parser.hh.

int GetCurrentLinenum (  )  const [inline]

retrieve the line, the parser is currently working on

Definition at line 217 of file star_parser.hh.

virtual bool OnBeginData ( const StringRef data_name  )  [inline, virtual]

invoked when a new data control structure is encountered

Returns:
When true, for each data-item belonging to the data block, OnDataItem() is invoked. For every loop, OnBeginLoop() is called.

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 147 of file star_parser.hh.

virtual bool OnBeginData ( const StringRef data_name  )  [inline, virtual]

invoked when a new data control structure is encountered

Returns:
When true, for each data-item belonging to the data block, OnDataItem() is invoked. For every loop, OnBeginLoop() is called.

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 147 of file star_parser.hh.

virtual bool OnBeginLoop ( const StarLoopDesc header  )  [inline, virtual]

called when a loop is encountered

Returns:
When true, for each row in the loop, OnDataRow() is returned. If false, the loop is skipped.

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 129 of file star_parser.hh.

virtual bool OnBeginLoop ( const StarLoopDesc header  )  [inline, virtual]

called when a loop is encountered

Returns:
When true, for each row in the loop, OnDataRow() is returned. If false, the loop is skipped.

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 129 of file star_parser.hh.

virtual void OnDataItem ( const StarDataItem item  )  [inline, virtual]

invoked when a data item is encountered

Reimplemented in ChemdictParser, and ChemdictParser.

Definition at line 142 of file star_parser.hh.

virtual void OnDataItem ( const StarDataItem item  )  [inline, virtual]

invoked when a data item is encountered

Reimplemented in ChemdictParser, and ChemdictParser.

Definition at line 142 of file star_parser.hh.

virtual void OnDataRow ( const StarLoopDesc header,
const std::vector< StringRef > &  columns 
) [inline, virtual]

invoked when a data row in a loop is encountered.

Parameters:
header describes the row format
columns contains the data columns

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 137 of file star_parser.hh.

virtual void OnDataRow ( const StarLoopDesc header,
const std::vector< StringRef > &  columns 
) [inline, virtual]

invoked when a data row in a loop is encountered.

Parameters:
header describes the row format
columns contains the data columns

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 137 of file star_parser.hh.

virtual void OnEndData (  )  [inline, virtual]

called when leaving a datasection. Will only be invoked when OnBeginData() returned true.

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 151 of file star_parser.hh.

virtual void OnEndData (  )  [inline, virtual]

called when leaving a datasection. Will only be invoked when OnBeginData() returned true.

Reimplemented in ChemdictParser, MMCifReader, ChemdictParser, and MMCifReader.

Definition at line 151 of file star_parser.hh.

virtual void OnEndLoop (  )  [inline, virtual]

invoked when leaving a loop

OnEndLoop() is only invoked, when OnBeginLoop() returned true.

Definition at line 133 of file star_parser.hh.

virtual void OnEndLoop (  )  [inline, virtual]

invoked when leaving a loop

OnEndLoop() is only invoked, when OnBeginLoop() returned true.

Definition at line 133 of file star_parser.hh.

void Parse (  ) 
void Parse (  ) 
void SetFilename ( const String filename  )  [inline]

Definition at line 211 of file star_parser.hh.

void SetFilename ( const String filename  )  [inline]

Definition at line 211 of file star_parser.hh.

static bool SplitLine ( const StringRef line,
std::vector< StringRef > &  parts,
bool  clear = true 
) [static]
static bool SplitLine ( const StringRef line,
std::vector< StringRef > &  parts,
bool  clear = true 
) [static]
bool TryGetBool ( const StringRef data,
const String name 
) const

try to convert a value to bool, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
bool TryGetBool ( const StringRef data,
const String name 
) const

try to convert a value to bool, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
std::pair<bool, float> TryGetFloat ( const StringRef data,
const String name,
bool  may_fail 
) const

try to convert a value to float, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
may_fail decides if an exception is raised (false) or not (true)
Returns:
converted value
float TryGetFloat ( const StringRef data,
const String name 
) const

try to convert a value to float, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
std::pair<bool, float> TryGetFloat ( const StringRef data,
const String name,
bool  may_fail 
) const

try to convert a value to float, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
may_fail decides if an exception is raised (false) or not (true)
Returns:
converted value
float TryGetFloat ( const StringRef data,
const String name 
) const

try to convert a value to float, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
std::pair<bool, int> TryGetInt ( const StringRef data,
const String name,
bool  may_fail 
) const

try to convert a value to integer, exception can be turned off.

Parameters:
data value to be converted
name to be included in the message
may_fail decides if an exception is raised (false) or not (true)
Returns:
pair with value and indicator if conversion worked
int TryGetInt ( const StringRef data,
const String name 
) const

try to convert a value to integer, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
std::pair<bool, int> TryGetInt ( const StringRef data,
const String name,
bool  may_fail 
) const

try to convert a value to integer, exception can be turned off.

Parameters:
data value to be converted
name to be included in the message
may_fail decides if an exception is raised (false) or not (true)
Returns:
pair with value and indicator if conversion worked
int TryGetInt ( const StringRef data,
const String name 
) const

try to convert a value to integer, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
Real TryGetReal ( const StringRef data,
const String name 
) const

try to convert a value to Real, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value
Real TryGetReal ( const StringRef data,
const String name 
) const

try to convert a value to Real, on failure raise an exception.

Parameters:
data value to be converted
name to be included in the message
Returns:
converted value

The documentation for this class was generated from the following files:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 20 Jun 2016 for OpenStructure by  doxygen 1.6.1