Apache Log4cxx Version 1.0.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
25namespace log4cxx
26{
27
28
29namespace helpers
30{
31
32typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
33
39class LOG4CXX_EXPORT CharMessageBuffer
40{
41 public:
50
51
57 CharMessageBuffer& operator<<(const std::basic_string<char>& msg);
63 CharMessageBuffer& operator<<(const char* msg);
70
76 CharMessageBuffer& operator<<(const char msg);
77
83 std::ostream& operator<<(ios_base_manip manip);
89 std::ostream& operator<<(bool val);
90
96 std::ostream& operator<<(short val);
102 std::ostream& operator<<(int val);
108 std::ostream& operator<<(unsigned int val);
114 std::ostream& operator<<(long val);
120 std::ostream& operator<<(unsigned long val);
126 std::ostream& operator<<(float val);
132 std::ostream& operator<<(double val);
138 std::ostream& operator<<(long double val);
144 std::ostream& operator<<(void* val);
145
149 operator std::basic_ostream<char>& ();
150
156 const std::basic_string<char>& str(std::basic_ostream<char>& os);
157
163 const std::basic_string<char>& str(CharMessageBuffer& buf);
164
169 bool hasStream() const;
170
171 private:
179 CharMessageBuffer& operator=(const CharMessageBuffer&);
180
181 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(CharMessageBufferPrivate, m_priv)
182};
183
184template<class V>
185std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val)
186{
187 return ((std::basic_ostream<char>&) os) << val;
188}
189
190#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR
196class LOG4CXX_EXPORT UniCharMessageBuffer
197{
198 public:
207
208 typedef std::basic_ostream<UniChar> uostream;
209
210
216 UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
229
236
237#if LOG4CXX_CFSTRING_API
245#endif
246
252 uostream& operator<<(ios_base_manip manip);
259
265 uostream& operator<<(short val);
277 uostream& operator<<(unsigned int val);
289 uostream& operator<<(unsigned long val);
295 uostream& operator<<(float val);
301 uostream& operator<<(double val);
307 uostream& operator<<(long double val);
313 uostream& operator<<(void* val);
314
315
319 operator uostream& ();
320
326 const std::basic_string<UniChar>& str(uostream& os);
327
333 const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
334
339 bool hasStream() const;
340
341 private:
350
351 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(UniCharMessageBufferPrivate, m_priv)
352};
353
354template<class V>
356{
357 return ((UniCharMessageBuffer::uostream&) os) << val;
358}
359#endif
360
361#if LOG4CXX_WCHAR_T_API
367class LOG4CXX_EXPORT WideMessageBuffer
368{
369 public:
378
379
385 WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg);
391 WideMessageBuffer& operator<<(const wchar_t* msg);
398
404 WideMessageBuffer& operator<<(const wchar_t msg);
405
411 std::basic_ostream<wchar_t>& operator<<(ios_base_manip manip);
417 std::basic_ostream<wchar_t>& operator<<(bool val);
418
424 std::basic_ostream<wchar_t>& operator<<(short val);
430 std::basic_ostream<wchar_t>& operator<<(int val);
436 std::basic_ostream<wchar_t>& operator<<(unsigned int val);
442 std::basic_ostream<wchar_t>& operator<<(long val);
448 std::basic_ostream<wchar_t>& operator<<(unsigned long val);
454 std::basic_ostream<wchar_t>& operator<<(float val);
460 std::basic_ostream<wchar_t>& operator<<(double val);
466 std::basic_ostream<wchar_t>& operator<<(long double val);
472 std::basic_ostream<wchar_t>& operator<<(void* val);
473
474
478 operator std::basic_ostream<wchar_t>& ();
479
485 const std::basic_string<wchar_t>& str(std::basic_ostream<wchar_t>& os);
486
492 const std::basic_string<wchar_t>& str(WideMessageBuffer& buf);
493
498 bool hasStream() const;
499
500 private:
508 WideMessageBuffer& operator=(const WideMessageBuffer&);
509
510 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(WideMessageBufferPrivate, m_priv)
511};
512
513template<class V>
514std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val)
515{
516 return ((std::basic_ostream<wchar_t>&) os) << val;
517}
518
524class LOG4CXX_EXPORT MessageBuffer
525{
526 public:
535
539 operator std::ostream& ();
540
547 CharMessageBuffer& operator<<(const std::string& msg);
554 CharMessageBuffer& operator<<(const char* msg);
562
570
577 const std::string& str(CharMessageBuffer& buf);
578
585 const std::string& str(std::ostream& os);
586
593 WideMessageBuffer& operator<<(const std::wstring& msg);
600 WideMessageBuffer& operator<<(const wchar_t* msg);
614 WideMessageBuffer& operator<<(const wchar_t msg);
615
616#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
623 UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
645#endif
646
647#if LOG4CXX_CFSTRING_API
655#endif
656
662 std::ostream& operator<<(ios_base_manip manip);
663
669 std::ostream& operator<<(bool val);
670
676 std::ostream& operator<<(short val);
682 std::ostream& operator<<(int val);
688 std::ostream& operator<<(unsigned int val);
694 std::ostream& operator<<(long val);
700 std::ostream& operator<<(unsigned long val);
706 std::ostream& operator<<(float val);
712 std::ostream& operator<<(double val);
718 std::ostream& operator<<(long double val);
724 std::ostream& operator<<(void* val);
731 const std::wstring& str(WideMessageBuffer& buf);
732
739 const std::wstring& str(std::basic_ostream<wchar_t>& os);
740
741#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
748 const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
749
756 const std::basic_string<UniChar>& str(UniCharMessageBuffer::uostream& os);
757#endif
758
763 bool hasStream() const;
764
765 private:
773 MessageBuffer& operator=(const MessageBuffer&);
774
775 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(MessageBufferPrivate, m_priv)
776};
777
778template<class V>
779std::ostream& operator<<(MessageBuffer& os, const V& val)
780{
781 return ((std::ostream&) os) << val;
782}
783
784#if LOG4CXX_LOGCHAR_IS_UTF8
785 typedef CharMessageBuffer LogCharMessageBuffer;
786#endif
787
788#if LOG4CXX_LOGCHAR_IS_WCHAR
789 typedef WideMessageBuffer LogCharMessageBuffer;
790#endif
791
792#if LOG4CXX_LOGCHAR_IS_UNICHAR
793 typedef UniCharMessageBuffer LogCharMessageBuffer;
794#endif
795
796#else // !LOG4CXX_WCHAR_T_API
797typedef CharMessageBuffer MessageBuffer;
798typedef CharMessageBuffer LogCharMessageBuffer;
799#endif // !LOG4CXX_WCHAR_T_API
800
801}
802}
803
804#endif
805
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: messagebuffer.h:40
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:525
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:197
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:208
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:368
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:30
std::basic_ostream< char > & operator<<(CharMessageBuffer &os, const V &val)
Definition: messagebuffer.h:185
Definition: configuration.h:25
unsigned short UniChar
Definition: logstring.h:38