OpenStructure
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
 
Real GetRealOrDefault (const StringRef &data, const String &name, Real alt, bool(*is_default)(StringRef)) 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
 
Real GetRealOrDefault (const StringRef &data, const String &name, Real alt, bool(*is_default)(StringRef)) 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 IsUndefined (StringRef value)
 
static bool SplitLine (const StringRef &line, std::vector< StringRef > &parts, bool clear=true)
 
static bool IsUndefined (StringRef value)
 

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 114 of file star_parser.hh.

Constructor & Destructor Documentation

◆ StarParser() [1/4]

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

create a StarParser

Parameters
streaminput stream
items_as_rowif true, data-items are first gathered (identifier as header, values as row) and then parsed like a loop (OnBeginLoop(), OnDataRow(), OnEndLoop())

◆ StarParser() [2/4]

StarParser ( const String filename,
bool  items_as_row = false 
)
explicit

◆ ~StarParser() [1/2]

virtual ~StarParser ( )
inlinevirtual

Definition at line 124 of file star_parser.hh.

◆ StarParser() [3/4]

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

create a StarParser

Parameters
streaminput stream
items_as_rowif true, data-items are first gathered (identifier as header, values as row) and then parsed like a loop (OnBeginLoop(), OnDataRow(), OnEndLoop())

◆ StarParser() [4/4]

StarParser ( const String filename,
bool  items_as_row = false 
)
explicit

◆ ~StarParser() [2/2]

virtual ~StarParser ( )
inlinevirtual

Definition at line 124 of file star_parser.hh.

Member Function Documentation

◆ FormatDiagnostic() [1/2]

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

format diagnostic and returns it as a string.

◆ FormatDiagnostic() [2/2]

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

format diagnostic and returns it as a string.

◆ GetCurrentLinenum() [1/2]

int GetCurrentLinenum ( ) const
inline

retrieve the line, the parser is currently working on

Definition at line 232 of file star_parser.hh.

◆ GetCurrentLinenum() [2/2]

int GetCurrentLinenum ( ) const
inline

retrieve the line, the parser is currently working on

Definition at line 232 of file star_parser.hh.

◆ GetRealOrDefault() [1/2]

Real GetRealOrDefault ( const StringRef data,
const String name,
Real  alt,
bool(*)(StringRef is_default 
) const

try to convert a value to Real, on failure return default value.

Parameters
datavalue to be converted
nameto be included in the message
altvalue
is_defaulta function to check if data is a default value.
Returns
converted or alt value

◆ GetRealOrDefault() [2/2]

Real GetRealOrDefault ( const StringRef data,
const String name,
Real  alt,
bool(*)(StringRef is_default 
) const

try to convert a value to Real, on failure return default value.

Parameters
datavalue to be converted
nameto be included in the message
altvalue
is_defaulta function to check if data is a default value.
Returns
converted or alt value

◆ IsUndefined() [1/2]

static bool IsUndefined ( StringRef  value)
inlinestatic

Definition at line 242 of file star_parser.hh.

◆ IsUndefined() [2/2]

static bool IsUndefined ( StringRef  value)
inlinestatic

Definition at line 242 of file star_parser.hh.

◆ OnBeginData() [1/2]

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

Definition at line 149 of file star_parser.hh.

◆ OnBeginData() [2/2]

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

Definition at line 149 of file star_parser.hh.

◆ OnBeginLoop() [1/2]

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

Definition at line 131 of file star_parser.hh.

◆ OnBeginLoop() [2/2]

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

Definition at line 131 of file star_parser.hh.

◆ OnDataItem() [1/2]

virtual void OnDataItem ( const StarDataItem item)
inlinevirtual

invoked when a data item is encountered

Reimplemented in ChemdictParser, and ChemdictParser.

Definition at line 144 of file star_parser.hh.

◆ OnDataItem() [2/2]

virtual void OnDataItem ( const StarDataItem item)
inlinevirtual

invoked when a data item is encountered

Reimplemented in ChemdictParser, and ChemdictParser.

Definition at line 144 of file star_parser.hh.

◆ OnDataRow() [1/2]

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

Definition at line 139 of file star_parser.hh.

◆ OnDataRow() [2/2]

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

Definition at line 139 of file star_parser.hh.

◆ OnEndData() [1/2]

virtual void OnEndData ( )
inlinevirtual

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

Reimplemented in MMCifReader, ChemdictParser, MMCifReader, and ChemdictParser.

Definition at line 153 of file star_parser.hh.

◆ OnEndData() [2/2]

virtual void OnEndData ( )
inlinevirtual

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

Reimplemented in MMCifReader, ChemdictParser, MMCifReader, and ChemdictParser.

Definition at line 153 of file star_parser.hh.

◆ OnEndLoop() [1/2]

virtual void OnEndLoop ( )
inlinevirtual

invoked when leaving a loop

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

Definition at line 135 of file star_parser.hh.

◆ OnEndLoop() [2/2]

virtual void OnEndLoop ( )
inlinevirtual

invoked when leaving a loop

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

Definition at line 135 of file star_parser.hh.

◆ Parse() [1/2]

void Parse ( )

◆ Parse() [2/2]

void Parse ( )

◆ SetFilename() [1/2]

void SetFilename ( const String filename)
inline

Definition at line 226 of file star_parser.hh.

◆ SetFilename() [2/2]

void SetFilename ( const String filename)
inline

Definition at line 226 of file star_parser.hh.

◆ SplitLine() [1/2]

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

◆ SplitLine() [2/2]

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

◆ TryGetBool() [1/2]

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

◆ TryGetBool() [2/2]

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

◆ TryGetFloat() [1/4]

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

◆ TryGetFloat() [2/4]

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

◆ TryGetFloat() [3/4]

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

◆ TryGetFloat() [4/4]

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

◆ TryGetInt() [1/4]

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

◆ TryGetInt() [2/4]

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

◆ TryGetInt() [3/4]

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

◆ TryGetInt() [4/4]

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

◆ TryGetReal() [1/2]

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

◆ TryGetReal() [2/2]

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 file: