TuplePrinter.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/tuple/TuplePrinter.cpp#10 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2003-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/tuple/TuplePrinter.h"
00026 #include "fennel/tuple/TupleDescriptor.h"
00027 
00028 #include <boost/io/ios_state.hpp>
00029 
00030 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/tuple/TuplePrinter.cpp#10 $");
00031 
00032 TuplePrinter::TuplePrinter()
00033 {
00034     pStream = NULL;
00035 }
00036 
00037 void TuplePrinter::print(
00038     std::ostream &stream,
00039     TupleDescriptor const &tupleDesc,
00040     TupleData const &tupleData)
00041 {
00042     boost::io::ios_all_saver streamStateSaver(stream);
00043     pStream = &stream;
00044     iValue = 0;
00045     (*pStream) << "[ ";
00046     tupleDesc.visit(tupleData,*this,false);
00047     (*pStream) << " ]";
00048     pStream = NULL;
00049 }
00050 
00051 void TuplePrinter::preVisitValue()
00052 {
00053     if (iValue) {
00054         (*pStream) << ", ";
00055     }
00056 }
00057 
00058 void TuplePrinter::postVisitValue()
00059 {
00060     ++iValue;
00061 }
00062 
00063 void TuplePrinter::visitString(std::string s)
00064 {
00065     preVisitValue();
00066     // TODO:  escaping
00067     (*pStream) << "'" << s << "'";
00068     postVisitValue();
00069 }
00070 
00071 void TuplePrinter::visitChars(char const *c, TupleStorageByteLength n)
00072 {
00073     std::string s(c,n);
00074     visitString(s);
00075 }
00076 
00077 void TuplePrinter::visitUnicodeChars(Ucs2ConstBuffer c, uint n)
00078 {
00079     // TODO jvs 13-Jan-2009:  something prettier
00080     visitBytes(c, n*2);
00081 }
00082 
00083 void TuplePrinter::visitUnsignedInt(uint64_t i)
00084 {
00085     preVisitValue();
00086     (*pStream) << i;
00087     postVisitValue();
00088 }
00089 
00090 void TuplePrinter::visitSignedInt(int64_t i)
00091 {
00092     preVisitValue();
00093     // FIXME:  this comes out as garbage for the smallest negative value; not
00094     // sure why
00095     (*pStream) << i;
00096     postVisitValue();
00097 }
00098 
00099 void TuplePrinter::visitDouble(double d)
00100 {
00101     preVisitValue();
00102     (*pStream) << d;
00103     postVisitValue();
00104 }
00105 
00106 void TuplePrinter::visitFloat(float f)
00107 {
00108     preVisitValue();
00109     (*pStream) << f;
00110     postVisitValue();
00111 }
00112 
00113 void TuplePrinter::visitBoolean(bool b)
00114 {
00115     preVisitValue();
00116     if (b) {
00117         (*pStream) << "true";
00118     } else {
00119         (*pStream) << "false";
00120     }
00121     postVisitValue();
00122 }
00123 
00124 void TuplePrinter::visitBytes(void const *v, TupleStorageByteLength iBytes)
00125 {
00126     preVisitValue();
00127     if (!v) {
00128         (*pStream) << "NULL";
00129     } else {
00130         hexDump(*pStream,v,iBytes);
00131     }
00132     postVisitValue();
00133 }
00134 
00135 void TuplePrinter::preVisitDocument(std::string)
00136 {
00137     // unused
00138 }
00139 
00140 void TuplePrinter::postVisitDocument()
00141 {
00142     // unused
00143 }
00144 
00145 void TuplePrinter::preVisitTable(std::string)
00146 {
00147     // unused
00148 }
00149 
00150 void TuplePrinter::postVisitTable()
00151 {
00152     // unused
00153 }
00154 
00155 void TuplePrinter::preVisitRow()
00156 {
00157     // unused
00158 }
00159 
00160 void TuplePrinter::postVisitRow()
00161 {
00162     // unused
00163 }
00164 
00165 void TuplePrinter::visitAttribute(std::string)
00166 {
00167     // unused
00168 }
00169 
00170 void TuplePrinter::visitPageId(PageId)
00171 {
00172     // unused
00173 }
00174 
00175 void TuplePrinter::visitPageOwnerId(PageOwnerId)
00176 {
00177     // unused
00178 }
00179 
00180 void TuplePrinter::visitSegByteId(SegByteId)
00181 {
00182     // unused
00183 }
00184 
00185 void TuplePrinter::visitFormatted(char const *)
00186 {
00187     // unused
00188 }
00189 
00190 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/tuple/TuplePrinter.cpp#10 $");
00191 
00192 // End TuplePrinter.cpp

Generated on Mon Jun 22 04:00:21 2009 for Fennel by  doxygen 1.5.1