Apache Log4cxx  Version 1.3.1
log4cxx/helpers/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 namespace LOG4CXX_NS
26 {
27 
28 
29 namespace helpers
30 {
31 
32 typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
33 
39 class 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 #if LOG4CXX_CFSTRING_API
85 #endif
86 
92  std::ostream& operator<<(ios_base_manip manip);
98  std::ostream& operator<<(bool val);
99 
105  std::ostream& operator<<(short val);
111  std::ostream& operator<<(int val);
117  std::ostream& operator<<(unsigned int val);
123  std::ostream& operator<<(long val);
129  std::ostream& operator<<(unsigned long val);
135  std::ostream& operator<<(float val);
141  std::ostream& operator<<(double val);
147  std::ostream& operator<<(long double val);
153  std::ostream& operator<<(void* val);
154 
158  operator std::basic_ostream<char>& ();
159 
165  std::basic_string<char> extract_str(std::basic_ostream<char>& os);
166 
172  std::basic_string<char> extract_str(CharMessageBuffer& buf);
173 
179  const std::basic_string<char>& str(std::basic_ostream<char>& os);
180 
186  const std::basic_string<char>& str(CharMessageBuffer& buf);
187 
192  bool hasStream() const;
193 
194  private:
202  CharMessageBuffer& operator=(const CharMessageBuffer&);
203 
204  LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(CharMessageBufferPrivate, m_priv)
205 };
206 
207 template<class V>
208 std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val)
209 {
210  return ((std::basic_ostream<char>&) os) << val;
211 }
212 
213 #if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
219 class LOG4CXX_EXPORT UniCharMessageBuffer
220 {
221  public:
230 
231  typedef std::basic_ostream<UniChar> uostream;
232 
233 
239  UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
252 
259 
260 #if LOG4CXX_CFSTRING_API
268 #endif
269 
281  uostream& operator<<(bool val);
282 
288  uostream& operator<<(short val);
294  uostream& operator<<(int val);
300  uostream& operator<<(unsigned int val);
306  uostream& operator<<(long val);
312  uostream& operator<<(unsigned long val);
318  uostream& operator<<(float val);
324  uostream& operator<<(double val);
330  uostream& operator<<(long double val);
336  uostream& operator<<(void* val);
337 
338 
342  operator uostream& ();
343 
349  std::basic_string<UniChar> extract_str(uostream& os);
350 
356  std::basic_string<UniChar> extract_str(UniCharMessageBuffer& buf);
357 
363  const std::basic_string<UniChar>& str(uostream& os);
364 
370  const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
371 
376  bool hasStream() const;
377 
378  private:
386  UniCharMessageBuffer& operator=(const UniCharMessageBuffer&);
387 
388  LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(UniCharMessageBufferPrivate, m_priv)
389 };
390 
391 template<class V>
393 {
394  return ((UniCharMessageBuffer::uostream&) os) << val;
395 }
396 #endif
397 
398 #if LOG4CXX_WCHAR_T_API
404 class LOG4CXX_EXPORT WideMessageBuffer
405 {
406  public:
415 
416 
422  WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg);
428  WideMessageBuffer& operator<<(const wchar_t* msg);
435 
441  WideMessageBuffer& operator<<(const wchar_t msg);
442 
448  std::basic_ostream<wchar_t>& operator<<(ios_base_manip manip);
454  std::basic_ostream<wchar_t>& operator<<(bool val);
455 
461  std::basic_ostream<wchar_t>& operator<<(short val);
467  std::basic_ostream<wchar_t>& operator<<(int val);
473  std::basic_ostream<wchar_t>& operator<<(unsigned int val);
479  std::basic_ostream<wchar_t>& operator<<(long val);
485  std::basic_ostream<wchar_t>& operator<<(unsigned long val);
491  std::basic_ostream<wchar_t>& operator<<(float val);
497  std::basic_ostream<wchar_t>& operator<<(double val);
503  std::basic_ostream<wchar_t>& operator<<(long double val);
509  std::basic_ostream<wchar_t>& operator<<(void* val);
510 
511 
515  operator std::basic_ostream<wchar_t>& ();
516 
522  std::basic_string<wchar_t> extract_str(std::basic_ostream<wchar_t>& os);
523 
529  std::basic_string<wchar_t> extract_str(WideMessageBuffer& buf);
530 
536  const std::basic_string<wchar_t>& str(std::basic_ostream<wchar_t>& os);
537 
543  const std::basic_string<wchar_t>& str(WideMessageBuffer& buf);
544 
549  bool hasStream() const;
550 
551  private:
559  WideMessageBuffer& operator=(const WideMessageBuffer&);
560 
561  LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(WideMessageBufferPrivate, m_priv)
562 };
563 
564 template<class V>
565 std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val)
566 {
567  return ((std::basic_ostream<wchar_t>&) os) << val;
568 }
569 
575 class LOG4CXX_EXPORT MessageBuffer
576 {
577  public:
586 
590  operator std::ostream& ();
591 
598  CharMessageBuffer& operator<<(const std::string& msg);
605  CharMessageBuffer& operator<<(const char* msg);
613 
620  CharMessageBuffer& operator<<(const char msg);
621 
628  std::string extract_str(CharMessageBuffer& buf);
629 
636  std::string extract_str(std::ostream& os);
637 
644  const std::string& str(CharMessageBuffer& buf);
645 
652  const std::string& str(std::ostream& os);
653 
660  WideMessageBuffer& operator<<(const std::wstring& msg);
667  WideMessageBuffer& operator<<(const wchar_t* msg);
681  WideMessageBuffer& operator<<(const wchar_t msg);
682 
683 #if LOG4CXX_UNICHAR_API
690  UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
712 
718  std::basic_string<UniChar> extract_str(UniCharMessageBuffer& buf);
719 
725  std::basic_string<UniChar> extract_str(std::basic_ostream<UniChar>& os);
726 #endif
727 
728 #if LOG4CXX_UNICHAR_API && LOG4CXX_CFSTRING_API
736 
737 #elif LOG4CXX_CFSTRING_API
745 #endif
746 
752  std::ostream& operator<<(ios_base_manip manip);
753 
759  std::ostream& operator<<(bool val);
760 
766  std::ostream& operator<<(short val);
772  std::ostream& operator<<(int val);
778  std::ostream& operator<<(unsigned int val);
784  std::ostream& operator<<(long val);
790  std::ostream& operator<<(unsigned long val);
796  std::ostream& operator<<(float val);
802  std::ostream& operator<<(double val);
808  std::ostream& operator<<(long double val);
814  std::ostream& operator<<(void* val);
821  std::wstring extract_str(WideMessageBuffer& buf);
822 
829  std::wstring extract_str(std::basic_ostream<wchar_t>& os);
830 
837  const std::wstring& str(WideMessageBuffer& buf);
838 
845  const std::wstring& str(std::basic_ostream<wchar_t>& os);
846 
847 #if LOG4CXX_UNICHAR_API
854  const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
855 
862  const std::basic_string<UniChar>& str(UniCharMessageBuffer::uostream& os);
863 #endif
864 
869  bool hasStream() const;
870 
871  private:
879  MessageBuffer& operator=(const MessageBuffer&);
880 
881  LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(MessageBufferPrivate, m_priv)
882 };
883 
884 template<class V>
885 std::ostream& operator<<(MessageBuffer& os, const V& val)
886 {
887  return ((std::ostream&) os) << val;
888 }
889 
890 #if LOG4CXX_LOGCHAR_IS_UTF8
891  typedef CharMessageBuffer LogCharMessageBuffer;
892 #endif
893 
894 #if LOG4CXX_LOGCHAR_IS_WCHAR
895  typedef WideMessageBuffer LogCharMessageBuffer;
896 #endif
897 
898 #if LOG4CXX_LOGCHAR_IS_UNICHAR
899  typedef UniCharMessageBuffer LogCharMessageBuffer;
900 #endif
901 
902 #else // !LOG4CXX_WCHAR_T_API
903 typedef CharMessageBuffer MessageBuffer;
904 typedef CharMessageBuffer LogCharMessageBuffer;
905 #endif // !LOG4CXX_WCHAR_T_API
906 
907 }
908 }
909 
910 #endif
911 
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: log4cxx/helpers/messagebuffer.h:40
CharMessageBuffer & operator<<(const char msg)
Appends character to buffer.
CharMessageBuffer & operator<<(const CFStringRef &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.
std::ostream & operator<<(ios_base_manip manip)
Insertion operator for STL manipulators such as std::fixed.
const std::basic_string< char > & str(CharMessageBuffer &buf)
Get content of buffer.
const std::basic_string< char > & str(std::basic_ostream< char > &os)
Get content of buffer.
CharMessageBuffer & operator<<(char *msg)
Appends string to buffer.
std::ostream & operator<<(short val)
Insertion operator for built-in type.
CharMessageBuffer()
Creates a new instance.
std::ostream & operator<<(unsigned int val)
Insertion operator for built-in type.
std::basic_string< char > extract_str(CharMessageBuffer &buf)
Remove the constructed string.
std::basic_string< char > extract_str(std::basic_ostream< char > &os)
Remove the constructed string.
std::ostream & operator<<(long val)
Insertion operator for built-in type.
std::ostream & operator<<(unsigned long val)
Insertion operator for built-in type.
std::ostream & operator<<(double val)
Insertion operator for built-in type.
std::ostream & operator<<(void *val)
Insertion operator for built-in type.
std::ostream & operator<<(long double val)
Insertion operator for built-in type.
std::ostream & operator<<(int val)
Insertion operator for built-in type.
CharMessageBuffer & operator<<(const std::basic_string< char > &msg)
Appends string to buffer.
CharMessageBuffer & operator<<(const char *msg)
Appends string to buffer.
std::ostream & operator<<(bool val)
Insertion operator for built-in type.
std::ostream & operator<<(float val)
Insertion operator for built-in type.
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: log4cxx/helpers/messagebuffer.h:576
CharMessageBuffer & operator<<(const char *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
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<<(double val)
Insertion operator for built-in type.
std::ostream & operator<<(long val)
Insertion operator for built-in type.
CharMessageBuffer & operator<<(const std::string &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.
WideMessageBuffer & operator<<(const wchar_t msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::string extract_str(CharMessageBuffer &buf)
Remove the constructed string.
std::wstring extract_str(std::basic_ostream< wchar_t > &os)
Remove the constructed string.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
std::ostream & operator<<(int val)
Insertion operator for built-in type.
std::ostream & operator<<(void *val)
Insertion operator for built-in type.
std::ostream & operator<<(ios_base_manip manip)
Insertion operator for STL manipulators such as std::fixed.
std::ostream & operator<<(unsigned long val)
Insertion operator for built-in type.
CharMessageBuffer & operator<<(const char msg)
Appends a string into the buffer and fixes the buffer to use char characters.
const std::wstring & str(WideMessageBuffer &buf)
Get content of buffer.
std::ostream & operator<<(short val)
Insertion operator for built-in type.
std::ostream & operator<<(long double 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<<(unsigned int val)
Insertion operator for built-in type.
std::wstring extract_str(WideMessageBuffer &buf)
Remove the constructed string.
UniCharMessageBuffer & operator<<(const UniChar *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
UniCharMessageBuffer & operator<<(const UniChar msg)
Appends a string into the buffer and fixes the buffer to use char characters.
MessageBuffer()
Creates a new instance.
WideMessageBuffer & operator<<(const std::wstring &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
std::ostream & operator<<(bool val)
Insertion operator for built-in type.
std::basic_string< UniChar > extract_str(UniCharMessageBuffer &buf)
Remove the constructed string.
CharMessageBuffer & operator<<(char *msg)
Appends a string into the buffer and fixes the buffer to use char characters.
UniCharMessageBuffer & operator<<(const std::basic_string< UniChar > &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
UniCharMessageBuffer & operator<<(const CFStringRef &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
const std::string & str(std::ostream &os)
Get content of buffer.
std::string extract_str(std::ostream &os)
Remove the constructed string.
const std::basic_string< UniChar > & str(UniCharMessageBuffer &buf)
Get content of buffer.
std::ostream & operator<<(float val)
Insertion operator for built-in type.
std::basic_string< UniChar > extract_str(std::basic_ostream< UniChar > &os)
Remove the constructed string.
const std::basic_string< UniChar > & str(UniCharMessageBuffer::uostream &os)
Get content of buffer.
const std::string & str(CharMessageBuffer &buf)
Get content of buffer.
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition: log4cxx/helpers/messagebuffer.h:220
const std::basic_string< UniChar > & str(uostream &os)
Get content of buffer.
UniCharMessageBuffer & operator<<(UniChar *msg)
Appends string to buffer.
uostream & operator<<(short val)
Insertion operator for built-in type.
std::basic_string< UniChar > extract_str(UniCharMessageBuffer &buf)
Remove the constructed string.
const std::basic_string< UniChar > & str(UniCharMessageBuffer &buf)
Get content of buffer.
std::basic_ostream< UniChar > uostream
Definition: log4cxx/helpers/messagebuffer.h:231
uostream & operator<<(unsigned int val)
Insertion operator for built-in type.
UniCharMessageBuffer()
Creates a new instance.
UniCharMessageBuffer & operator<<(const UniChar msg)
Appends character to buffer.
uostream & operator<<(long val)
Insertion operator for built-in type.
uostream & operator<<(int val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(const CFStringRef &msg)
Appends a string into the buffer and fixes the buffer to use char characters.
uostream & operator<<(void *val)
Insertion operator for built-in type.
uostream & operator<<(float val)
Insertion operator for built-in type.
std::basic_string< UniChar > extract_str(uostream &os)
Remove the constructed string.
uostream & operator<<(unsigned long val)
Insertion operator for built-in type.
uostream & operator<<(double val)
Insertion operator for built-in type.
uostream & operator<<(long double val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(const std::basic_string< UniChar > &msg)
Appends string to buffer.
uostream & operator<<(bool val)
Insertion operator for built-in type.
UniCharMessageBuffer & operator<<(const UniChar *msg)
Appends string to buffer.
uostream & operator<<(ios_base_manip manip)
Insertion operator for STL manipulators such as std::fixed.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition: log4cxx/helpers/messagebuffer.h:405
WideMessageBuffer()
Creates a new instance.
WideMessageBuffer & operator<<(const wchar_t *msg)
Appends string to buffer.
WideMessageBuffer & operator<<(wchar_t *msg)
Appends string to buffer.
bool hasStream() const
Returns true if buffer has an encapsulated STL stream.
const std::basic_string< wchar_t > & str(WideMessageBuffer &buf)
Get content of buffer.
const std::basic_string< wchar_t > & str(std::basic_ostream< wchar_t > &os)
Get content of buffer.
std::basic_string< wchar_t > extract_str(WideMessageBuffer &buf)
Remove the constructed string.
std::basic_string< wchar_t > extract_str(std::basic_ostream< wchar_t > &os)
Remove the constructed string.
WideMessageBuffer & operator<<(const std::basic_string< wchar_t > &msg)
Appends string to buffer.
WideMessageBuffer & operator<<(const wchar_t msg)
Appends character to buffer.
const struct __CFString * CFStringRef
Definition: logstring.h:30
std::ios_base &(* ios_base_manip)(std::ios_base &)
Definition: log4cxx/helpers/messagebuffer.h:32
std::ostream & operator<<(MessageBuffer &os, const V &val)
Definition: log4cxx/helpers/messagebuffer.h:885
unsigned short UniChar
Definition: logstring.h:38