00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #include <ndb_global.h> 00018 00019 #include <NdbOut.hpp> 00020 #include <OutputStream.hpp> 00021 00022 static FileOutputStream ndbouts_fileoutputstream(stdout); 00023 NdbOut ndbout(ndbouts_fileoutputstream); 00024 00025 static const char * fms[] = { 00026 "%d", "0x%02x", // Int8 00027 "%u", "0x%02x", // Uint8 00028 "%d", "0x%04x", // Int16 00029 "%u", "0x%04x", // Uint16 00030 "%d", "0x%08x", // Int32 00031 "%u", "0x%08x", // Uint32 00032 "%lld", "0x%016llx", // Int64 00033 "%llu", "0x%016llx" // Uint64 00034 "%llu", "0x%016llx" // UintPtr 00035 }; 00036 00037 NdbOut& 00038 NdbOut::operator<<(Int8 v) { m_out->print(fms[0+isHex],(int)v); return *this;} 00039 NdbOut& 00040 NdbOut::operator<<(Uint8 v) { m_out->print(fms[2+isHex],(int)v); return *this;} 00041 NdbOut& 00042 NdbOut::operator<<(Int16 v) { m_out->print(fms[4+isHex],(int)v); return *this;} 00043 NdbOut& 00044 NdbOut::operator<<(Uint16 v) { m_out->print(fms[6+isHex],(int)v); return *this;} 00045 NdbOut& 00046 NdbOut::operator<<(Int32 v) { m_out->print(fms[8+isHex], v); return *this;} 00047 NdbOut& 00048 NdbOut::operator<<(Uint32 v) { m_out->print(fms[10+isHex], v); return *this;} 00049 NdbOut& 00050 NdbOut::operator<<(Int64 v) { m_out->print(fms[12+isHex], v); return *this;} 00051 NdbOut& 00052 NdbOut::operator<<(Uint64 v) { m_out->print(fms[14+isHex], v); return *this;} 00053 NdbOut& 00054 NdbOut::operator<<(unsigned long int v) { return *this << (Uint64) v; } 00055 00056 NdbOut& 00057 NdbOut::operator<<(const char* val){ m_out->print("%s", val ? val : "(null)"); return * this; } 00058 NdbOut& 00059 NdbOut::operator<<(const void* val){ m_out->print("%p", val); return * this; } 00060 NdbOut& 00061 NdbOut::operator<<(BaseString &val){ return *this << val.c_str(); } 00062 00063 NdbOut& 00064 NdbOut::operator<<(float val){ m_out->print("%f", (double)val); return * this;} 00065 NdbOut& 00066 NdbOut::operator<<(double val){ m_out->print("%f", val); return * this; } 00067 00068 NdbOut& NdbOut::endline() 00069 { 00070 isHex = 0; // Reset hex to normal, if user forgot this 00071 m_out->println(""); 00072 m_out->flush(); 00073 return *this; 00074 } 00075 00076 NdbOut& NdbOut::flushline() 00077 { 00078 m_out->flush(); 00079 return *this; 00080 } 00081 00082 NdbOut& NdbOut::setHexFormat(int _format) 00083 { 00084 isHex = (_format == 0 ? 0 : 1); 00085 return *this; 00086 } 00087 00088 NdbOut::NdbOut(OutputStream & out) 00089 : m_out(& out) 00090 { 00091 isHex = 0; 00092 } 00093 00094 NdbOut::~NdbOut() 00095 { 00096 } 00097 00098 void 00099 NdbOut::print(const char * fmt, ...){ 00100 va_list ap; 00101 char buf[1000]; 00102 00103 va_start(ap, fmt); 00104 if (fmt != 0) 00105 BaseString::vsnprintf(buf, sizeof(buf)-1, fmt, ap); 00106 ndbout << buf; 00107 va_end(ap); 00108 } 00109 00110 void 00111 NdbOut::println(const char * fmt, ...){ 00112 va_list ap; 00113 char buf[1000]; 00114 00115 va_start(ap, fmt); 00116 if (fmt != 0) 00117 BaseString::vsnprintf(buf, sizeof(buf)-1, fmt, ap); 00118 ndbout << buf << endl; 00119 va_end(ap); 00120 } 00121 00122 extern "C" 00123 void 00124 ndbout_c(const char * fmt, ...){ 00125 va_list ap; 00126 char buf[1000]; 00127 00128 va_start(ap, fmt); 00129 if (fmt != 0) 00130 BaseString::vsnprintf(buf, sizeof(buf)-1, fmt, ap); 00131 ndbout << buf << endl; 00132 va_end(ap); 00133 } 00134 00135 FilteredNdbOut::FilteredNdbOut(OutputStream & out, 00136 int threshold, int level) 00137 : NdbOut(out) { 00138 m_level = level; 00139 m_threshold = threshold; 00140 m_org = &out; 00141 m_null = new NullOutputStream(); 00142 setLevel(level); 00143 } 00144 00145 FilteredNdbOut::~FilteredNdbOut(){ 00146 delete m_null; 00147 } 00148 00149 void 00150 FilteredNdbOut::setLevel(int i){ 00151 m_level = i; 00152 if(m_level >= m_threshold){ 00153 m_out = m_org; 00154 } else { 00155 m_out = m_null; 00156 } 00157 } 00158 00159 void 00160 FilteredNdbOut::setThreshold(int i){ 00161 m_threshold = i; 00162 setLevel(m_level); 00163 } 00164 00165 int 00166 FilteredNdbOut::getLevel() const { 00167 return m_level; 00168 } 00169 int 00170 FilteredNdbOut::getThreshold() const { 00171 return m_threshold; 00172 } 00173
1.4.7

