Apache log4cxx  Version 0.13.0
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 
30 namespace log4cxx
31 {
32 
33 
34 namespace helpers
35 {
36 
38 
39 typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
40 
46 class LOG4CXX_EXPORT CharMessageBuffer
47 {
48  public:
57 
58 
64  CharMessageBuffer& operator<<(const std::basic_string<char>& msg);
70  CharMessageBuffer& operator<<(const char* msg);
76  CharMessageBuffer& operator<<(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 
198 template<class V>
199 std::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
205 
210 class 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
252 
259 #endif
260 
266  uostream& operator<<(ios_base_manip manip);
272  uostream& operator<<(bool val);
273 
279  uostream& operator<<(short val);
285  uostream& operator<<(int val);
291  uostream& operator<<(unsigned int val);
297  uostream& operator<<(long 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:
363  UniCharMessageBuffer& operator=(const UniCharMessageBuffer&);
364 
368  std::basic_string<UniChar> buf;
372  std::basic_ostringstream<UniChar>* stream;
373 };
374 
375 template<class V>
377 {
378  return ((UniCharMessageBuffer::uostream&) os) << val;
379 }
380 #endif
381 
382 #if LOG4CXX_WCHAR_T_API
383 
388 class 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);
418  WideMessageBuffer& operator<<(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 
541 template<class V>
542 std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val)
543 {
544  return ((std::basic_ostream<wchar_t>&) os) << val;
545 }
546 
552 class LOG4CXX_EXPORT MessageBuffer
553 {
554  public:
558  MessageBuffer();
562  ~MessageBuffer();
563 
567  operator std::ostream& ();
568 
575  CharMessageBuffer& operator<<(const std::string& msg);
582  CharMessageBuffer& operator<<(const char* msg);
589  CharMessageBuffer& operator<<(char* msg);
590 
597  CharMessageBuffer& operator<<(const char msg);
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);
635  WideMessageBuffer& operator<<(wchar_t* msg);
642  WideMessageBuffer& operator<<(const wchar_t msg);
643 
644 #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
645 
651  UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
673 #endif
674 
675 #if LOG4CXX_CFSTRING_API
676 
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
770 
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 
806  CharMessageBuffer cbuf;
807 
811  WideMessageBuffer* wbuf;
812 #if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
813 
816  UniCharMessageBuffer* ubuf;
817 #endif
818 };
819 
820 template<class V>
821 std::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
840 typedef CharMessageBuffer LogCharMessageBuffer;
841 #endif
842 
843 }
844 }
845 
846 #if defined(_MSC_VER)
847  #pragma warning (pop)
848 #endif
849 
850 #endif
851 
unsigned short UniChar
Definition: logstring.h:44
const struct __CFString * CFStringRef
Definition: logstring.h:36
std::basic_ostream< char > & operator<<(CharMessageBuffer &os, const V &val)
Definition: messagebuffer.h:199
void MessageBufferUseStaticStream()
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition: messagebuffer.h:388
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition: messagebuffer.h:210
std::ios_base &(* ios_base_manip)(std::ios_base &)
Definition: messagebuffer.h:39
std::basic_ostream< UniChar > uostream
Definition: messagebuffer.h:222
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: messagebuffer.h:552
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition: messagebuffer.h:46
Definition: appender.h:32