00001 //---------------------------------------------------------------------------- 00002 /** @file SgGameWriter.h */ 00003 //---------------------------------------------------------------------------- 00004 00005 #ifndef SG_GAMEWRITER_H 00006 #define SG_GAMEWRITER_H 00007 00008 #include <iosfwd> 00009 #include "SgProp.h" 00010 00011 class SgNode; 00012 00013 //---------------------------------------------------------------------------- 00014 00015 /** Write file with SGF data */ 00016 class SgGameWriter 00017 { 00018 public: 00019 SgGameWriter(std::ostream& out); 00020 00021 /** Write the game tree at 'root' to the given archive. 00022 Add file format and application properties to the root node. 00023 @param root Root node of the game. 00024 @param allProps Write all properties. 00025 @param fileFormat if zero, write it out with the default file format. 00026 @param application Application name (will add AP property if not 00027 empty) 00028 @param gameNumber Game number (will add GM property) 00029 @param defaultSize The (game-dependent) default board size, if file 00030 contains no SZ property. 00031 @throws SgException If saving fails (presently it does only check if 00032 the file is ok at the beginning, not if all writes succeed) 00033 */ 00034 void WriteGame(SgNode& root, bool allProps, int fileFormat, 00035 const std::string& application, int gameNumber, 00036 int defaultSize); 00037 00038 private: 00039 std::ostream& m_out; 00040 00041 int m_fileFormat; 00042 00043 /** Number of properties on this line. */ 00044 int m_numPropsOnLine; 00045 00046 void ConvertFormat(SgNode& root); 00047 00048 void HandleProps(const SgNode* node, int& boardSize) const; 00049 00050 /** Should property be written to file? May depend on options. */ 00051 bool ShouldWriteProperty(const SgProp& prop); 00052 00053 void StartNewLine(); 00054 00055 void WriteNode(const SgNode& node, bool allProps, int boardSize, 00056 SgPropPointFmt fmt); 00057 00058 void WriteSubtree(const SgNode& node, bool allProps, int boardSize, 00059 SgPropPointFmt fmt); 00060 00061 /** Not implemented. */ 00062 SgGameWriter(const SgGameWriter&); 00063 00064 /** Not implemented. */ 00065 SgGameWriter& operator=(const SgGameWriter&); 00066 }; 00067 00068 //---------------------------------------------------------------------------- 00069 00070 #endif // SG_GAMEWRITER_H