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