Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes

SgGameReader Class Reference

Read file with SGF data. More...

#include <SgGameReader.h>

List of all members.

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

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 26 of file SgGameReader.h.


Member Typedef Documentation

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.


Member Enumeration Documentation

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 31 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 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]
SgNode * SgGameReader::ReadGame (  ) 

Read next game tree from file.

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

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]

Definition at line 137 of file SgGameReader.cpp.

References m_in.

Referenced by ReadSubtree().

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]

Definition at line 191 of file SgGameReader.cpp.

References m_in.

Referenced by ReadSubtree().


Member Data Documentation

const int SgGameReader::m_defaultSize [private]

Definition at line 74 of file SgGameReader.h.

Referenced by ReadGame().

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

Definition at line 79 of file SgGameReader.h.

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


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


Sun Mar 13 2011 Doxygen 1.7.1