Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgProp.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgProp.h
00003     Properties for nodes in a game tree.
00004 
00005     Module SgProp defines properties that are stored in each node of a game
00006     tree. Most properties correspond to items written in the SGF file format,
00007     but there are other properties that are hidden and only used by the
00008     system.
00009 */
00010 //----------------------------------------------------------------------------
00011 
00012 #ifndef SG_PROP_H
00013 #define SG_PROP_H
00014 
00015 #include <string>
00016 #include <vector>
00017 #include "SgBlackWhite.h"
00018 #include "SgPoint.h"
00019 #include "SgVector.h"
00020 
00021 class SgProp;
00022 
00023 //----------------------------------------------------------------------------
00024 
00025 /** The ID associated with this property */
00026 typedef int SgPropID;
00027 
00028 /** The flags describing this property */
00029 typedef int SgPropFlags;
00030 
00031 //----------------------------------------------------------------------------
00032 
00033 /** Game dependent format for point values of SGF properties. */
00034 enum SgPropPointFmt {
00035     /** Point format used in Go.
00036         Points are written as two letters. 'aa' is top left corner.
00037     */
00038     SG_PROPPOINTFMT_GO,
00039 
00040     /** Point format used in Hex and Reversi.
00041         Points are written as letter/number. 'a1' is top left corner.
00042         Both letters 'i' and 'j' are used ('i' is not skipped as in standard
00043         Go coordinates)
00044     */
00045     SG_PROPPOINTFMT_HEX
00046 };
00047 
00048 //----------------------------------------------------------------------------
00049 
00050 namespace SgPropUtil
00051 {
00052     std::string EscapeSpecialCharacters(const std::string& s,
00053                                         bool escapeColon);
00054 
00055     /** Return point format for a given game.
00056         Returns SG_PROPPOINTFMT_GO for unknown game numbers.
00057     */
00058     SgPropPointFmt GetPointFmt(int gameNumber);
00059 
00060     /** Convert point to SGF point string. */
00061     std::string PointToSgfString(SgMove p, int boardSize,
00062                                  SgPropPointFmt fmt, int fileFormat = 4);
00063 
00064     /** Convert SGF point string to point.
00065         @return The point or SG_PASS (only allowed if point format is
00066         SG_PROPPOINTFMT_GO) or SG_NULLMOVE, if s is not a valid point.
00067      */
00068     SgPoint SgfStringToPoint(const std::string& s, int boardSize,
00069                              SgPropPointFmt fmt);
00070 }
00071 
00072 //----------------------------------------------------------------------------
00073 
00074 /** Maximum number of property classes defined */
00075 const int SG_MAX_PROPCLASS = 150;
00076 
00077 /** Contains information related to Black player */
00078 const int SG_PROPCLASS_BLACK = 1 << 0;
00079 
00080 /** Contains information related to White player */
00081 const int SG_PROPCLASS_WHITE = 1 << 1;
00082 
00083 /** Game info */
00084 const int SG_PROPCLASS_INFO = 1 << 2;
00085 
00086 /** Annotation */
00087 const int SG_PROPCLASS_ANNO = 1 << 3;
00088 
00089 /** Statistics generated by the program */
00090 const int SG_PROPCLASS_STAT = 1 << 4;
00091 
00092 /** Property can only be stored in root */
00093 const int SG_PROPCLASS_ROOT = 1 << 5;
00094 
00095 /** Move annotation */
00096 const int SG_PROPCLASS_ANNO_MOVE = 1 << 6;
00097 
00098 /** Position annotation */
00099 const int SG_PROPCLASS_ANNO_POS = 1 << 7;
00100 
00101 /** Black or white move */
00102 const int SG_PROPCLASS_MOVE = 1 << 8;
00103 
00104 /** Marks on board points */
00105 const int SG_PROPCLASS_MARK = 1 << 9;
00106 
00107 /** Time left info */
00108 const int SG_PROPCLASS_TIME = 1 << 10;
00109 
00110 /** Abstract property */
00111 const int SG_PROPCLASS_ABSTRACT = 1 << 11;
00112 
00113 /** Property is not part of the FF[3] standard */
00114 const int SG_PROPCLASS_NOT_FF3 = 1 << 12;
00115 
00116 /** Property is not part of the FF[4] standard */
00117 const int SG_PROPCLASS_NOT_FF4 = 1 << 13;
00118 
00119 /** Custom Smart Go property */
00120 const int SG_PROPCLASS_CUSTOM = 1 << 14;
00121 
00122 /** Don't write prop when publishing clean file */
00123 const int SG_PROPCLASS_NOTCLEAN = 1 << 15;
00124 
00125 /** Write out this property starting on a new line */
00126 const int SG_PROPCLASS_NEWLINE = 1 << 16;
00127 
00128 //----------------------------------------------------------------------------
00129 
00130 /** Property list.
00131     Implemented as list of pointers to objects derived from Property.
00132 */
00133 class SgPropList
00134 {
00135 public:
00136     SgPropList();
00137 
00138     ~SgPropList();
00139 
00140     /** Return whether this list contains zero elements. */
00141     bool IsEmpty() const;
00142 
00143     /** Remove all elements in this list, disposing each property. */
00144     void Clear();
00145 
00146     /** Return the first property in the list that matches the given ID.
00147         Note that SG_PROP_INFO, SG_PROP_ANNOTATE, SG_PROP_POS_ANNO,
00148         SG_PROP_MOVE_ANNO, and SG_PROP_COUNT match any property that has the
00149         corresponding flag set.
00150         @return 0 if there is no such property.
00151     */
00152     SgProp* Get(SgPropID id) const;
00153 
00154     /** Return the first property in the list that matches the given text. */
00155     SgProp* GetPropContainingText(const std::string& findText) const;
00156 
00157     /** Add the property to this property list.
00158         Enforces that no two properties of the same kind are added.
00159     */
00160     void Add(const SgProp* prop);
00161 
00162     /** If the property with the given ID exists, move it to the front of this
00163         property list.
00164     */
00165     void MoveToFront(SgPropID id);
00166 
00167     /** Remove the property from the property list.
00168         Return true if the property was in the list.
00169     */
00170     bool Remove(const SgProp* prop);
00171 
00172     /** Remove any properties that match 'id' from this list, and
00173         dispose them, except don't touch *protectProp if it's in
00174         the list.
00175     */
00176     void Remove(SgPropID id, const SgProp* protectProp);
00177 
00178     void RemoveProp(SgPropID id) { Remove(id, 0); }
00179 
00180     /** Add the move annotations at the end of '*string'.
00181         !! very good move SG_PROP_GOOD_MOVE[2] <br>
00182         !  good move SG_PROP_GOOD_MOVE[1] <br>
00183         !? interesting move SG_PROP_INTERESTING <br>
00184         ?! doubtful move SG_PROP_DOUBTFUL <br>
00185         ?  bad move SG_PROP_BAD_MOVE[1] <br>
00186         ?? very bad move SG_PROP_BAD_MOVE[2] <br>
00187         Return true if a move annotation was added.
00188     */
00189     bool AppendMoveAnnotation(std::string* s) const;
00190 
00191 private:
00192     friend class SgPropListIterator;
00193 
00194     /** property list implemented as list of properties */
00195     SgVectorOf<SgProp> m_list;
00196 
00197     /** not implemented */
00198     SgPropList(const SgPropList&);
00199 
00200     /** not implemented */
00201     SgPropList& operator=(const SgPropList&);
00202 };
00203 
00204 inline bool SgPropList::IsEmpty() const
00205 {
00206     return m_list.IsEmpty();
00207 }
00208 
00209 //----------------------------------------------------------------------------
00210 
00211 /** Iterate through Properties in a PropList */
00212 class SgPropListIterator
00213 {
00214 public:
00215     /** Create a list iterator to iterate through list. */
00216     SgPropListIterator(const SgPropList& propList);
00217 
00218     void operator++();
00219 
00220     SgProp* operator*() const;
00221 
00222     operator bool() const;
00223 
00224 private:
00225     SgVectorIteratorOf<SgProp> m_listIterator;
00226 
00227     /** Not implemented */
00228     SgPropListIterator(const SgPropListIterator&);
00229 
00230     /** Not implemented */
00231     SgPropListIterator& operator=(const SgPropListIterator&);
00232 };
00233 
00234 inline SgPropListIterator::SgPropListIterator(const SgPropList& propList)
00235     : m_listIterator(propList.m_list)
00236 {
00237 }
00238 
00239 inline void SgPropListIterator::operator++()
00240 {
00241     m_listIterator.operator++();
00242 }
00243 
00244 inline SgProp* SgPropListIterator::operator*() const
00245 {
00246     return m_listIterator.operator*();
00247 }
00248 
00249 inline SgPropListIterator::operator bool() const
00250 {
00251     return m_listIterator.operator bool();
00252 }
00253 
00254 //----------------------------------------------------------------------------
00255 
00256 /** Property base class */
00257 class SgProp
00258 {
00259 public:
00260     explicit SgProp(SgPropID id);
00261 
00262     virtual ~SgProp();
00263 
00264     /** Override this function for each property class to return an exact
00265         duplicate of this property.
00266     */
00267     virtual SgProp* Duplicate() const = 0;
00268 
00269     /** Return the property type of this property. */
00270     SgPropID ID() const;
00271 
00272     /** Get the flags for this property type.
00273         Not normally overridden.
00274     */
00275     virtual SgPropFlags Flags() const;
00276 
00277     /** Get the the label for this property type.
00278         Overridden only by SgPropUnknown.
00279     */
00280     virtual std::string Label() const;
00281 
00282     /** Return whether any of the given flags are set for this property. */
00283     bool Flag(SgPropFlags flags) const;
00284 
00285     /** Convert the property into string representation.
00286         Escapes special characters if needed (this depends on the property,
00287         e.g. the colon needs to be escaped only by some properties)
00288         Use the default file format if 'fileFormat' is
00289         zero; use the proper version of the sgf file format if 'fileFormat'
00290         is 3 or greater.
00291         @return true if the property should be written to file
00292     */
00293     virtual bool ToString(std::vector<std::string>& values, int boardSize,
00294                           SgPropPointFmt fmt, int fileFormat) const = 0;
00295 
00296     /** Override this method to convert the string read from disk to the value
00297         of this property, and set the value of this property.
00298         @return true, if the string could be converted to a valid property.
00299     */
00300     virtual bool FromString(const std::vector<std::string>& values,
00301                             int boardSize, SgPropPointFmt fmt) = 0;
00302 
00303     /** Call this function with a property of the right type to register that
00304         property type.
00305         Ownership of 'prop' is passed to the Property class;
00306         it will dispose the property upon exit.
00307         Register returns the property identifier to be used to refer to this
00308         property.
00309         Abstract properties can be registered with 'prop' set to 0.
00310         No property object of that type can be instantiated.
00311         (?? useful for searching?)
00312         This method asserts and returns 0 if the registry is full.
00313     */
00314     static SgPropID Register(SgProp* prop, const char* label,
00315                              SgPropFlags flags = 0);
00316 
00317     /** Create a property with the given property ID. */
00318     static SgProp* CreateProperty(SgPropID id);
00319 
00320     /** Return the ID for a given label.
00321         Return SG_PROP_NONE if there is no property with that label.
00322     */
00323     static SgPropID GetIDOfLabel(const std::string& label);
00324 
00325     /** Convert the text specified in the Find dialog to special propIDs to
00326         search for.
00327         Return SG_PROP_NONE if the literal text should be searched for.
00328     */
00329     static SgPropID ConvertFindTextToPropID(const std::string& findText);
00330 
00331     /** Initialize properties.
00332         Registers most properties. Does not register SG_PROP_MOVE_BLACK ("B")
00333         and SG_PROP_MOVE_WHITE ("W"), because they are game dependent.
00334     */
00335     static void Init();
00336 
00337     /** Finalize properties. */
00338     static void Fini();
00339 
00340     /** If this property is marked as either SG_PROPCLASS_BLACK or
00341         SG_PROPCLASS_WHITE, return that property.
00342         Otherwise the return value is undefined (checked with assertion).
00343     */
00344     SgBlackWhite Player() const;
00345 
00346     bool IsPlayer(SgBlackWhite player) const;
00347 
00348     /** If the given property is marked as either SG_PROPCLASS_BLACK or
00349         SG_PROPCLASS_WHITE, return the property of the opposite color,
00350         otherwise return 'id'.
00351     */
00352     static SgPropID OpponentProp(SgPropID id);
00353 
00354     /** If the given property is marked as either SG_PROPCLASS_BLACK or
00355         SG_PROPCLASS_WHITE, return the property of player's color, otherwise
00356         return 'id'.
00357     */
00358     static SgPropID PlayerProp(SgPropID id, SgBlackWhite player);
00359 
00360     /** Override this method to do something special when changing the color
00361         of a property (e.g. a value might need to be negated).
00362     */
00363     virtual void ChangeToOpponent();
00364 
00365     /** Return true if the given 'id' matches this property.
00366         The special properties SG_PROP_INFO, SG_PROP_ANNOTATE,
00367         SG_PROP_POS_ANNO, SG_PROP_MOVE_ANNO, and SG_PROP_COUNT match any
00368         property that has the corresponding flag set.
00369     */
00370     bool MatchesID(SgPropID id) const;
00371 
00372     /** Return true if this property matches the given text.
00373         Override for specific properties.
00374     */
00375     virtual bool ContainsText(const std::string& findText);
00376 
00377 protected:
00378     SgPropID m_id;
00379 
00380     static bool Initialized();
00381 
00382 private:
00383     /** Was SgProp::Init() called? */
00384     static bool s_initialized;
00385 
00386     static int s_numPropClasses;
00387 
00388     static SgPropFlags s_flags[SG_MAX_PROPCLASS];
00389 
00390     static std::string s_label[SG_MAX_PROPCLASS];
00391 
00392     static SgProp* s_prop[SG_MAX_PROPCLASS];
00393 
00394     /** not implemented */
00395     SgProp(const SgProp&);
00396 
00397     /** not implemented */
00398     SgProp& operator=(const SgProp&);
00399 };
00400 
00401 inline SgProp::SgProp(SgPropID id)
00402     : m_id(id)
00403 {
00404 }
00405 
00406 inline SgPropID SgProp::ID() const
00407 {
00408     return m_id;
00409 }
00410 
00411 inline bool SgProp::Flag(SgPropFlags flags) const
00412 {
00413     return (Flags() & flags) != 0;
00414 }
00415 
00416 //----------------------------------------------------------------------------
00417 
00418 /** Unknown property.
00419     Unknown properties are used to store properties read from file but not
00420     understood by this version. This property keeps the label and the string
00421     that were read in, so that it can be written out again in exactly the same
00422     way.
00423 */
00424 class SgPropUnknown
00425     : public SgProp
00426 {
00427 public:
00428     explicit SgPropUnknown(SgPropID id);
00429 
00430     SgPropUnknown(SgPropID id, std::string label,
00431                   const std::vector<std::string>& values);
00432 
00433     SgProp* Duplicate() const;
00434 
00435     bool ToString(std::vector<std::string>& values, int boardSize,
00436                   SgPropPointFmt fmt, int fileFormat) const;
00437 
00438     bool FromString(const std::vector<std::string>& values,
00439                     int boardSize, SgPropPointFmt fmt);
00440 
00441     std::string Label() const;
00442 
00443 private:
00444     std::string m_label;
00445 
00446     std::vector<std::string> m_values;
00447 };
00448 
00449 inline SgPropUnknown::SgPropUnknown(SgPropID id)
00450     : SgProp(id)
00451 {
00452 }
00453 
00454 inline SgPropUnknown::SgPropUnknown(SgPropID id, std::string label,
00455                                     const std::vector<std::string>& values)
00456     : SgProp(id),
00457       m_label(label),
00458       m_values(values)
00459 {
00460 }
00461 
00462 inline std::string SgPropUnknown::Label() const
00463 {
00464     return m_label;
00465 }
00466 
00467 //----------------------------------------------------------------------------
00468 
00469 /** A property with integer value. */
00470 class SgPropInt
00471     : public SgProp
00472 {
00473 public:
00474     explicit SgPropInt(SgPropID id);
00475 
00476     SgPropInt(SgPropID id, int value);
00477 
00478     SgProp* Duplicate() const;
00479 
00480     bool ToString(std::vector<std::string>& values, int boardSize,
00481                   SgPropPointFmt fmt, int fileFormat) const;
00482 
00483     bool FromString(const std::vector<std::string>& values,
00484                     int boardSize, SgPropPointFmt fmt);
00485 
00486     /** Return the integer value of this property. */
00487     int Value() const;
00488 
00489     bool IsValue(int value) const;
00490 
00491     /** Set the integer value of this property. */
00492     void SetValue(int value);
00493 
00494 protected:
00495     int m_value;
00496 };
00497 
00498 inline SgPropInt::SgPropInt(SgPropID id)
00499     : SgProp(id),
00500       m_value(0)
00501 {
00502 }
00503 
00504 inline SgPropInt::SgPropInt(SgPropID id, int value)
00505     : SgProp(id),
00506       m_value(value)
00507 {
00508 }
00509 
00510 inline int SgPropInt::Value() const
00511 {
00512     SG_ASSERT(Initialized());
00513     return m_value;
00514 }
00515 
00516 inline bool SgPropInt::IsValue(int value) const
00517 {
00518     return m_value == value;
00519 }
00520 
00521 inline void SgPropInt::SetValue(int value)
00522 {
00523     m_value = value;
00524 }
00525 
00526 //----------------------------------------------------------------------------
00527 
00528 /** A property with a double value. Optionally can specify precision, too. */
00529 class SgPropReal
00530     : public SgProp
00531 {
00532 public:
00533     explicit SgPropReal(SgPropID id);
00534 
00535     /** Create property with double value and given precision.
00536         @param id Property ID
00537         @param value Value
00538         @param precision Precision after dot.
00539         0 means default precision.
00540     */
00541     SgPropReal(SgPropID id, double value, int precision = 0);
00542 
00543     SgProp* Duplicate() const;
00544 
00545     bool ToString(std::vector<std::string>& values, int boardSize,
00546                   SgPropPointFmt fmt, int fileFormat) const;
00547 
00548     bool FromString(const std::vector<std::string>& values,
00549                     int boardSize, SgPropPointFmt fmt);
00550 
00551     double Value() const;
00552 
00553     void SetValue(double value, int precision = 0);
00554 
00555 protected:
00556     int m_precision;
00557 
00558     double m_value;
00559 };
00560 
00561 inline SgPropReal::SgPropReal(SgPropID id)
00562     : SgProp(id),
00563       m_precision(0),
00564       m_value(0)
00565 {
00566 }
00567 
00568 inline SgPropReal::SgPropReal(SgPropID id, double value, int precision)
00569     : SgProp(id),
00570       m_precision(precision),
00571       m_value(value)
00572 {
00573 }
00574 
00575 inline double SgPropReal::Value() const
00576 {
00577     return m_value;
00578 }
00579 
00580 inline void SgPropReal::SetValue(double value, int precision)
00581 {
00582     m_value = value;
00583     m_precision = precision;
00584 }
00585 
00586 //----------------------------------------------------------------------------
00587 
00588 /** A property with no associated value.
00589     Works as a flag (property present/absent).
00590 */
00591 class SgPropSimple
00592     : public SgProp
00593 {
00594 public:
00595     explicit SgPropSimple(SgPropID id);
00596 
00597     SgProp* Duplicate() const;
00598 
00599     bool ToString(std::vector<std::string>& values, int boardSize,
00600                   SgPropPointFmt fmt, int fileFormat) const;
00601 
00602     bool FromString(const std::vector<std::string>& values,
00603                     int boardSize, SgPropPointFmt fmt);
00604 };
00605 
00606 inline SgPropSimple::SgPropSimple(SgPropID id)
00607     : SgProp(id)
00608 {
00609 }
00610 
00611 //----------------------------------------------------------------------------
00612 
00613 /** Multiple property.
00614     @todo AR: Make sure it's in range[1..2]. Should be deleted if it's 0.
00615     @todo AR: could do away with this after all, set flag instead?
00616 */
00617 class SgPropMultiple
00618     : public SgPropInt
00619 {
00620 public:
00621     explicit SgPropMultiple(SgPropID id);
00622 
00623     SgPropMultiple(SgPropID id, int value);
00624 
00625     SgProp* Duplicate() const;
00626 };
00627 
00628 inline SgPropMultiple::SgPropMultiple(SgPropID id)
00629     : SgPropInt(id, 1)
00630 {
00631 }
00632 
00633 inline SgPropMultiple::SgPropMultiple(SgPropID id, int value)
00634     : SgPropInt(id, value)
00635 {
00636 }
00637 
00638 //----------------------------------------------------------------------------
00639 
00640 /** Like SgPropInt but can change sign for opponent's value. */
00641 class SgPropValue
00642     : public SgPropInt
00643 {
00644 public:
00645     explicit SgPropValue(SgPropID id);
00646 
00647     SgPropValue(SgPropID id, int value);
00648 
00649     SgProp* Duplicate() const;
00650 
00651     virtual void ChangeToOpponent();
00652 };
00653 
00654 inline SgPropValue::SgPropValue(SgPropID id)
00655     : SgPropInt(id)
00656 {
00657 }
00658 
00659 inline SgPropValue::SgPropValue(SgPropID id, int value)
00660     : SgPropInt(id, value)
00661 {
00662 }
00663 
00664 //----------------------------------------------------------------------------
00665 
00666 /** A property with time value. */
00667 class SgPropTime
00668     : public SgPropReal
00669 {
00670 public:
00671     SgPropTime(SgPropID id, double value = 0, int precision = 1);
00672 
00673     virtual ~SgPropTime();
00674 
00675     SgProp* Duplicate() const;
00676 };
00677 
00678 inline SgPropTime::SgPropTime(SgPropID id, double value, int precision)
00679     : SgPropReal(id, value, precision)
00680 {
00681 }
00682 
00683 //----------------------------------------------------------------------------
00684 
00685 /** Like SgPropTime, but gets stored with millisecond precision rather than
00686     tenths of a second.
00687 */
00688 class SgPropMSec
00689     : public SgPropTime
00690 {
00691 public:
00692     explicit SgPropMSec(SgPropID id);
00693 
00694     SgPropMSec(SgPropID id, double value);
00695 
00696     virtual ~SgPropMSec();
00697 
00698     SgProp* Duplicate() const;
00699 };
00700 
00701 inline SgPropMSec::SgPropMSec(SgPropID id)
00702     : SgPropTime(id, 0, 3)
00703 {
00704 }
00705 
00706 inline SgPropMSec::SgPropMSec(SgPropID id, double value)
00707     : SgPropTime(id, value, 3)
00708 {
00709 }
00710 
00711 //----------------------------------------------------------------------------
00712 
00713 /** A property storing a point-move for games.
00714     Only for games in which a move can be described by a point.
00715 */
00716 class SgPropMove
00717     : public SgProp
00718 {
00719 public:
00720     explicit SgPropMove(SgPropID id);
00721 
00722     SgPropMove(SgPropID id, SgMove move);
00723 
00724     SgProp* Duplicate() const;
00725 
00726     /** Return the move value of this property. */
00727     SgPoint Value() const;
00728 
00729     bool IsValue(SgPoint move) const;
00730 
00731     bool ToString(std::vector<std::string>& values, int boardSize,
00732                   SgPropPointFmt fmt, int fileFormat) const;
00733 
00734     bool FromString(const std::vector<std::string>& values,
00735                     int boardSize, SgPropPointFmt fmt);
00736 
00737 protected:
00738     SgPoint m_move;
00739 };
00740 
00741 inline SgPropMove::SgPropMove(SgPropID id)
00742     : SgProp(id),
00743       m_move(SG_NULLMOVE)
00744 {
00745 }
00746 
00747 inline SgPropMove::SgPropMove(SgPropID id, SgMove move)
00748     : SgProp(id),
00749       m_move(move)
00750 {
00751 }
00752 
00753 inline SgPoint SgPropMove::Value() const
00754 {
00755     return m_move;
00756 }
00757 
00758 inline bool SgPropMove::IsValue(SgPoint move) const
00759 {
00760     return m_move == move;
00761 }
00762 
00763 //----------------------------------------------------------------------------
00764 
00765 /** A property storing a list of points. */
00766 class SgPropPointList
00767     : public SgProp
00768 {
00769 public:
00770     explicit SgPropPointList(SgPropID id);
00771 
00772     SgPropPointList(SgPropID id, const SgVector<SgPoint>& list);
00773 
00774     virtual ~SgPropPointList();
00775 
00776     SgProp* Duplicate() const;
00777 
00778     /** Return the vector stored in this property. */
00779     const SgVector<SgPoint>& Value() const;
00780     SgVector<SgPoint>& Value();
00781 
00782     /** Set the vector of this property. */
00783     void SetValue(const SgVector<SgPoint>& list);
00784 
00785     void PushBack(SgPoint p);
00786 
00787     bool ToString(std::vector<std::string>& values, int boardSize,
00788                   SgPropPointFmt fmt, int fileFormat) const;
00789 
00790     bool FromString(const std::vector<std::string>& values,
00791                     int boardSize, SgPropPointFmt fmt);
00792 
00793 private:
00794     SgVector<SgPoint> m_list;
00795 };
00796 
00797 inline SgPropPointList::SgPropPointList(SgPropID id)
00798     : SgProp(id)
00799 {
00800 }
00801 
00802 inline const SgVector<SgPoint>& SgPropPointList::Value() const
00803 {
00804     return m_list;
00805 }
00806 
00807 inline SgVector<SgPoint>& SgPropPointList::Value()
00808 {
00809     return m_list;
00810 }
00811 
00812 inline void SgPropPointList::SetValue(const SgVector<SgPoint>& list)
00813 {
00814     m_list = list;
00815 }
00816 
00817 inline void SgPropPointList::PushBack(SgPoint p)
00818 {
00819     m_list.PushBack(p);
00820 }
00821 
00822 //----------------------------------------------------------------------------
00823 
00824 /** A property storing a text string. */
00825 class SgPropText
00826     : public SgProp
00827 {
00828 public:
00829     explicit SgPropText(SgPropID id);
00830 
00831     SgPropText(SgPropID id, const std::string& text);
00832 
00833     SgProp* Duplicate() const;
00834 
00835     /** Return the string value of this property. */
00836     const std::string& Value() const;
00837 
00838     std::string& Value();
00839 
00840     void SetValue(const std::string& value);
00841 
00842     void AppendText(const std::string& text);
00843 
00844     bool ToString(std::vector<std::string>& values, int boardSize,
00845                   SgPropPointFmt fmt, int fileFormat) const;
00846 
00847     bool FromString(const std::vector<std::string>& values,
00848                     int boardSize, SgPropPointFmt fmt);
00849 
00850     virtual bool ContainsText(const std::string& findText);
00851 
00852 private:
00853     std::string m_text;
00854 };
00855 
00856 inline SgPropText::SgPropText(SgPropID id)
00857     : SgProp(id),
00858       m_text()
00859 {
00860 }
00861 
00862 inline SgPropText::SgPropText(SgPropID id, const std::string& text)
00863     : SgProp(id),
00864       m_text(text)
00865 {
00866 }
00867 
00868 inline const std::string& SgPropText::Value() const
00869 {
00870     return m_text;
00871 }
00872 
00873 inline std::string& SgPropText::Value()
00874 {
00875     return m_text;
00876 }
00877 
00878 inline void SgPropText::SetValue(const std::string& value)
00879 {
00880     m_text = value;
00881 }
00882 
00883 inline void SgPropText::AppendText(const std::string& text)
00884 {
00885     m_text += text;
00886 }
00887 
00888 //----------------------------------------------------------------------------
00889 
00890 /** Keeps a string for each point in a set of points. */
00891 class SgPropTextList
00892     : public SgProp
00893 {
00894 public:
00895     explicit SgPropTextList(SgPropID id);
00896 
00897     SgPropTextList(SgPropID id, const SgVector<SgPoint>& points,
00898                    SgVectorOf<std::string> strings);
00899 
00900     virtual ~SgPropTextList();
00901 
00902     SgProp* Duplicate() const;
00903 
00904     /** Return a list with all the points that have text associated with
00905         them.
00906     */
00907     const SgVector<SgPoint>& GetPointsWithText() const;
00908 
00909     /** If point 'p' has a string, copy that string into '*string' and return
00910         true.
00911         Otherwise return false and don't change '*string'.
00912     */
00913     bool GetStringAtPoint(SgPoint p, std::string* s) const;
00914 
00915     /** Set the string for point 'p' to 'string'.
00916         If that point already has a string, replace it with the new string.
00917     */
00918     void AddStringAtPoint(SgPoint p, const std::string& s);
00919 
00920     /** Append 'string' to the string for point 'p'.
00921         If that point has no string, create a new one.
00922     */
00923     void AppendToStringAtPoint(SgPoint p, const std::string& s);
00924 
00925     /** Remove any existing string for point 'p'. */
00926     void ClearStringAtPoint(SgPoint p);
00927 
00928     bool ToString(std::vector<std::string>& values, int boardSize,
00929                   SgPropPointFmt fmt, int fileFormat) const;
00930 
00931     bool FromString(const std::vector<std::string>& values,
00932                     int boardSize, SgPropPointFmt fmt);
00933 
00934     virtual bool ContainsText(const std::string& findText);
00935 
00936 private:
00937     SgVector<SgPoint> m_points;
00938 
00939     SgVectorOf<std::string> m_strings;
00940 };
00941 
00942 inline SgPropTextList::SgPropTextList(SgPropID id)
00943     : SgProp(id),
00944       m_points(),
00945       m_strings()
00946 {
00947 }
00948 
00949 inline const SgVector<SgPoint>& SgPropTextList::GetPointsWithText() const
00950 {
00951     return m_points;
00952 }
00953 
00954 //----------------------------------------------------------------------------
00955 
00956 /** A property storing a player color (Black or White). */
00957 class SgPropPlayer
00958     : public SgProp
00959 {
00960 public:
00961     explicit SgPropPlayer(SgPropID id);
00962 
00963     SgPropPlayer(SgPropID id, int player);
00964 
00965     SgProp* Duplicate() const;
00966 
00967     SgBlackWhite Value() const;
00968 
00969     void SetValue(SgBlackWhite player);
00970 
00971     virtual void ChangeToOpponent();
00972 
00973     bool ToString(std::vector<std::string>& values, int boardSize,
00974                   SgPropPointFmt fmt, int fileFormat) const;
00975 
00976     bool FromString(const std::vector<std::string>& values,
00977                     int boardSize, SgPropPointFmt fmt);
00978 
00979 private:
00980     SgBlackWhite m_player;
00981 };
00982 
00983 inline SgPropPlayer::SgPropPlayer(SgPropID id)
00984     : SgProp(id),
00985       m_player(SG_BLACK)
00986 {
00987 }
00988 
00989 inline SgPropPlayer::SgPropPlayer(SgPropID id, int player)
00990     : SgProp(id),
00991       m_player(player)
00992 {
00993 }
00994 
00995 inline SgBlackWhite SgPropPlayer::Value() const
00996 {
00997     return m_player;
00998 }
00999 
01000 inline void SgPropPlayer::SetValue(SgBlackWhite player)
01001 {
01002     m_player = player;
01003 }
01004 
01005 //----------------------------------------------------------------------------
01006 
01007 /** A property storing a list of stones to add to the board,
01008     or points to make empty.
01009 */
01010 class SgPropAddStone
01011     : public SgPropPointList
01012 {
01013 public:
01014     explicit SgPropAddStone(SgPropID id);
01015 
01016     SgPropAddStone(SgPropID id, const SgVector<SgPoint>& list);
01017 
01018     virtual ~SgPropAddStone();
01019 
01020     SgProp* Duplicate() const;
01021 };
01022 
01023 inline SgPropAddStone::SgPropAddStone(SgPropID id)
01024     : SgPropPointList(id)
01025 {
01026 }
01027 
01028 inline SgPropAddStone::SgPropAddStone(SgPropID id,
01029                                       const SgVector<SgPoint>& list)
01030     : SgPropPointList(id, list)
01031 {
01032 }
01033 
01034 //----------------------------------------------------------------------------
01035 
01036 /** @name General */
01037 //@{
01038 
01039 /** Default value returned by some functions */
01040 extern SgPropID SG_PROP_NONE;
01041 
01042 /** Unknown property read from disk */
01043 extern SgPropID SG_PROP_UNKNOWN;
01044 
01045 //@}
01046 
01047 /** @name Moves */
01048 //@{
01049 
01050 /** Generic property for black and white move */
01051 extern SgPropID SG_PROP_MOVE;
01052 
01053 /** Black move */
01054 extern SgPropID SG_PROP_MOVE_BLACK;
01055 
01056 /** White move */
01057 extern SgPropID SG_PROP_MOVE_WHITE;
01058 
01059 //@}
01060 
01061 /** @name Board edits */
01062 //@{
01063 
01064 /** Add a list of black stones to the current position */
01065 extern SgPropID SG_PROP_ADD_BLACK;
01066 
01067 /** Add a list of white stones to the current position */
01068 extern SgPropID SG_PROP_ADD_WHITE;
01069 
01070 /** Remove stones from the board */
01071 extern SgPropID SG_PROP_ADD_EMPTY;
01072 
01073 /** Whose turn it is to move after executing the node */
01074 extern SgPropID SG_PROP_PLAYER;
01075 
01076 
01077 /** @name Value and territory */
01078 //@{
01079 
01080 /** Node value expressed as positive = good for Black */
01081 extern SgPropID SG_PROP_VALUE;
01082 
01083 /** Black surrounded territory and dead white stones */
01084 extern SgPropID SG_PROP_TERR_BLACK;
01085 
01086 /** White surrounded territory and dead black stones */
01087 extern SgPropID SG_PROP_TERR_WHITE;
01088 
01089 //@}
01090 
01091 /** @name Marks drawn on the board */
01092 //@{
01093 
01094 /** Generic property for marked board points */
01095 extern SgPropID SG_PROP_MARKS;
01096 
01097 /** Selected points used to temporarily mark points */
01098 extern SgPropID SG_PROP_SELECT;
01099 
01100 /** Crosses displayed on stones and empty points */
01101 extern SgPropID SG_PROP_MARKED;
01102 
01103 /** Triangles displayed on stones and empty points */
01104 extern SgPropID SG_PROP_TRIANGLE;
01105 
01106 /** Small squares or square stones */
01107 extern SgPropID SG_PROP_SQUARE;
01108 
01109 /** Diamond marks */
01110 extern SgPropID SG_PROP_DIAMOND;
01111 
01112 /** Board points marked with small grey circles */
01113 extern SgPropID SG_PROP_CIRCLE;
01114 
01115 /** Dimmed points */
01116 extern SgPropID SG_PROP_DIMMED;
01117 
01118 /** Sequence of pairs: point, four letter label */
01119 extern SgPropID SG_PROP_LABEL;
01120 
01121 //@}
01122 
01123 /** @name Time control */
01124 //@{
01125 
01126 /** Generic property for time left information */
01127 extern SgPropID SG_PROP_TIMES;
01128 
01129 /** Time left for the black player (TimeProp) */
01130 extern SgPropID SG_PROP_TIME_BLACK;
01131 
01132 /** Time left for the white player (TimeProp) */
01133 extern SgPropID SG_PROP_TIME_WHITE;
01134 
01135 /** Number of stones to play for black in this overtime period */
01136 extern SgPropID SG_PROP_OT_BLACK;
01137 
01138 /** Number of stones to play for white in this overtime period */
01139 extern SgPropID SG_PROP_OT_WHITE;
01140 
01141 /** Number of moves per overtime period (0 = no overtime) */
01142 extern SgPropID SG_PROP_OT_NU_MOVES;
01143 
01144 /** Length of each overtime period */
01145 extern SgPropID SG_PROP_OT_PERIOD;
01146 
01147 /** Seconds of operator overhead for each move */
01148 extern SgPropID SG_PROP_OVERHEAD;
01149 
01150 /** Added to root node if losing on time is enforced */
01151 extern SgPropID SG_PROP_LOSE_TIME;
01152 
01153 //@}
01154 
01155 /** @name Statistics */
01156 //@{
01157 
01158 /** Generic property subsuming all in statistics category */
01159 extern SgPropID SG_PROP_COUNT;
01160 
01161 /** The time used to solve a problem */
01162 extern SgPropID SG_PROP_TIME_USED;
01163 
01164 /** The number of nodes looked at to solve a problem */
01165 extern SgPropID SG_PROP_NUM_NODES;
01166 
01167 /** The number of leaf nodes inspected */
01168 extern SgPropID SG_PROP_NUM_LEAFS;
01169 
01170 /** The maximal depth reached during the search */
01171 extern SgPropID SG_PROP_MAX_DEPTH;
01172 
01173 /** The number of plies searched */
01174 extern SgPropID SG_PROP_DEPTH;
01175 
01176 /** The number of top level moves at deepest search */
01177 extern SgPropID SG_PROP_PART_DEPTH;
01178 
01179 /** A value computed for a position */
01180 extern SgPropID SG_PROP_EVAL;
01181 
01182 /** The move expected from the current player */
01183 extern SgPropID SG_PROP_EXPECTED;
01184 
01185 /** Moves tried at a node in self-test mode */
01186 extern SgPropID SG_PROP_SELF_TEST;
01187 
01188 //@}
01189 
01190 /** @name Root props */
01191 //@{
01192 
01193 /** The file format used to store the game */
01194 extern SgPropID SG_PROP_FORMAT;
01195 
01196 /** The board size */
01197 extern SgPropID SG_PROP_SIZE;
01198 
01199 /** The game (encoding see SgTypes.TheGame) */
01200 extern SgPropID SG_PROP_GAME;
01201 
01202 /** Species of the black player (human, computer, modem) */
01203 extern SgPropID SG_PROP_SPEC_BLACK;
01204 
01205 /** Species of the white player (human, computer, modem) */
01206 extern SgPropID SG_PROP_SPEC_WHITE;
01207 
01208 /** Number of Chinese handicap stones */
01209 extern SgPropID SG_PROP_CHINESE;
01210 
01211 /** The application that wrote this file */
01212 extern SgPropID SG_PROP_APPLIC;
01213 
01214 //@}
01215 
01216 /** @name Annotations */
01217 //@{
01218 
01219 /** Generic property subsuming all annotation properties */
01220 extern SgPropID SG_PROP_ANNOTATE;
01221 
01222 /** The textual comment of a node */
01223 extern SgPropID SG_PROP_COMMENT;
01224 
01225 /** Short textual comment */
01226 extern SgPropID SG_PROP_NAME;
01227 
01228 /** Position marked with a check mark */
01229 extern SgPropID SG_PROP_CHECK;
01230 
01231 /** Position marked with a sigma icon */
01232 extern SgPropID SG_PROP_SIGMA;
01233 
01234 /** General position mark */
01235 extern SgPropID SG_PROP_HOTSPOT;
01236 
01237 /** Divides the game into sections to be printed */
01238 extern SgPropID SG_PROP_FIGURE;
01239 
01240 //@}
01241 
01242 /** @name Position annotations */
01243 //@{
01244 
01245 /** Generic property subsuming all position annotations */
01246 extern SgPropID SG_PROP_POS_ANNO;
01247 
01248 /** Good position for Black */
01249 extern SgPropID SG_PROP_GOOD_BLACK;
01250 
01251 /** Good position for White */
01252 extern SgPropID SG_PROP_GOOD_WHITE;
01253 
01254 /** Even position */
01255 extern SgPropID SG_PROP_EVEN_POS;
01256 
01257 /** Unclear position */
01258 extern SgPropID SG_PROP_UNCLEAR;
01259 
01260 //@}
01261 
01262 /** @name Move annotations */
01263 //@{
01264 
01265 /** Generic property subsuming all move annotations */
01266 extern SgPropID SG_PROP_MOVE_ANNO;
01267 
01268 /** Denotes an exceptionally good move (! or !!) */
01269 extern SgPropID SG_PROP_GOOD_MOVE;
01270 
01271 /** Denotes a bad move (? or ??) */
01272 extern SgPropID SG_PROP_BAD_MOVE;
01273 
01274 /** Denotes an interesting move (!?) */
01275 extern SgPropID SG_PROP_INTERESTING;
01276 
01277 /** Denotes a doubtful move (?!) */
01278 extern SgPropID SG_PROP_DOUBTFUL;
01279 
01280 //@}
01281 
01282 /** @name Game info */
01283 //@{
01284 
01285 /** Generic property subsuming all game info props */
01286 extern SgPropID SG_PROP_INFO;
01287 
01288 /** The file name of the game */
01289 extern SgPropID SG_PROP_GAME_NAME;
01290 
01291 /** Comment pertaining to the whole game */
01292 extern SgPropID SG_PROP_GAME_COMMENT;
01293 
01294 /** Text describing the event */
01295 extern SgPropID SG_PROP_EVENT;
01296 
01297 /** The round of the tournament */
01298 extern SgPropID SG_PROP_ROUND;
01299 
01300 /** The date when the game was played */
01301 extern SgPropID SG_PROP_DATE;
01302 
01303 /** Where the game was played */
01304 extern SgPropID SG_PROP_PLACE;
01305 
01306 /** Name of the black player */
01307 extern SgPropID SG_PROP_PLAYER_BLACK;
01308 
01309 /** Name of the white player */
01310 extern SgPropID SG_PROP_PLAYER_WHITE;
01311 
01312 /** Who won the game */
01313 extern SgPropID SG_PROP_RESULT;
01314 
01315 /** The person who entered the game and comments */
01316 extern SgPropID SG_PROP_USER;
01317 
01318 /** The time allocated to each player */
01319 extern SgPropID SG_PROP_TIME;
01320 
01321 /** Where the game was copied from */
01322 extern SgPropID SG_PROP_SOURCE;
01323 
01324 /** Who has the copyright on the material */
01325 extern SgPropID SG_PROP_COPYRIGHT;
01326 
01327 /** Who analyzed the game */
01328 extern SgPropID SG_PROP_ANALYSIS;
01329 
01330 /** Ranking of black player */
01331 extern SgPropID SG_PROP_RANK_BLACK;
01332 
01333 /** Ranking of white player */
01334 extern SgPropID SG_PROP_RANK_WHITE;
01335 
01336 /** Team of black player */
01337 extern SgPropID SG_PROP_TEAM_BLACK;
01338 
01339 /** Team of white player */
01340 extern SgPropID SG_PROP_TEAM_WHITE;
01341 
01342 /** The opening played in the game */
01343 extern SgPropID SG_PROP_OPENING;
01344 
01345 /** Special rules (Go: Japanese or Chinese) */
01346 extern SgPropID SG_PROP_RULES;
01347 
01348 /** Number of handicap stones */
01349 extern SgPropID SG_PROP_HANDICAP;
01350 
01351 /** Komi value */
01352 extern SgPropID SG_PROP_KOMI;
01353 
01354 //@}
01355 
01356 /** @name Abstract properties */
01357 //@{
01358 
01359 /** Indicates that depth-first traversal searches text */
01360 extern SgPropID SG_PROP_FIND_MOVE;
01361 
01362 /** Indicates that depth-first traversal searches move */
01363 extern SgPropID SG_PROP_FIND_TEXT;
01364 
01365 /** Used to search for branch points */
01366 extern SgPropID SG_PROP_BRANCH;
01367 
01368 /** A terminal node, only used for display */
01369 extern SgPropID SG_PROP_TERMINAL;
01370 
01371 //@}
01372 
01373 /** @name Smart Go specific properties */
01374 //@{
01375 
01376 /** Move motive: why move was generated */
01377 extern SgPropID SG_PROP_MOTIVE;
01378 
01379 /** Sequence of moves expected by computer player */
01380 extern SgPropID SG_PROP_SEQUENCE;
01381 
01382 /** Constraint: points must not be empty */
01383 extern SgPropID SG_PROP_NOT_EMPTY;
01384 
01385 /** Constraint: points must not be black */
01386 extern SgPropID SG_PROP_NOT_BLACK;
01387 
01388 /** Constraint: points must not be white */
01389 extern SgPropID SG_PROP_NOT_WHITE;
01390 
01391 //@}
01392 
01393 //----------------------------------------------------------------------------
01394 
01395 #endif // SG_PROP_H


17 Jun 2010 Doxygen 1.4.7