Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgWrite.cpp

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


Sun Mar 13 2011 Doxygen 1.7.1