1 /* Copyright (c) 2003-2005, 2008 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #include <ndb_global.h>
19 #include <OutputStream.hpp>
21 static FileOutputStream
ndbouts_fileoutputstream(stdout
);
22 NdbOut
ndbout(ndbouts_fileoutputstream
);
24 static const char * fms
[] = {
25 "%d", "0x%02x", // Int8
26 "%u", "0x%02x", // Uint8
27 "%d", "0x%04x", // Int16
28 "%u", "0x%04x", // Uint16
29 "%d", "0x%08x", // Int32
30 "%u", "0x%08x", // Uint32
31 "%lld", "0x%016llx", // Int64
32 "%llu", "0x%016llx", // Uint64
33 "%llu", "0x%016llx" // UintPtr
37 NdbOut::operator<<(Int8 v
) { m_out
->print(fms
[0+isHex
],(int)v
); return *this;}
39 NdbOut::operator<<(Uint8 v
) { m_out
->print(fms
[2+isHex
],(int)v
); return *this;}
41 NdbOut::operator<<(Int16 v
) { m_out
->print(fms
[4+isHex
],(int)v
); return *this;}
43 NdbOut::operator<<(Uint16 v
) { m_out
->print(fms
[6+isHex
],(int)v
); return *this;}
45 NdbOut::operator<<(Int32 v
) { m_out
->print(fms
[8+isHex
], v
); return *this;}
47 NdbOut::operator<<(Uint32 v
) { m_out
->print(fms
[10+isHex
], v
); return *this;}
49 NdbOut::operator<<(Int64 v
) { m_out
->print(fms
[12+isHex
], v
); return *this;}
51 NdbOut::operator<<(Uint64 v
) { m_out
->print(fms
[14+isHex
], v
); return *this;}
53 NdbOut::operator<<(unsigned long int v
) { return *this << (Uint64
) v
; }
56 NdbOut::operator<<(const char* val
){ m_out
->print("%s", val
? val
: "(null)"); return * this; }
58 NdbOut::operator<<(const void* val
){ m_out
->print("%p", val
); return * this; }
60 NdbOut::operator<<(BaseString
&val
){ return *this << val
.c_str(); }
63 NdbOut::operator<<(float val
){ m_out
->print("%f", (double)val
); return * this;}
65 NdbOut::operator<<(double val
){ m_out
->print("%f", val
); return * this; }
67 NdbOut
& NdbOut::endline()
69 isHex
= 0; // Reset hex to normal, if user forgot this
75 NdbOut
& NdbOut::flushline()
81 NdbOut
& NdbOut::setHexFormat(int _format
)
83 isHex
= (_format
== 0 ? 0 : 1);
87 NdbOut::NdbOut(OutputStream
& out
)
98 NdbOut::print(const char * fmt
, ...){
104 BaseString::vsnprintf(buf
, sizeof(buf
)-1, fmt
, ap
);
110 NdbOut::println(const char * fmt
, ...){
116 BaseString::vsnprintf(buf
, sizeof(buf
)-1, fmt
, ap
);
117 ndbout
<< buf
<< endl
;
123 ndbout_c(const char * fmt
, ...){
129 BaseString::vsnprintf(buf
, sizeof(buf
)-1, fmt
, ap
);
130 ndbout
<< buf
<< endl
;
134 FilteredNdbOut::FilteredNdbOut(OutputStream
& out
,
135 int threshold
, int level
)
138 m_threshold
= threshold
;
140 m_null
= new NullOutputStream();
144 FilteredNdbOut::~FilteredNdbOut(){
149 FilteredNdbOut::setLevel(int i
){
151 if(m_level
>= m_threshold
){
159 FilteredNdbOut::setThreshold(int i
){
165 FilteredNdbOut::getLevel() const {
169 FilteredNdbOut::getThreshold() const {