00001 //---------------------------------------------------------------------------- 00002 /** @file SgWrite.cpp 00003 See SgWrite.h. 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #include "SgSystem.h" 00008 #include "SgWrite.h" 00009 00010 #include <cstdio> 00011 #include <iostream> 00012 #include <iomanip> 00013 #include <sstream> 00014 #include "SgVector.h" 00015 00016 using namespace std; 00017 00018 //---------------------------------------------------------------------------- 00019 00020 ostream& operator<<(ostream& out, const SgWriteLabel& w) 00021 { 00022 string label = w.m_label + " "; 00023 out << left << setw(15) << label; 00024 return out; 00025 } 00026 00027 ostream& operator<<(ostream& out, const SgWriteLine &w) 00028 { 00029 SG_UNUSED(w); 00030 out << 00031 "----------" 00032 "----------" 00033 "----------" 00034 "----------" 00035 "----------" 00036 "----------" 00037 "----------" 00038 "--------\n"; // 78 chars 00039 return out; 00040 } 00041 00042 //---------------------------------------------------------------------------- 00043 00044 ostream& operator<<(ostream& out, const SgWriteMove& w) 00045 { 00046 out << SgBW(w.m_color) << ' ' << SgWritePoint(w.m_point) << ' '; 00047 return out; 00048 } 00049 00050 //---------------------------------------------------------------------------- 00051 00052 SgWritePointList::SgWritePointList(const vector<SgPoint>& pointList, 00053 std::string label, bool writeSize) 00054 : m_writeSize(writeSize), 00055 m_pointList(pointList), 00056 m_label(label) 00057 { 00058 } 00059 00060 SgWritePointList::SgWritePointList(const SgVector<SgPoint>& pointList, 00061 string label, bool writeSize) 00062 : m_writeSize(writeSize), 00063 m_label(label) 00064 { 00065 for (SgVectorIterator<SgPoint> it(pointList); it; ++it) 00066 m_pointList.push_back(*it); 00067 } 00068 00069 ostream& SgWritePointList::Write(ostream& out) const 00070 { 00071 const size_t charPerLine = 60; 00072 size_t size = m_pointList.size(); 00073 if (m_label != "") 00074 out << SgWriteLabel(m_label); 00075 ostringstream buffer; 00076 if (m_writeSize) 00077 buffer << size; 00078 if (size > 0) 00079 { 00080 if (m_writeSize) 00081 buffer << " "; 00082 for (vector<SgPoint>::const_iterator it = m_pointList.begin(); 00083 it != m_pointList.end(); ++it) 00084 { 00085 if (buffer.str().size() > charPerLine) 00086 { 00087 out << buffer.str() << '\n'; 00088 buffer.str(""); 00089 if (m_label != "") 00090 out << SgWriteLabel(""); 00091 } 00092 buffer << SgWritePoint(*it) << ' '; 00093 } 00094 } 00095 out << buffer.str() << '\n'; 00096 return out; 00097 } 00098 00099 ostream& operator<<(ostream& out, const SgWritePointList& write) 00100 { 00101 return write.Write(out); 00102 } 00103 00104 ostream& operator<<(ostream& out, const SgWriteBoolean &w) 00105 { 00106 if (w.m_value) 00107 out << "true"; 00108 else 00109 out << "false"; 00110 return out; 00111 } 00112 00113 //---------------------------------------------------------------------------- 00114 00115 SgWriteBoolAsInt::SgWriteBoolAsInt(bool value) 00116 : m_value(value) 00117 { 00118 } 00119 00120 ostream& SgWriteBoolAsInt::Write(ostream& out) const 00121 { 00122 return out << (m_value ? "1" : "0"); 00123 } 00124 00125 ostream& operator<<(ostream& out, const SgWriteBoolAsInt& write) 00126 { 00127 return write.Write(out); 00128 } 00129 00130 //---------------------------------------------------------------------------- 00131