MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbOut.hpp
1 /*
2  Copyright (C) 2003, 2005, 2006, 2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef NDBOUT_H
20 #define NDBOUT_H
21 
22 #ifdef __cplusplus
23 
24 #include <ndb_types.h>
25 #include <util/BaseString.hpp>
26 #include <ndb_global.h>
27 
34 /*
35  Example usage:
36 
37  #include "NdbOut.hpp"
38 
39  / * Use ndbout as you would use cout:
40 
41  ndbout << "Hello World! "<< 1 << " Hello again"
42  << 67 << anIntegerVar << "Hup << endl;
43 
44 
45  / * Use ndbout_c as you would use printf:
46 
47  ndbout_c("Hello World %d\n", 1);
48 */
49 
50 class NdbOut;
51 class OutputStream;
52 class NullOutputStream;
53 
54 /* Declare a static variable of NdbOut as ndbout */
55 extern NdbOut ndbout, ndberr;
56 
57 class NdbOut
58 {
59 public:
60  NdbOut& operator<<(NdbOut& (* _f)(NdbOut&));
61  NdbOut& operator<<(Int8);
62  NdbOut& operator<<(Uint8);
63  NdbOut& operator<<(Int16);
64  NdbOut& operator<<(Uint16);
65  NdbOut& operator<<(Int32);
66  NdbOut& operator<<(Uint32);
67  NdbOut& operator<<(Int64);
68  NdbOut& operator<<(Uint64);
69  NdbOut& operator<<(long unsigned int);
70  NdbOut& operator<<(const char*);
71  NdbOut& operator<<(const unsigned char*);
72  NdbOut& operator<<(BaseString &);
73  NdbOut& operator<<(const void*);
74  NdbOut& operator<<(float);
75  NdbOut& operator<<(double);
76  NdbOut& endline(void);
77  NdbOut& flushline(void);
78  NdbOut& setHexFormat(int _format);
79 
80  NdbOut();
81  NdbOut(OutputStream &, bool autoflush = true);
82  virtual ~NdbOut();
83 
84  void print(const char * fmt, ...)
85  ATTRIBUTE_FORMAT(printf, 2, 3);
86  void println(const char * fmt, ...)
87  ATTRIBUTE_FORMAT(printf, 2, 3);
88 
89  OutputStream * m_out;
90 private:
91  void choose(const char * fmt,...);
92  int isHex;
93  bool m_autoflush;
94 };
95 
96 #ifdef NDB_WIN
97 typedef int(*NdbOutF)(char*);
98 extern NdbOutF ndbout_svc;
99 #endif
100 
101 inline NdbOut& NdbOut::operator<<(NdbOut& (* _f)(NdbOut&)) {
102  (* _f)(*this);
103  return * this;
104 }
105 
106 inline NdbOut& endl(NdbOut& _NdbOut) {
107  return _NdbOut.endline();
108 }
109 
110 inline NdbOut& flush(NdbOut& _NdbOut) {
111  return _NdbOut.flushline();
112 }
113 
114 inline NdbOut& hex(NdbOut& _NdbOut) {
115  return _NdbOut.setHexFormat(1);
116 }
117 
118 inline NdbOut& dec(NdbOut& _NdbOut) {
119  return _NdbOut.setHexFormat(0);
120 }
121 extern "C"
122 void ndbout_c(const char * fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
123 extern "C"
124 void vndbout_c(const char * fmt, va_list ap);
125 
126 class FilteredNdbOut : public NdbOut {
127 public:
128  FilteredNdbOut(OutputStream &, int threshold = 0, int level = 0);
129  virtual ~FilteredNdbOut();
130 
131  void setLevel(int i);
132  void setThreshold(int i);
133 
134  int getLevel() const;
135  int getThreshold() const;
136 
137 private:
138  int m_threshold, m_level;
139  OutputStream * m_org;
140  NullOutputStream * m_null;
141 };
142 
143 #else
144 void ndbout_c(const char * fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
145 #endif
146 
147 #endif