source: pacpusframework/trunk/3rd/apache-log4cxx/include/log4cxx/helpers/messagebuffer.h@ 62

Last change on this file since 62 was 2, checked in by sgosseli, 12 years ago

Add 3rd party libraries (log4cxx).

File size: 25.4 KB
Line 
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 namespace helpers {
29
30 typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
31
32 /**
33 * This class is used by the LOG4CXX_INFO and similar
34 * macros to support insertion operators in the message parameter.
35 * The class is not intended for use outside of that context.
36 */
37 class LOG4CXX_EXPORT CharMessageBuffer {
38 public:
39 /**
40 * Creates a new instance.
41 */
42 CharMessageBuffer();
43 /**
44 * Destructor.
45 */
46 ~CharMessageBuffer();
47
48
49 /**
50 * Appends string to buffer.
51 * @param msg string append.
52 * @return this buffer.
53 */
54 CharMessageBuffer& operator<<(const std::basic_string<char>& msg);
55 /**
56 * Appends string to buffer.
57 * @param msg string to append.
58 * @return this buffer.
59 */
60 CharMessageBuffer& operator<<(const char* msg);
61 /**
62 * Appends string to buffer.
63 * @param msg string to append.
64 * @return this buffer.
65 */
66 CharMessageBuffer& operator<<(char* msg);
67
68 /**
69 * Appends character to buffer.
70 * @param msg character to append.
71 * @return this buffer.
72 */
73 CharMessageBuffer& operator<<(const char msg);
74
75 /**
76 * Insertion operator for STL manipulators such as std::fixed.
77 * @param manip manipulator.
78 * @return encapsulated STL stream.
79 */
80 std::ostream& operator<<(ios_base_manip manip);
81 /**
82 * Insertion operator for built-in type.
83 * @param val build in type.
84 * @return encapsulated STL stream.
85 */
86 std::ostream& operator<<(bool val);
87
88 /**
89 * Insertion operator for built-in type.
90 * @param val build in type.
91 * @return encapsulated STL stream.
92 */
93 std::ostream& operator<<(short val);
94 /**
95 * Insertion operator for built-in type.
96 * @param val build in type.
97 * @return encapsulated STL stream.
98 */
99 std::ostream& operator<<(int val);
100 /**
101 * Insertion operator for built-in type.
102 * @param val build in type.
103 * @return encapsulated STL stream.
104 */
105 std::ostream& operator<<(unsigned int val);
106 /**
107 * Insertion operator for built-in type.
108 * @param val build in type.
109 * @return encapsulated STL stream.
110 */
111 std::ostream& operator<<(long val);
112 /**
113 * Insertion operator for built-in type.
114 * @param val build in type.
115 * @return encapsulated STL stream.
116 */
117 std::ostream& operator<<(unsigned long val);
118 /**
119 * Insertion operator for built-in type.
120 * @param val build in type.
121 * @return encapsulated STL stream.
122 */
123 std::ostream& operator<<(float val);
124 /**
125 * Insertion operator for built-in type.
126 * @param val build in type.
127 * @return encapsulated STL stream.
128 */
129 std::ostream& operator<<(double val);
130 /**
131 * Insertion operator for built-in type.
132 * @param val build in type.
133 * @return encapsulated STL stream.
134 */
135 std::ostream& operator<<(long double val);
136 /**
137 * Insertion operator for built-in type.
138 * @param val build in type.
139 * @return encapsulated STL stream.
140 */
141 std::ostream& operator<<(void* val);
142
143 /**
144 * Cast to ostream.
145 */
146 operator std::basic_ostream<char>&();
147
148 /**
149 * Get content of buffer.
150 * @param os used only to signal that
151 * the embedded stream was used.
152 */
153 const std::basic_string<char>& str(std::basic_ostream<char>& os);
154
155 /**
156 * Get content of buffer.
157 * @param buf used only to signal that
158 * the embedded stream was not used.
159 */
160 const std::basic_string<char>& str(CharMessageBuffer& buf);
161
162 /**
163 * Returns true if buffer has an encapsulated STL stream.
164 * @return true if STL stream was created.
165 */
166 bool hasStream() const;
167
168 private:
169 /**
170 * Prevent use of default copy constructor.
171 */
172 CharMessageBuffer(const CharMessageBuffer&);
173 /**
174 * Prevent use of default assignment operator.
175 */
176 CharMessageBuffer& operator=(const CharMessageBuffer&);
177
178 /**
179 * Encapsulated std::string.
180 */
181 std::basic_string<char> buf;
182 /**
183 * Encapsulated stream, created on demand.
184 */
185 std::basic_ostringstream<char>* stream;
186 };
187
188template<class V>
189std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val) {
190 return ((std::basic_ostream<char>&) os) << val;
191}
192
193#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR
194 /**
195 * This class is designed to support insertion operations
196 * in the message argument to the LOG4CXX_INFO and similar
197 * macros and is not designed for general purpose use.
198 */
199 class LOG4CXX_EXPORT UniCharMessageBuffer {
200 public:
201 /**
202 * Creates a new instance.
203 */
204 UniCharMessageBuffer();
205 /**
206 * Destructor.
207 */
208 ~UniCharMessageBuffer();
209
210 typedef std::basic_ostream<UniChar> uostream;
211
212
213 /**
214 * Appends string to buffer.
215 * @param msg string append.
216 * @return this buffer.
217 */
218 UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
219 /**
220 * Appends string to buffer.
221 * @param msg string to append.
222 * @return this buffer.
223 */
224 UniCharMessageBuffer& operator<<(const UniChar* msg);
225 /**
226 * Appends string to buffer.
227 * @param msg string to append.
228 * @return this buffer.
229 */
230 UniCharMessageBuffer& operator<<(UniChar* msg);
231
232 /**
233 * Appends character to buffer.
234 * @param msg character to append.
235 * @return this buffer.
236 */
237 UniCharMessageBuffer& operator<<(const UniChar msg);
238
239#if LOG4CXX_CFSTRING_API
240 /**
241 * Appends a string into the buffer and
242 * fixes the buffer to use char characters.
243 * @param msg message to append.
244 * @return encapsulated CharMessageBuffer.
245 */
246 UniCharMessageBuffer& operator<<(const CFStringRef& msg);
247#endif
248
249 /**
250 * Insertion operator for STL manipulators such as std::fixed.
251 * @param manip manipulator.
252 * @return encapsulated STL stream.
253 */
254 uostream& operator<<(ios_base_manip manip);
255 /**
256 * Insertion operator for built-in type.
257 * @param val build in type.
258 * @return encapsulated STL stream.
259 */
260 uostream& operator<<(bool val);
261
262 /**
263 * Insertion operator for built-in type.
264 * @param val build in type.
265 * @return encapsulated STL stream.
266 */
267 uostream& operator<<(short val);
268 /**
269 * Insertion operator for built-in type.
270 * @param val build in type.
271 * @return encapsulated STL stream.
272 */
273 uostream& operator<<(int val);
274 /**
275 * Insertion operator for built-in type.
276 * @param val build in type.
277 * @return encapsulated STL stream.
278 */
279 uostream& operator<<(unsigned int val);
280 /**
281 * Insertion operator for built-in type.
282 * @param val build in type.
283 * @return encapsulated STL stream.
284 */
285 uostream& operator<<(long val);
286 /**
287 * Insertion operator for built-in type.
288 * @param val build in type.
289 * @return encapsulated STL stream.
290 */
291 uostream& operator<<(unsigned long val);
292 /**
293 * Insertion operator for built-in type.
294 * @param val build in type.
295 * @return encapsulated STL stream.
296 */
297 uostream& operator<<(float val);
298 /**
299 * Insertion operator for built-in type.
300 * @param val build in type.
301 * @return encapsulated STL stream.
302 */
303 uostream& operator<<(double val);
304 /**
305 * Insertion operator for built-in type.
306 * @param val build in type.
307 * @return encapsulated STL stream.
308 */
309 uostream& operator<<(long double val);
310 /**
311 * Insertion operator for built-in type.
312 * @param val build in type.
313 * @return encapsulated STL stream.
314 */
315 uostream& operator<<(void* val);
316
317
318 /**
319 * Cast to ostream.
320 */
321 operator uostream&();
322
323 /**
324 * Get content of buffer.
325 * @param os used only to signal that
326 * the embedded stream was used.
327 */
328 const std::basic_string<UniChar>& str(uostream& os);
329
330 /**
331 * Get content of buffer.
332 * @param buf used only to signal that
333 * the embedded stream was not used.
334 */
335 const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
336
337 /**
338 * Returns true if buffer has an encapsulated STL stream.
339 * @return true if STL stream was created.
340 */
341 bool hasStream() const;
342
343 private:
344 /**
345 * Prevent use of default copy constructor.
346 */
347 UniCharMessageBuffer(const UniCharMessageBuffer&);
348 /**
349 * Prevent use of default assignment operator.
350 */
351 UniCharMessageBuffer& operator=(const UniCharMessageBuffer&);
352
353 /**
354 * Encapsulated std::string.
355 */
356 std::basic_string<UniChar> buf;
357 /**
358 * Encapsulated stream, created on demand.
359 */
360 std::basic_ostringstream<UniChar>* stream;
361 };
362
363template<class V>
364UniCharMessageBuffer::uostream& operator<<(UniCharMessageBuffer& os, const V& val) {
365 return ((UniCharMessageBuffer::uostream&) os) << val;
366}
367#endif
368
369#if LOG4CXX_WCHAR_T_API
370 /**
371 * This class is designed to support insertion operations
372 * in the message argument to the LOG4CXX_INFO and similar
373 * macros and is not designed for general purpose use.
374 */
375 class LOG4CXX_EXPORT WideMessageBuffer {
376 public:
377 /**
378 * Creates a new instance.
379 */
380 WideMessageBuffer();
381 /**
382 * Destructor.
383 */
384 ~WideMessageBuffer();
385
386
387 /**
388 * Appends string to buffer.
389 * @param msg string append.
390 * @return this buffer.
391 */
392 WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg);
393 /**
394 * Appends string to buffer.
395 * @param msg string to append.
396 * @return this buffer.
397 */
398 WideMessageBuffer& operator<<(const wchar_t* msg);
399 /**
400 * Appends string to buffer.
401 * @param msg string to append.
402 * @return this buffer.
403 */
404 WideMessageBuffer& operator<<(wchar_t* msg);
405
406 /**
407 * Appends character to buffer.
408 * @param msg character to append.
409 * @return this buffer.
410 */
411 WideMessageBuffer& operator<<(const wchar_t msg);
412
413 /**
414 * Insertion operator for STL manipulators such as std::fixed.
415 * @param manip manipulator.
416 * @return encapsulated STL stream.
417 */
418 std::basic_ostream<wchar_t>& operator<<(ios_base_manip manip);
419 /**
420 * Insertion operator for built-in type.
421 * @param val build in type.
422 * @return encapsulated STL stream.
423 */
424 std::basic_ostream<wchar_t>& operator<<(bool val);
425
426 /**
427 * Insertion operator for built-in type.
428 * @param val build in type.
429 * @return encapsulated STL stream.
430 */
431 std::basic_ostream<wchar_t>& operator<<(short val);
432 /**
433 * Insertion operator for built-in type.
434 * @param val build in type.
435 * @return encapsulated STL stream.
436 */
437 std::basic_ostream<wchar_t>& operator<<(int val);
438 /**
439 * Insertion operator for built-in type.
440 * @param val build in type.
441 * @return encapsulated STL stream.
442 */
443 std::basic_ostream<wchar_t>& operator<<(unsigned int val);
444 /**
445 * Insertion operator for built-in type.
446 * @param val build in type.
447 * @return encapsulated STL stream.
448 */
449 std::basic_ostream<wchar_t>& operator<<(long val);
450 /**
451 * Insertion operator for built-in type.
452 * @param val build in type.
453 * @return encapsulated STL stream.
454 */
455 std::basic_ostream<wchar_t>& operator<<(unsigned long val);
456 /**
457 * Insertion operator for built-in type.
458 * @param val build in type.
459 * @return encapsulated STL stream.
460 */
461 std::basic_ostream<wchar_t>& operator<<(float val);
462 /**
463 * Insertion operator for built-in type.
464 * @param val build in type.
465 * @return encapsulated STL stream.
466 */
467 std::basic_ostream<wchar_t>& operator<<(double val);
468 /**
469 * Insertion operator for built-in type.
470 * @param val build in type.
471 * @return encapsulated STL stream.
472 */
473 std::basic_ostream<wchar_t>& operator<<(long double val);
474 /**
475 * Insertion operator for built-in type.
476 * @param val build in type.
477 * @return encapsulated STL stream.
478 */
479 std::basic_ostream<wchar_t>& operator<<(void* val);
480
481
482 /**
483 * Cast to ostream.
484 */
485 operator std::basic_ostream<wchar_t>&();
486
487 /**
488 * Get content of buffer.
489 * @param os used only to signal that
490 * the embedded stream was used.
491 */
492 const std::basic_string<wchar_t>& str(std::basic_ostream<wchar_t>& os);
493
494 /**
495 * Get content of buffer.
496 * @param buf used only to signal that
497 * the embedded stream was not used.
498 */
499 const std::basic_string<wchar_t>& str(WideMessageBuffer& buf);
500
501 /**
502 * Returns true if buffer has an encapsulated STL stream.
503 * @return true if STL stream was created.
504 */
505 bool hasStream() const;
506
507 private:
508 /**
509 * Prevent use of default copy constructor.
510 */
511 WideMessageBuffer(const WideMessageBuffer&);
512 /**
513 * Prevent use of default assignment operator.
514 */
515 WideMessageBuffer& operator=(const WideMessageBuffer&);
516
517 /**
518 * Encapsulated std::string.
519 */
520 std::basic_string<wchar_t> buf;
521 /**
522 * Encapsulated stream, created on demand.
523 */
524 std::basic_ostringstream<wchar_t>* stream;
525 };
526
527template<class V>
528std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val) {
529 return ((std::basic_ostream<wchar_t>&) os) << val;
530}
531
532 /**
533 * This class is used by the LOG4CXX_INFO and similar
534 * macros to support insertion operators in the message parameter.
535 * The class is not intended for use outside of that context.
536 */
537 class LOG4CXX_EXPORT MessageBuffer {
538 public:
539 /**
540 * Creates a new instance.
541 */
542 MessageBuffer();
543 /**
544 * Destructor.
545 */
546 ~MessageBuffer();
547
548 /**
549 * Cast to ostream.
550 */
551 operator std::ostream&();
552
553 /**
554 * Appends a string into the buffer and
555 * fixes the buffer to use char characters.
556 * @param msg message to append.
557 * @return encapsulated CharMessageBuffer.
558 */
559 CharMessageBuffer& operator<<(const std::string& msg);
560 /**
561 * Appends a string into the buffer and
562 * fixes the buffer to use char characters.
563 * @param msg message to append.
564 * @return encapsulated CharMessageBuffer.
565 */
566 CharMessageBuffer& operator<<(const char* msg);
567 /**
568 * Appends a string into the buffer and
569 * fixes the buffer to use char characters.
570 * @param msg message to append.
571 * @return encapsulated CharMessageBuffer.
572 */
573 CharMessageBuffer& operator<<(char* msg);
574
575 /**
576 * Appends a string into the buffer and
577 * fixes the buffer to use char characters.
578 * @param msg message to append.
579 * @return encapsulated CharMessageBuffer.
580 */
581 CharMessageBuffer& operator<<(const char msg);
582
583 /**
584 * Get content of buffer.
585 * @param buf used only to signal
586 * the character type and that
587 * the embedded stream was not used.
588 */
589 const std::string& str(CharMessageBuffer& buf);
590
591 /**
592 * Get content of buffer.
593 * @param os used only to signal
594 * the character type and that
595 * the embedded stream was used.
596 */
597 const std::string& str(std::ostream& os);
598
599 /**
600 * Appends a string into the buffer and
601 * fixes the buffer to use char characters.
602 * @param msg message to append.
603 * @return encapsulated CharMessageBuffer.
604 */
605 WideMessageBuffer& operator<<(const std::wstring& msg);
606 /**
607 * Appends a string into the buffer and
608 * fixes the buffer to use char characters.
609 * @param msg message to append.
610 * @return encapsulated CharMessageBuffer.
611 */
612 WideMessageBuffer& operator<<(const wchar_t* msg);
613 /**
614 * Appends a string into the buffer and
615 * fixes the buffer to use char characters.
616 * @param msg message to append.
617 * @return encapsulated CharMessageBuffer.
618 */
619 WideMessageBuffer& operator<<(wchar_t* msg);
620 /**
621 * Appends a string into the buffer and
622 * fixes the buffer to use char characters.
623 * @param msg message to append.
624 * @return encapsulated CharMessageBuffer.
625 */
626 WideMessageBuffer& operator<<(const wchar_t msg);
627
628#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
629 /**
630 * Appends a string into the buffer and
631 * fixes the buffer to use char characters.
632 * @param msg message to append.
633 * @return encapsulated CharMessageBuffer.
634 */
635 UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
636 /**
637 * Appends a string into the buffer and
638 * fixes the buffer to use char characters.
639 * @param msg message to append.
640 * @return encapsulated CharMessageBuffer.
641 */
642 UniCharMessageBuffer& operator<<(const UniChar* msg);
643 /**
644 * Appends a string into the buffer and
645 * fixes the buffer to use char characters.
646 * @param msg message to append.
647 * @return encapsulated CharMessageBuffer.
648 */
649 UniCharMessageBuffer& operator<<(UniChar* msg);
650 /**
651 * Appends a string into the buffer and
652 * fixes the buffer to use char characters.
653 * @param msg message to append.
654 * @return encapsulated CharMessageBuffer.
655 */
656 UniCharMessageBuffer& operator<<(const UniChar msg);
657#endif
658
659#if LOG4CXX_CFSTRING_API
660 /**
661 * Appends a string into the buffer and
662 * fixes the buffer to use char characters.
663 * @param msg message to append.
664 * @return encapsulated CharMessageBuffer.
665 */
666 UniCharMessageBuffer& operator<<(const CFStringRef& msg);
667#endif
668
669 /**
670 * Insertion operator for STL manipulators such as std::fixed.
671 * @param manip manipulator.
672 * @return encapsulated STL stream.
673 */
674 std::ostream& operator<<(ios_base_manip manip);
675
676 /**
677 * Insertion operator for built-in type.
678 * @param val build in type.
679 * @return encapsulated STL stream.
680 */
681 std::ostream& operator<<(bool val);
682
683 /**
684 * Insertion operator for built-in type.
685 * @param val build in type.
686 * @return encapsulated STL stream.
687 */
688 std::ostream& operator<<(short val);
689 /**
690 * Insertion operator for built-in type.
691 * @param val build in type.
692 * @return encapsulated STL stream.
693 */
694 std::ostream& operator<<(int val);
695 /**
696 * Insertion operator for built-in type.
697 * @param val build in type.
698 * @return encapsulated STL stream.
699 */
700 std::ostream& operator<<(unsigned int val);
701 /**
702 * Insertion operator for built-in type.
703 * @param val build in type.
704 * @return encapsulated STL stream.
705 */
706 std::ostream& operator<<(long val);
707 /**
708 * Insertion operator for built-in type.
709 * @param val build in type.
710 * @return encapsulated STL stream.
711 */
712 std::ostream& operator<<(unsigned long val);
713 /**
714 * Insertion operator for built-in type.
715 * @param val build in type.
716 * @return encapsulated STL stream.
717 */
718 std::ostream& operator<<(float val);
719 /**
720 * Insertion operator for built-in type.
721 * @param val build in type.
722 * @return encapsulated STL stream.
723 */
724 std::ostream& operator<<(double val);
725 /**
726 * Insertion operator for built-in type.
727 * @param val build in type.
728 * @return encapsulated STL stream.
729 */
730 std::ostream& operator<<(long double val);
731 /**
732 * Insertion operator for built-in type.
733 * @param val build in type.
734 * @return encapsulated STL stream.
735 */
736 std::ostream& operator<<(void* val);
737 /**
738 * Get content of buffer.
739 * @param buf used only to signal
740 * the character type and that
741 * the embedded stream was not used.
742 */
743 const std::wstring& str(WideMessageBuffer& buf);
744
745 /**
746 * Get content of buffer.
747 * @param os used only to signal
748 * the character type and that
749 * the embedded stream was used.
750 */
751 const std::wstring& str(std::basic_ostream<wchar_t>& os);
752
753#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
754 /**
755 * Get content of buffer.
756 * @param buf used only to signal
757 * the character type and that
758 * the embedded stream was not used.
759 */
760 const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
761
762 /**
763 * Get content of buffer.
764 * @param os used only to signal
765 * the character type and that
766 * the embedded stream was used.
767 */
768 const std::basic_string<UniChar>& str(UniCharMessageBuffer::uostream& os);
769#endif
770
771 /**
772 * Returns true if buffer has an encapsulated STL stream.
773 * @return true if STL stream was created.
774 */
775 bool hasStream() const;
776
777 private:
778 /**
779 * Prevent use of default copy constructor.
780 */
781 MessageBuffer(const MessageBuffer&);
782 /**
783 * Prevent use of default assignment operator.
784 */
785 MessageBuffer& operator=(const MessageBuffer&);
786
787 /**
788 * Character message buffer.
789 */
790 CharMessageBuffer cbuf;
791
792 /**
793 * Encapsulated wide message buffer, created on demand.
794 */
795 WideMessageBuffer* wbuf;
796#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
797 /**
798 * Encapsulated wide message buffer, created on demand.
799 */
800 UniCharMessageBuffer* ubuf;
801#endif
802 };
803
804template<class V>
805std::ostream& operator<<(MessageBuffer& os, const V& val) {
806 return ((std::ostream&) os) << val;
807}
808
809#if LOG4CXX_LOGCHAR_IS_UTF8
810typedef CharMessageBuffer LogCharMessageBuffer;
811#endif
812
813#if LOG4CXX_LOGCHAR_IS_WCHAR
814typedef WideMessageBuffer LogCharMessageBuffer;
815#endif
816
817#if LOG4CXX_LOGCHAR_IS_UNICHAR
818typedef UniCharMessageBuffer LogCharMessageBuffer;
819#endif
820
821#else
822typedef CharMessageBuffer MessageBuffer;
823typedef CharMessageBuffer LogCharMessageBuffer;
824#endif
825
826}}
827#endif
828
Note: See TracBrowser for help on using the repository browser.