Read file with SGF data. More...
#include <SgGameReader.h>
Public Types | |
enum | WarningFlags { INVALID_BOARDSIZE, PROPERTY_WITHOUT_VALUE, NU_WARNING_FLAGS } |
Warning conditions that occurred during reading. More... | |
typedef std::bitset < NU_WARNING_FLAGS > | Warnings |
Warnings that occurred during reading. | |
Public Member Functions | |
SgGameReader (std::istream &in, int defaultSize=19) | |
Create reader from an input stream. | |
Warnings | GetWarnings () const |
Get warnings of last ReadGame or ReadGames. | |
void | PrintWarnings (std::ostream &out) const |
Print warnings of last ReadGame or ReadGames to stream. | |
SgNode * | ReadGame () |
Read next game tree from file. | |
void | ReadGames (SgVectorOf< SgNode > *rootList) |
Read all game trees from this file. | |
Private Types | |
typedef std::map< std::string, std::vector< std::string > > | RawProperties |
Map label to values (unparsed). | |
Private Member Functions | |
SgGameReader (const SgGameReader &) | |
Not implemented. | |
SgGameReader & | operator= (const SgGameReader &) |
Not implemented. | |
void | HandleProperties (SgNode *node, const RawProperties &properties, int &boardSize, SgPropPointFmt &fmt) |
Create SgProp instances and add them to node. | |
SgNode * | ReadGame (bool resetWarnings) |
std::string | ReadLabel (int c) |
SgNode * | ReadSubtree (SgNode *node, int boardSize, SgPropPointFmt fmt) |
bool | ReadValue (std::string &value) |
Static Private Member Functions | |
static bool | GetIntProp (const RawProperties &properties, const std::string &label, int &value) |
Private Attributes | |
std::istream & | m_in |
const int | m_defaultSize |
int | m_fileFormat |
The file format read in. | |
Warnings | m_warnings |
Read file with SGF data.
Definition at line 26 of file SgGameReader.h.
typedef std::map<std::string, std::vector<std::string> > SgGameReader::RawProperties [private] |
Map label to values (unparsed).
Definition at line 70 of file SgGameReader.h.
typedef std::bitset<NU_WARNING_FLAGS> SgGameReader::Warnings |
Warnings that occurred during reading.
Definition at line 44 of file SgGameReader.h.
Warning conditions that occurred during reading.
INVALID_BOARDSIZE |
Invalid board size. The file contained a size property with a value not in [SG_MIN_SIZE..SG_MAX_SIZE]. |
PROPERTY_WITHOUT_VALUE | |
NU_WARNING_FLAGS |
Number of WarningFlags. |
Definition at line 31 of file SgGameReader.h.
SgGameReader::SgGameReader | ( | std::istream & | in, | |
int | defaultSize = 19 | |||
) |
Create reader from an input stream.
in | The input stream. | |
defaultSize | The (game-dependent) default board size, if file contains no SZ property. no SZ property. |
Definition at line 36 of file SgGameReader.cpp.
SgGameReader::SgGameReader | ( | const SgGameReader & | ) | [private] |
Not implemented.
bool SgGameReader::GetIntProp | ( | const RawProperties & | properties, | |
const std::string & | label, | |||
int & | value | |||
) | [static, private] |
Definition at line 43 of file SgGameReader.cpp.
Referenced by HandleProperties().
SgGameReader::Warnings SgGameReader::GetWarnings | ( | ) | const |
Get warnings of last ReadGame or ReadGames.
Definition at line 102 of file SgGameReader.h.
References m_warnings.
void SgGameReader::HandleProperties | ( | SgNode * | node, | |
const RawProperties & | properties, | |||
int & | boardSize, | |||
SgPropPointFmt & | fmt | |||
) | [private] |
Create SgProp instances and add them to node.
The only properties that are interpreted by the reader are SZ (board size) and GM (point format, because they must be handled before all other root node properties to parse points correctly.
Definition at line 58 of file SgGameReader.cpp.
References SgNode::Add(), SgProp::CreateProperty(), SgProp::FromString(), SgProp::GetIDOfLabel(), GetIntProp(), SgPropUtil::GetPointFmt(), INVALID_BOARDSIZE, m_warnings, PROPERTY_WITHOUT_VALUE, SG_MAX_SIZE, SG_PROP_NONE, and SG_PROP_UNKNOWN.
Referenced by ReadSubtree().
SgGameReader& SgGameReader::operator= | ( | const SgGameReader & | ) | [private] |
Not implemented.
void SgGameReader::PrintWarnings | ( | std::ostream & | out | ) | const |
Print warnings of last ReadGame or ReadGames to stream.
Prints the warnings as human readable text.
Definition at line 91 of file SgGameReader.cpp.
References INVALID_BOARDSIZE, m_warnings, PROPERTY_WITHOUT_VALUE, and SG_ASSERT.
SgNode * SgGameReader::ReadGame | ( | bool | resetWarnings | ) | [private] |
Definition at line 101 of file SgGameReader.cpp.
References m_defaultSize, m_in, m_warnings, ReadSubtree(), SgNode::Root(), and SG_PROPPOINTFMT_GO.
SgNode * SgGameReader::ReadGame | ( | ) |
Read next game tree from file.
Definition at line 107 of file SgGameReader.h.
Referenced by ReadGames().
void SgGameReader::ReadGames | ( | SgVectorOf< SgNode > * | rootList | ) |
Read all game trees from this file.
Return a list with the root of each game tree.
Definition at line 122 of file SgGameReader.cpp.
References SgVector< void * >::Clear(), m_warnings, SgVectorOf< T >::PushBack(), ReadGame(), and SG_ASSERT.
string SgGameReader::ReadLabel | ( | int | c | ) | [private] |
SgNode * SgGameReader::ReadSubtree | ( | SgNode * | node, | |
int | boardSize, | |||
SgPropPointFmt | fmt | |||
) | [private] |
Definition at line 154 of file SgGameReader.cpp.
References HandleProperties(), m_in, SgNode::NewRightMostSon(), ReadLabel(), and ReadValue().
Referenced by ReadGame().
bool SgGameReader::ReadValue | ( | std::string & | value | ) | [private] |
const int SgGameReader::m_defaultSize [private] |
Definition at line 74 of file SgGameReader.h.
Referenced by ReadGame().
int SgGameReader::m_fileFormat [private] |
The file format read in.
Definition at line 77 of file SgGameReader.h.
std::istream& SgGameReader::m_in [private] |
Definition at line 72 of file SgGameReader.h.
Referenced by ReadGame(), ReadLabel(), ReadSubtree(), and ReadValue().
Warnings SgGameReader::m_warnings [private] |
Definition at line 79 of file SgGameReader.h.
Referenced by GetWarnings(), HandleProperties(), PrintWarnings(), ReadGame(), and ReadGames().