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