Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgWrite.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgWrite.h
00003     Utility write functions for SmartGo data types.
00004     @todo Write functions logically belong to the files of the classes they
00005     are outputting; should be moved.
00006 */
00007 //----------------------------------------------------------------------------
00008 
00009 #ifndef SG_WRITE_H
00010 #define SG_WRITE_H
00011 
00012 #include <iomanip>
00013 #include <iosfwd>
00014 #include <sstream>
00015 #include <string>
00016 #include <vector>
00017 #include "SgBoardColor.h"
00018 #include "SgPoint.h"
00019 #include "SgSList.h"
00020 #include "SgVector.h"
00021 
00022 //----------------------------------------------------------------------------
00023 
00024 /** Write left aligned text with a minimum width of 15 characters.
00025     Also appends a space to the label text.
00026 */
00027 class SgWriteLabel
00028 {
00029 public:
00030     SgWriteLabel(const std::string& label)
00031         : m_label(label)
00032     { }
00033 
00034     friend std::ostream& operator<<(std::ostream& out,
00035                                     const SgWriteLabel& w);
00036 
00037 private:
00038     std::string m_label;
00039 };
00040 
00041 //----------------------------------------------------------------------------
00042 
00043 /** Write all points in list.
00044     Splits long lists into multiple lines.
00045 */
00046 class SgWritePointList
00047 {
00048 public:
00049     SgWritePointList(const std::vector<SgPoint>& pointList,
00050                      std::string label = "",
00051                      bool writeSize = true);
00052 
00053     SgWritePointList(const SgVector<SgPoint>& pointList,
00054                      std::string label = "",
00055                      bool writeSize = true);
00056 
00057     std::ostream& Write(std::ostream& out) const;
00058 
00059 private:
00060     bool m_writeSize;
00061 
00062     std::vector<SgPoint> m_pointList;
00063 
00064     std::string m_label;
00065 };
00066 
00067 /** @relatesalso SgWritePointList */
00068 std::ostream& operator<<(std::ostream& out, const SgWritePointList& write);
00069 
00070 //----------------------------------------------------------------------------
00071 
00072 /** Output a SgSList with SgPoint elements to a stream. */
00073 template<int SIZE>
00074 class SgWriteSPointList
00075 {
00076 public:
00077     SgWriteSPointList(const SgSList<SgPoint,SIZE>& list,
00078                       std::string label = "", bool writeSize = true);
00079 
00080     std::ostream& Write(std::ostream& out) const;
00081 
00082 private:
00083     bool m_writeSize;
00084 
00085     const SgSList<SgPoint,SIZE>& m_list;
00086 
00087     std::string m_label;
00088 };
00089 
00090 /** @relatesalso SgWriteSPointList */
00091 template<int SIZE>
00092 std::ostream& operator<<(std::ostream& out,
00093                          const SgWriteSPointList<SIZE>& write);
00094 
00095 template<int SIZE>
00096 SgWriteSPointList<SIZE>::SgWriteSPointList(const SgSList<SgPoint,SIZE>& list,
00097                                            std::string label, bool writeSize)
00098     : m_writeSize(writeSize),
00099       m_list(list),
00100       m_label(label)
00101 {
00102 }
00103 
00104 template<int SIZE>
00105 std::ostream& SgWriteSPointList<SIZE>::Write(std::ostream& out) const
00106 {
00107     std::vector<SgPoint> list;
00108     for (typename SgSList<SgPoint,SIZE>::Iterator it(m_list); it; ++it)
00109         list.push_back(*it);
00110     return (out << SgWritePointList(list, m_label, m_writeSize));
00111 }
00112 
00113 template<int SIZE>
00114 std::ostream& operator<<(std::ostream& out,
00115                          const SgWriteSPointList<SIZE>& write)
00116 {
00117     return write.Write(out);
00118 }
00119 
00120 //----------------------------------------------------------------------------
00121 
00122 /** Write player color and move for games in which a move is a SgPoint.
00123     @todo Move to SgPoint, merge class with SgWritePoint.
00124 */
00125 class SgWriteMove
00126 {
00127 public:
00128     SgWriteMove(SgPoint point, SgBlackWhite color)
00129         : m_point(point),
00130           m_color(color)
00131     { }
00132 
00133 private:
00134     friend std::ostream& operator<<(std::ostream& out, const SgWriteMove &w);
00135 
00136     SgPoint m_point;
00137 
00138     SgBlackWhite m_color;
00139 };
00140 
00141 //----------------------------------------------------------------------------
00142 
00143 /** Write line of dashes. */
00144 class SgWriteLine
00145 {
00146 public:
00147     SgWriteLine()
00148     { }
00149 
00150     friend std::ostream& operator<<(std::ostream& out,
00151                                     const SgWriteLine &w);
00152 };
00153 
00154 //----------------------------------------------------------------------------
00155 
00156 /** Only writes "not" if value is false */
00157 class SgWriteBoolean
00158 {
00159 public:
00160     explicit SgWriteBoolean(bool value) : m_value(value) {}
00161 
00162 private:
00163     friend std::ostream& operator<<(std::ostream& out,
00164                                     const SgWriteBoolean &w);
00165     bool m_value;
00166 };
00167 
00168 //----------------------------------------------------------------------------
00169 
00170 /** Writes boolean as 0/1. */
00171 class SgWriteBoolAsInt
00172 {
00173 public:
00174     SgWriteBoolAsInt(bool value);
00175 
00176     std::ostream& Write(std::ostream& out) const;
00177 
00178 private:
00179     bool m_value;
00180 };
00181 
00182 /** @relatesalso SgWriteBoolAsInt */
00183 std::ostream& operator<<(std::ostream& out, const SgWriteBoolAsInt& write);
00184 
00185 //----------------------------------------------------------------------------
00186 
00187 #endif // SG_WRITE_H


17 Jun 2010 Doxygen 1.4.7