Apache log4cxx Version 0.13.0
Loading...
Searching...
No Matches
messagebuffer.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_MESSAGE_BUFFER_H
19#define _LOG4CXX_MESSAGE_BUFFER_H
20
21#include <log4cxx/log4cxx.h>
22#include <log4cxx/logstring.h>
23#include <sstream>
24
25#if defined(_MSC_VER)
26 #pragma warning ( push )
27 #pragma warning ( disable: 4251 4275 )
28#endif
29
30namespace log4cxx
31{
32
33
34namespace helpers
35{
36
38
39typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
40
46class LOG4CXX_EXPORT CharMessageBuffer
47{
48 public:
57
58
64 CharMessageBuffer& operator<<(const std::basic_string<char>& msg);
70 CharMessageBuffer& operator<<(const char* msg);
77
83 CharMessageBuffer& operator<<(const char msg);
84
90 std::ostream& operator<<(ios_base_manip manip);
96 std::ostream& operator<<(bool val);
97
103 std::ostream& operator<<(short val);
109 std::ostream& operator<<(int val);
115 std::ostream& operator<<(unsigned int val);
121 std::ostream& operator<<(long val);
127 std::ostream& operator<<(unsigned long val);
133 std::ostream& operator<<(float val);
139 std::ostream& operator<<(double val);
145 std::ostream& operator<<(long double val);
151 std::ostream& operator<<(void* val);
152
156 operator std::basic_ostream<char>& ();
157
163 const std::basic_string<char>& str(std::basic_ostream<char>& os);
164
170 const std::basic_string<char>& str(CharMessageBuffer& buf);
171
176 bool hasStream() const;
177
178 private:
186 CharMessageBuffer& operator=(const CharMessageBuffer&);
187
191 std::basic_string<char> buf;
195 std::basic_ostringstream<char>* stream;
196};
197
198template<class V>
199std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val)
200{
201 return ((std::basic_ostream<char>&) os) << val;
202}
203
204#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR
210class LOG4CXX_EXPORT UniCharMessageBuffer
211{
212 public:
221
222 typedef std::basic_ostream<UniChar> uostream;
223
224
230 UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
243
250
251#if LOG4CXX_CFSTRING_API
259#endif
260
266 uostream& operator<<(ios_base_manip manip);
273
279 uostream& operator<<(short val);
291 uostream& operator<<(unsigned int val);
303 uostream& operator<<(unsigned long val);
309 uostream& operator<<(float val);
315 uostream& operator<<(double val);
321 uostream& operator<<(long double val);
327 uostream& operator<<(void* val);
328
329
333 operator uostream& ();
334
340 const std::basic_string<UniChar>& str(uostream& os);
341
347 const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
348
353 bool hasStream() const;
354
355 private:
364
368 std::basic_string<UniChar> buf;
372 std::basic_ostringstream<UniChar>* stream;
373};
374
375template<class V>
377{
378 return ((UniCharMessageBuffer::uostream&) os) << val;
379}
380#endif
381
382#if LOG4CXX_WCHAR_T_API
388class LOG4CXX_EXPORT WideMessageBuffer
389{
390 public:
399
400
406 WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg);
412 WideMessageBuffer& operator<<(const wchar_t* msg);
419
425 WideMessageBuffer& operator<<(const wchar_t msg);
426
432 std::basic_ostream<wchar_t>& operator<<(ios_base_manip manip);
438 std::basic_ostream<wchar_t>& operator<<(bool val);
439
445 std::basic_ostream<wchar_t>& operator<<(short val);
451 std::basic_ostream<wchar_t>& operator<<(int val);
457 std::basic_ostream<wchar_t>& operator<<(unsigned int val);
463 std::basic_ostream<wchar_t>& operator<<(long val);
469 std::basic_ostream<wchar_t>& operator<<(unsigned long val);
475 std::basic_ostream<wchar_t>& operator<<(float val);
481 std::basic_ostream<wchar_t>& operator<<(double val);
487 std::basic_ostream<wchar_t>& operator<<(long double val);
493 std::basic_ostream<wchar_t>& operator<<(void* val);
494
495
499 operator std::basic_ostream<wchar_t>& ();
500
506 const std::basic_string<wchar_t>& str(std::basic_ostream<wchar_t>& os);
507
513 const std::basic_string<wchar_t>& str(WideMessageBuffer& buf);
514
519 bool hasStream() const;
520
521 private:
529 WideMessageBuffer& operator=(const WideMessageBuffer&);
530
534 std::basic_string<wchar_t> buf;
538 std::basic_ostringstream<wchar_t>* stream;
539};
540
541template<class V>
542std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val)
543{
544 return ((std::basic_ostream<wchar_t>&) os) << val;
545}
546
552class LOG4CXX_EXPORT MessageBuffer
553{
554 public:
563
567 operator std::ostream& ();
568
575 CharMessageBuffer& operator<<(const std::string& msg);
582 CharMessageBuffer& operator<<(const char* msg);
590
598
605 const std::string& str(CharMessageBuffer& buf);
606
613 const std::string& str(std::ostream& os);
614
621 WideMessageBuffer& operator<<(const std::wstring& msg);
628 WideMessageBuffer& operator<<(const wchar_t* msg);
642 WideMessageBuffer& operator<<(const wchar_t msg);
643
644#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
651 UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
673#endif
674
675#if LOG4CXX_CFSTRING_API
683#endif
684
690 std::ostream& operator<<(ios_base_manip manip);
691
697 std::ostream& operator<<(bool val);
698
704 std::ostream& operator<<(short val);
710 std::ostream& operator<<(int val);
716 std::ostream& operator<<(unsigned int val);
722 std::ostream& operator<<(long val);
728 std::ostream& operator<<(unsigned long val);
734 std::ostream& operator<<(float val);
740 std::ostream& operator<<(double val);
746 std::ostream& operator<<(long double val);
752 std::ostream& operator<<(void* val);
759 const std::wstring& str(WideMessageBuffer& buf);
760
767 const std::wstring& str(std::basic_ostream<wchar_t>& os);
768
769#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
776 const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
777
784 const std::basic_string<UniChar>& str(UniCharMessageBuffer::uostream& os);
785#endif
786
791 bool hasStream() const;
792
793 private:
801 MessageBuffer& operator=(const MessageBuffer&);
802
807
811 WideMessageBuffer* wbuf;
812#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
817#endif
818};
819
820template<class V>
821std::ostream& operator<<(MessageBuffer& os, const V& val)
822{
823 return ((std::ostream&) os) << val;
824}
825
826#if LOG4CXX_LOGCHAR_IS_UTF8
827 typedef CharMessageBuffer LogCharMessageBuffer;
828#endif
829
830#if LOG4CXX_LOGCHAR_IS_WCHAR
831 typedef WideMessageBuffer LogCharMessageBuffer;
832#endif
833
834#if LOG4CXX_LOGCHAR_IS_UNICHAR
835 typedef UniCharMessageBuffer LogCharMessageBuffer;
836#endif
837
838#else
839typedef CharMessageBuffer MessageBuffer;
840typedef CharMessageBuffer LogCharMessageBuffer;
841#endif
842
843}
844}
845
846#if defined(_MSC_VER)
847 #pragma warning (pop)
848#endif
849
850#endif
851
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: messagebuffer.h:47
CharMessageBuffer & operator<<(char *msg)
Appends string to buffer.
std::ostream & operator<<(short val)
Insertion operator for built-in type.
std::ostream & operator<<(bool val)
Insertion operator for built-in type.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
CharMessageBuffer & operator<<(const std::basic_string< char > &msg)
Appends string to buffer.
CharMessageBuffer()
Creates a new instance.
std::ostream & operator<<(float val)
Insertion operator for built-in type.
CharMessageBuffer & operator<<(const char *msg)
Appends string to buffer.
std::ostream & operator<<(ios_base_manip manip)
Insertion operator for STL manipulators such as std::fixed.
std::ostream & operator<<(long double val)
Insertion operator for built-in type.
std::ostream & operator<<(double val)
Insertion operator for built-in type.
CharMessageBuffer & operator<<(const char msg)
Appends character to buffer.
std::ostream & operator<<(unsigned long val)
Insertion operator for built-in type.
std::ostream & operator<<(int val)
Insertion operator for built-in type.
const std::basic_string< char > & str(CharMessageBuffer &buf)
Get content of buffer.
std::ostream & operator<<(long val)
Insertion operator for built-in type.
std::ostream & operator<<(void *val)
Insertion operator for built-in type.
std::ostream & operator<<(unsigned int val)
Insertion operator for built-in type.
const std::basic_string< char > & str(std::basic_ostream< char > &os)
Get content of buffer.
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: messagebuffer.h:553
const std::wstring & str(WideMessageBuffer &buf)
Get content of buffer.
WideMessageBuffer & operator<<(const wchar_t *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
WideMessageBuffer & operator<<(wchar_t *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::ostream & operator<<(short val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(const UniChar *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
WideMessageBuffer & operator<<(const wchar_t msg)
Appends a string into the buffer and fixes the buffer to use char characters.
CharMessageBuffer & operator<<(const char *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::ostream & operator<<(float val)
Insertion operator for built-in type.
WideMessageBuffer & operator<<(const std::wstring &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::ostream & operator<<(unsigned long val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(UniChar *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::ostream & operator<<(long val)
Insertion operator for built-in type.
std::ostream & operator<<(unsigned int val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(const UniChar msg)
Appends a string into the buffer and fixes the buffer to use char characters.
CharMessageBuffer & operator<<(char *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
const std::basic_string< UniChar > & str(UniCharMessageBuffer &buf)
Get content of buffer.
std::ostream & operator<<(double val)
Insertion operator for built-in type.
std::ostream & operator<<(long double val)
Insertion operator for built-in type.
MessageBuffer()
Creates a new instance.
std::ostream & operator<<(int val)
Insertion operator for built-in type.
std::ostream & operator<<(bool val)
Insertion operator for built-in type.
const std::string & str(CharMessageBuffer &buf)
Get content of buffer.
const std::string & str(std::ostream &os)
Get content of buffer.
std::ostream & operator<<(ios_base_manip manip)
Insertion operator for STL manipulators such as std::fixed.
UniCharMessageBuffer & operator<<(const CFStringRef &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::ostream & operator<<(void *val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(const std::basic_string< UniChar > &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
const std::wstring & str(std::basic_ostream< wchar_t > &os)
Get content of buffer.
CharMessageBuffer & operator<<(const std::string &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
CharMessageBuffer & operator<<(const char msg)
Appends a string into the buffer and fixes the buffer to use char characters.
const std::basic_string< UniChar > & str(UniCharMessageBuffer::uostream &os)
Get content of buffer.
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition: messagebuffer.h:211
const std::basic_string< UniChar > & str(uostream &os)
Get content of buffer.
uostream & operator<<(long val)
Insertion operator for built-in type.
std::basic_ostream< UniChar > uostream
Definition: messagebuffer.h:222
uostream & operator<<(float val)
Insertion operator for built-in type.
UniCharMessageBuffer()
Creates a new instance.
uostream & operator<<(ios_base_manip manip)
Insertion operator for STL manipulators such as std::fixed.
UniCharMessageBuffer & operator<<(const std::basic_string< UniChar > &msg)
Appends string to buffer.
UniCharMessageBuffer & operator<<(const CFStringRef &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
uostream & operator<<(int val)
Insertion operator for built-in type.
uostream & operator<<(unsigned int val)
Insertion operator for built-in type.
uostream & operator<<(bool val)
Insertion operator for built-in type.
uostream & operator<<(unsigned long val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(UniChar *msg)
Appends string to buffer.
UniCharMessageBuffer & operator<<(const UniChar msg)
Appends character to buffer.
uostream & operator<<(void *val)
Insertion operator for built-in type.
uostream & operator<<(short val)
Insertion operator for built-in type.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
UniCharMessageBuffer & operator<<(const UniChar *msg)
Appends string to buffer.
uostream & operator<<(long double val)
Insertion operator for built-in type.
const std::basic_string< UniChar > & str(UniCharMessageBuffer &buf)
Get content of buffer.
uostream & operator<<(double val)
Insertion operator for built-in type.
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition: messagebuffer.h:389
WideMessageBuffer & operator<<(const wchar_t *msg)
Appends string to buffer.
WideMessageBuffer()
Creates a new instance.
const std::basic_string< wchar_t > & str(WideMessageBuffer &buf)
Get content of buffer.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
WideMessageBuffer & operator<<(const wchar_t msg)
Appends character to buffer.
WideMessageBuffer & operator<<(const std::basic_string< wchar_t > &msg)
Appends string to buffer.
WideMessageBuffer & operator<<(wchar_t *msg)
Appends string to buffer.
const std::basic_string< wchar_t > & str(std::basic_ostream< wchar_t > &os)
Get content of buffer.
const struct __CFString * CFStringRef
Definition: logstring.h:36
void MessageBufferUseStaticStream()
std::basic_ostream< char > & operator<<(CharMessageBuffer &os, const V &val)
Definition: messagebuffer.h:199
Definition: messagehandler.h:23
unsigned short UniChar
Definition: logstring.h:44