OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions
StarParser Class Reference

#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:
streaminput stream
item_as_rowif 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 ( )
inlinevirtual

Definition at line 122 of file star_parser.hh.

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

create a StarParser

Parameters:
streaminput stream
item_as_rowif 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 ( )
inlinevirtual

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)
inlinevirtual

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 MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 147 of file star_parser.hh.

virtual bool OnBeginData ( const StringRef data_name)
inlinevirtual

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 MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 147 of file star_parser.hh.

virtual bool OnBeginLoop ( const StarLoopDesc header)
inlinevirtual

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 MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 129 of file star_parser.hh.

virtual bool OnBeginLoop ( const StarLoopDesc header)
inlinevirtual

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 MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 129 of file star_parser.hh.

virtual void OnDataItem ( const StarDataItem item)
inlinevirtual

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)
inlinevirtual

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 
)
inlinevirtual

invoked when a data row in a loop is encountered.

Parameters:
headerdescribes the row format
columnscontains the data columns

Reimplemented in MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 137 of file star_parser.hh.

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

invoked when a data row in a loop is encountered.

Parameters:
headerdescribes the row format
columnscontains the data columns

Reimplemented in MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 137 of file star_parser.hh.

virtual void OnEndData ( )
inlinevirtual

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

Reimplemented in MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 151 of file star_parser.hh.

virtual void OnEndData ( )
inlinevirtual

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

Reimplemented in MMCifReader, MMCifReader, ChemdictParser, and ChemdictParser.

Definition at line 151 of file star_parser.hh.

virtual void OnEndLoop ( )
inlinevirtual

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 ( )
inlinevirtual

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:
datavalue to be converted
nameto 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:
datavalue to be converted
nameto be included in the message
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:
datavalue to be converted
nameto be included in the message
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:
datavalue to be converted
nameto 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:
datavalue to be converted
nameto be included in the message
may_faildecides if an exception is raised (false) or not (true)
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:
datavalue to be converted
nameto be included in the message
may_faildecides if an exception is raised (false) or not (true)
Returns:
converted value
int TryGetInt ( const StringRef data,
const String name 
) const

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

Parameters:
datavalue to be converted
nameto be included in the message
Returns:
converted value
int TryGetInt ( const StringRef data,
const String name 
) const

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

Parameters:
datavalue to be converted
nameto 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:
datavalue to be converted
nameto be included in the message
may_faildecides if an exception is raised (false) or not (true)
Returns:
pair with value and indicator if conversion worked
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:
datavalue to be converted
nameto be included in the message
may_faildecides if an exception is raised (false) or not (true)
Returns:
pair with value and indicator if conversion worked
Real TryGetReal ( const StringRef data,
const String name 
) const

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

Parameters:
datavalue to be converted
nameto 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:
datavalue to be converted
nameto be included in the message
Returns:
converted value

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