Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgGameReader Class Reference

#include <SgGameReader.h>

List of all members.


Detailed Description

Read file with SGF data.

Bug:
Properties are read sequentially, therefore GM and SZ properties have to be before any point value properties, because they are required to parse the point values. According to the SGF standard, the order or properties is arbitrary and there exist SGF files, which have the GM and SZ property after point properties (like AB, AW) in the root node. To fix this, all properties of a node would have to be read and GM and SZ handled first before parsing any other property values.

Definition at line 27 of file SgGameReader.h.

Public Types

typedef std::bitset< NU_WARNING_FLAGS > Warnings
 Warnings that occurred during reading.
 INVALID_BOARDSIZE
 Invalid board size.
 PROPERTY_WITHOUT_VALUE
 NU_WARNING_FLAGS
 Number of WarningFlags.
enum  WarningFlags { INVALID_BOARDSIZE, PROPERTY_WITHOUT_VALUE, NU_WARNING_FLAGS }
 Warning conditions that occurred during reading. More...

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.
SgNodeReadGame ()
 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.
SgGameReaderoperator= (const SgGameReader &)
 Not implemented.
void HandleProperties (SgNode *node, const RawProperties &properties, int &boardSize, SgPropPointFmt &fmt)
 Create SgProp instances and add them to node.
SgNodeReadGame (bool resetWarnings)
std::string ReadLabel (int c)
SgNodeReadSubtree (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


Member Typedef Documentation

typedef std::map<std::string, std::vector<std::string> > SgGameReader::RawProperties [private]

Map label to values (unparsed).

Definition at line 77 of file SgGameReader.h.

typedef std::bitset<NU_WARNING_FLAGS> SgGameReader::Warnings

Warnings that occurred during reading.

Definition at line 47 of file SgGameReader.h.


Member Enumeration Documentation

enum SgGameReader::WarningFlags

Warning conditions that occurred during reading.

Todo:
Some of these warnings should be errors.
Enumerator:
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 33 of file SgGameReader.h.


Constructor & Destructor Documentation

SgGameReader::SgGameReader ( std::istream &  in,
int  defaultSize = 19 
)

Create reader from an input stream.

Parameters:
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.


Member Function Documentation

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 109 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 59 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 92 of file SgGameReader.cpp.

References INVALID_BOARDSIZE, m_warnings, PrintWarning(), PROPERTY_WITHOUT_VALUE, and SG_ASSERT.

SgNode * SgGameReader::ReadGame ( bool  resetWarnings  )  [private]

Definition at line 102 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.

Returns:
Root node or 0 if there is no next game.

Definition at line 114 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 123 of file SgGameReader.cpp.

References SgVector< void * >::Clear(), m_warnings, SgVectorOf< T >::PushBack(), ReadGame(), and SG_ASSERT.

string SgGameReader::ReadLabel ( int  c  )  [private]

Definition at line 138 of file SgGameReader.cpp.

References m_in.

Referenced by ReadSubtree().

SgNode * SgGameReader::ReadSubtree ( SgNode node,
int  boardSize,
SgPropPointFmt  fmt 
) [private]

Definition at line 155 of file SgGameReader.cpp.

References HandleProperties(), m_in, ReadLabel(), and ReadValue().

Referenced by ReadGame().

bool SgGameReader::ReadValue ( std::string &  value  )  [private]

Definition at line 192 of file SgGameReader.cpp.

References m_in.

Referenced by ReadSubtree().


Member Data Documentation

const int SgGameReader::m_defaultSize [private]

Definition at line 81 of file SgGameReader.h.

Referenced by ReadGame().

int SgGameReader::m_fileFormat [private]

The file format read in.

Definition at line 84 of file SgGameReader.h.

std::istream& SgGameReader::m_in [private]

Definition at line 79 of file SgGameReader.h.

Referenced by ReadGame(), ReadLabel(), ReadSubtree(), and ReadValue().

Warnings SgGameReader::m_warnings [private]

Definition at line 86 of file SgGameReader.h.

Referenced by GetWarnings(), HandleProperties(), PrintWarnings(), ReadGame(), and ReadGames().


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


17 Jun 2010 Doxygen 1.4.7