/src/logging-log4cxx/src/main/cpp/mdc.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/mdc.h> | 
| 19 |  | #include <log4cxx/helpers/transcoder.h> | 
| 20 |  | #include <log4cxx/helpers/threadspecificdata.h> | 
| 21 |  |  | 
| 22 |  | #if LOG4CXX_CFSTRING_API | 
| 23 |  |   #include <CoreFoundation/CFString.h> | 
| 24 |  | #endif | 
| 25 |  |  | 
| 26 |  |  | 
| 27 |  | using namespace LOG4CXX_NS; | 
| 28 |  | using namespace LOG4CXX_NS::helpers; | 
| 29 |  |  | 
| 30 | 0 | MDC::MDC(const std::string& key1, const std::string& value) : key() | 
| 31 | 0 | { | 
| 32 | 0 |   Transcoder::decode(key1, key); | 
| 33 | 0 |   LOG4CXX_DECODE_CHAR(v, value); | 
| 34 | 0 |   putLS(key, v); | 
| 35 | 0 | } Unexecuted instantiation: log4cxx::MDC::MDC(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)Unexecuted instantiation: log4cxx::MDC::MDC(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) | 
| 36 |  |  | 
| 37 |  | MDC::~MDC() | 
| 38 | 0 | { | 
| 39 | 0 |   LogString prevVal; | 
| 40 | 0 |   remove(key, prevVal); | 
| 41 | 0 | } | 
| 42 |  |  | 
| 43 |  | void MDC::putLS(const LogString& key, const LogString& value) | 
| 44 | 27.7k | { | 
| 45 | 27.7k |   ThreadSpecificData::put(key, value); | 
| 46 | 27.7k | } log4cxx::MDC::putLS(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)| Line | Count | Source |  | 44 | 13.2k | { |  | 45 | 13.2k |   ThreadSpecificData::put(key, value); |  | 46 | 13.2k | } | 
log4cxx::MDC::putLS(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)| Line | Count | Source |  | 44 | 14.5k | { |  | 45 | 14.5k |   ThreadSpecificData::put(key, value); |  | 46 | 14.5k | } | 
 | 
| 47 |  |  | 
| 48 |  | void MDC::put(const std::string& key, const std::string& value) | 
| 49 | 46.1k | { | 
| 50 | 46.1k |   LOG4CXX_DECODE_CHAR(lkey, key); | 
| 51 | 46.1k |   LOG4CXX_DECODE_CHAR(lvalue, value); | 
| 52 | 46.1k |   putLS(lkey, lvalue); | 
| 53 | 46.1k | } log4cxx::MDC::put(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)| Line | Count | Source |  | 49 | 23.0k | { |  | 50 | 23.0k |   LOG4CXX_DECODE_CHAR(lkey, key); |  | 51 | 23.0k |   LOG4CXX_DECODE_CHAR(lvalue, value); |  | 52 | 23.0k |   putLS(lkey, lvalue); |  | 53 | 23.0k | } | 
log4cxx::MDC::put(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)| Line | Count | Source |  | 49 | 23.0k | { |  | 50 | 23.0k |   LOG4CXX_DECODE_CHAR(lkey, key); |  | 51 | 23.0k |   LOG4CXX_DECODE_CHAR(lvalue, value); |  | 52 | 23.0k |   putLS(lkey, lvalue); |  | 53 | 23.0k | } | 
 | 
| 54 |  |  | 
| 55 |  | bool MDC::get(const LogString& key, LogString& value) | 
| 56 | 10.9k | { | 
| 57 | 10.9k |   ThreadSpecificData* data = ThreadSpecificData::getCurrentData(); | 
| 58 |  |  | 
| 59 | 10.9k |   if (data != 0) | 
| 60 | 10.9k |   { | 
| 61 | 10.9k |     Map& map = data->getMap(); | 
| 62 |  |  | 
| 63 | 10.9k |     Map::iterator it = map.find(key); | 
| 64 |  |  | 
| 65 | 10.9k |     if (it != map.end()) | 
| 66 | 10.5k |     { | 
| 67 | 10.5k |       value.append(it->second); | 
| 68 | 10.5k |       return true; | 
| 69 | 10.5k |     } | 
| 70 |  |  | 
| 71 | 305 |     data->recycle(); | 
| 72 | 305 |   } | 
| 73 |  |  | 
| 74 | 305 |   return false; | 
| 75 | 10.9k | } log4cxx::MDC::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)| Line | Count | Source |  | 56 | 4.83k | { |  | 57 | 4.83k |   ThreadSpecificData* data = ThreadSpecificData::getCurrentData(); |  | 58 |  |  |  | 59 | 4.83k |   if (data != 0) |  | 60 | 4.83k |   { |  | 61 | 4.83k |     Map& map = data->getMap(); |  | 62 |  |  |  | 63 | 4.83k |     Map::iterator it = map.find(key); |  | 64 |  |  |  | 65 | 4.83k |     if (it != map.end()) |  | 66 | 4.67k |     { |  | 67 | 4.67k |       value.append(it->second); |  | 68 | 4.67k |       return true; |  | 69 | 4.67k |     } |  | 70 |  |  |  | 71 | 158 |     data->recycle(); |  | 72 | 158 |   } |  | 73 |  |  |  | 74 | 158 |   return false; |  | 75 | 4.83k | } | 
log4cxx::MDC::get(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&)| Line | Count | Source |  | 56 | 6.06k | { |  | 57 | 6.06k |   ThreadSpecificData* data = ThreadSpecificData::getCurrentData(); |  | 58 |  |  |  | 59 | 6.06k |   if (data != 0) |  | 60 | 6.06k |   { |  | 61 | 6.06k |     Map& map = data->getMap(); |  | 62 |  |  |  | 63 | 6.06k |     Map::iterator it = map.find(key); |  | 64 |  |  |  | 65 | 6.06k |     if (it != map.end()) |  | 66 | 5.92k |     { |  | 67 | 5.92k |       value.append(it->second); |  | 68 | 5.92k |       return true; |  | 69 | 5.92k |     } |  | 70 |  |  |  | 71 | 147 |     data->recycle(); |  | 72 | 147 |   } |  | 73 |  |  |  | 74 | 147 |   return false; |  | 75 | 6.06k | } | 
 | 
| 76 |  |  | 
| 77 |  | std::string MDC::get(const std::string& key) | 
| 78 | 0 | { | 
| 79 | 0 |   LOG4CXX_DECODE_CHAR(lkey, key); | 
| 80 | 0 |   LogString lvalue; | 
| 81 |  | 
 | 
| 82 | 0 |   if (get(lkey, lvalue)) | 
| 83 | 0 |   { | 
| 84 | 0 |     LOG4CXX_ENCODE_CHAR(value, lvalue); | 
| 85 | 0 |     return value; | 
| 86 | 0 |   } | 
| 87 |  |  | 
| 88 | 0 |   return std::string(); | 
| 89 | 0 | } Unexecuted instantiation: log4cxx::MDC::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)Unexecuted instantiation: log4cxx::MDC::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) | 
| 90 |  |  | 
| 91 |  | bool MDC::remove(const LogString& key, LogString& value) | 
| 92 | 0 | { | 
| 93 | 0 |   ThreadSpecificData* data = ThreadSpecificData::getCurrentData(); | 
| 94 |  | 
 | 
| 95 | 0 |   if (data != 0) | 
| 96 | 0 |   { | 
| 97 | 0 |     Map& map = data->getMap(); | 
| 98 | 0 |     Map::iterator it; | 
| 99 |  | 
 | 
| 100 | 0 |     if ((it = map.find(key)) != map.end()) | 
| 101 | 0 |     { | 
| 102 | 0 |       value = it->second; | 
| 103 | 0 |       map.erase(it); | 
| 104 | 0 |       data->recycle(); | 
| 105 | 0 |       return true; | 
| 106 | 0 |     } | 
| 107 | 0 |   } | 
| 108 |  |  | 
| 109 | 0 |   return false; | 
| 110 | 0 | } Unexecuted instantiation: log4cxx::MDC::remove(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)Unexecuted instantiation: log4cxx::MDC::remove(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&) | 
| 111 |  |  | 
| 112 |  | std::string MDC::remove(const std::string& key) | 
| 113 | 0 | { | 
| 114 | 0 |   LOG4CXX_DECODE_CHAR(lkey, key); | 
| 115 | 0 |   LogString lvalue; | 
| 116 |  | 
 | 
| 117 | 0 |   if (remove(lkey, lvalue)) | 
| 118 | 0 |   { | 
| 119 | 0 |     LOG4CXX_ENCODE_CHAR(value, lvalue); | 
| 120 | 0 |     return value; | 
| 121 | 0 |   } | 
| 122 |  |  | 
| 123 | 0 |   return std::string(); | 
| 124 | 0 | } Unexecuted instantiation: log4cxx::MDC::remove(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)Unexecuted instantiation: log4cxx::MDC::remove(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) | 
| 125 |  |  | 
| 126 |  |  | 
| 127 |  | void MDC::clear() | 
| 128 | 16.3k | { | 
| 129 | 16.3k |   ThreadSpecificData* data = ThreadSpecificData::getCurrentData(); | 
| 130 |  |  | 
| 131 | 16.3k |   if (data != 0) | 
| 132 | 16.3k |   { | 
| 133 | 16.3k |     Map& map = data->getMap(); | 
| 134 | 16.3k |     map.erase(map.begin(), map.end()); | 
| 135 | 16.3k |     data->recycle(); | 
| 136 | 16.3k |   } | 
| 137 | 16.3k | } | 
| 138 |  |  | 
| 139 |  |  | 
| 140 |  | #if LOG4CXX_WCHAR_T_API | 
| 141 | 0 | MDC::MDC(const std::wstring& key1, const std::wstring& value) : key() | 
| 142 | 0 | { | 
| 143 | 0 |   Transcoder::decode(key1, key); | 
| 144 | 0 |   LOG4CXX_DECODE_WCHAR(v, value); | 
| 145 | 0 |   putLS(key, v); | 
| 146 | 0 | } Unexecuted instantiation: log4cxx::MDC::MDC(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)Unexecuted instantiation: log4cxx::MDC::MDC(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&) | 
| 147 |  |  | 
| 148 |  | std::wstring MDC::get(const std::wstring& key) | 
| 149 | 0 | { | 
| 150 | 0 |   LOG4CXX_DECODE_WCHAR(lkey, key); | 
| 151 | 0 |   LogString lvalue; | 
| 152 |  | 
 | 
| 153 | 0 |   if (get(lkey, lvalue)) | 
| 154 | 0 |   { | 
| 155 | 0 |     LOG4CXX_ENCODE_WCHAR(value, lvalue); | 
| 156 | 0 |     return value; | 
| 157 | 0 |   } | 
| 158 |  |  | 
| 159 | 0 |   return std::wstring(); | 
| 160 | 0 | } Unexecuted instantiation: log4cxx::MDC::get(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)Unexecuted instantiation: log4cxx::MDC::get(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&) | 
| 161 |  |  | 
| 162 |  | void MDC::put(const std::wstring& key, const std::wstring& value) | 
| 163 | 9.42k | { | 
| 164 | 9.42k |   LOG4CXX_DECODE_WCHAR(lkey, key); | 
| 165 | 9.42k |   LOG4CXX_DECODE_WCHAR(lvalue, value); | 
| 166 | 9.42k |   putLS(lkey, lvalue); | 
| 167 | 9.42k | } log4cxx::MDC::put(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)| Line | Count | Source |  | 163 | 4.71k | { |  | 164 | 4.71k |   LOG4CXX_DECODE_WCHAR(lkey, key); |  | 165 | 4.71k |   LOG4CXX_DECODE_WCHAR(lvalue, value); |  | 166 | 4.71k |   putLS(lkey, lvalue); |  | 167 | 4.71k | } | 
log4cxx::MDC::put(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)| Line | Count | Source |  | 163 | 4.71k | { |  | 164 | 4.71k |   LOG4CXX_DECODE_WCHAR(lkey, key); |  | 165 | 4.71k |   LOG4CXX_DECODE_WCHAR(lvalue, value); |  | 166 | 4.71k |   putLS(lkey, lvalue); |  | 167 | 4.71k | } | 
 | 
| 168 |  |  | 
| 169 |  |  | 
| 170 |  | std::wstring MDC::remove(const std::wstring& key) | 
| 171 | 0 | { | 
| 172 | 0 |   LOG4CXX_DECODE_WCHAR(lkey, key); | 
| 173 | 0 |   LogString lvalue; | 
| 174 |  | 
 | 
| 175 | 0 |   if (remove(lkey, lvalue)) | 
| 176 | 0 |   { | 
| 177 | 0 |     LOG4CXX_ENCODE_WCHAR(value, lvalue); | 
| 178 | 0 |     return value; | 
| 179 | 0 |   } | 
| 180 |  |  | 
| 181 | 0 |   return std::wstring(); | 
| 182 | 0 | } Unexecuted instantiation: log4cxx::MDC::remove(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)Unexecuted instantiation: log4cxx::MDC::remove(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&) | 
| 183 |  | #endif | 
| 184 |  |  | 
| 185 |  | #if LOG4CXX_UNICHAR_API | 
| 186 |  | MDC::MDC(const std::basic_string<UniChar>& key1, const std::basic_string<UniChar>& value) | 
| 187 |  | { | 
| 188 |  |   Transcoder::decode(key1, key); | 
| 189 |  |   LOG4CXX_DECODE_UNICHAR(v, value); | 
| 190 |  |   putLS(key, v); | 
| 191 |  | } | 
| 192 |  |  | 
| 193 |  | std::basic_string<LOG4CXX_NS::UniChar> MDC::get(const std::basic_string<LOG4CXX_NS::UniChar>& key) | 
| 194 |  | { | 
| 195 |  |   LOG4CXX_DECODE_UNICHAR(lkey, key); | 
| 196 |  |   LogString lvalue; | 
| 197 |  |  | 
| 198 |  |   if (get(lkey, lvalue)) | 
| 199 |  |   { | 
| 200 |  |     LOG4CXX_ENCODE_UNICHAR(value, lvalue); | 
| 201 |  |     return value; | 
| 202 |  |   } | 
| 203 |  |  | 
| 204 |  |   return std::basic_string<UniChar>(); | 
| 205 |  | } | 
| 206 |  |  | 
| 207 |  | void MDC::put(const std::basic_string<UniChar>& key, const std::basic_string<LOG4CXX_NS::UniChar>& value) | 
| 208 |  | { | 
| 209 |  |   LOG4CXX_DECODE_UNICHAR(lkey, key); | 
| 210 |  |   LOG4CXX_DECODE_UNICHAR(lvalue, value); | 
| 211 |  |   putLS(lkey, lvalue); | 
| 212 |  | } | 
| 213 |  |  | 
| 214 |  |  | 
| 215 |  | std::basic_string<LOG4CXX_NS::UniChar> MDC::remove(const std::basic_string<LOG4CXX_NS::UniChar>& key) | 
| 216 |  | { | 
| 217 |  |   LOG4CXX_DECODE_UNICHAR(lkey, key); | 
| 218 |  |   LogString lvalue; | 
| 219 |  |  | 
| 220 |  |   if (remove(lkey, lvalue)) | 
| 221 |  |   { | 
| 222 |  |     LOG4CXX_ENCODE_UNICHAR(value, lvalue); | 
| 223 |  |     return value; | 
| 224 |  |   } | 
| 225 |  |  | 
| 226 |  |   return std::basic_string<UniChar>(); | 
| 227 |  | } | 
| 228 |  | #endif | 
| 229 |  |  | 
| 230 |  | #if LOG4CXX_CFSTRING_API | 
| 231 |  |  | 
| 232 |  | MDC::MDC(const CFStringRef& key1, const CFStringRef& value) | 
| 233 |  | { | 
| 234 |  |   Transcoder::decode(key1, key); | 
| 235 |  |   LOG4CXX_DECODE_CFSTRING(v, value); | 
| 236 |  |   putLS(key, v); | 
| 237 |  | } | 
| 238 |  |  | 
| 239 |  | CFStringRef MDC::get(const CFStringRef& key) | 
| 240 |  | { | 
| 241 |  |   LOG4CXX_DECODE_CFSTRING(lkey, key); | 
| 242 |  |   LogString lvalue; | 
| 243 |  |  | 
| 244 |  |   if (get(lkey, lvalue)) | 
| 245 |  |   { | 
| 246 |  |     LOG4CXX_ENCODE_CFSTRING(value, lvalue); | 
| 247 |  |     return value; | 
| 248 |  |   } | 
| 249 |  |  | 
| 250 |  |   return CFSTR(""); | 
| 251 |  | } | 
| 252 |  |  | 
| 253 |  | void MDC::put(const CFStringRef& key, const CFStringRef& value) | 
| 254 |  | { | 
| 255 |  |   LOG4CXX_DECODE_CFSTRING(lkey, key); | 
| 256 |  |   LOG4CXX_DECODE_CFSTRING(lvalue, value); | 
| 257 |  |   putLS(lkey, lvalue); | 
| 258 |  | } | 
| 259 |  |  | 
| 260 |  |  | 
| 261 |  | CFStringRef MDC::remove(const CFStringRef& key) | 
| 262 |  | { | 
| 263 |  |   LOG4CXX_DECODE_CFSTRING(lkey, key); | 
| 264 |  |   LogString lvalue; | 
| 265 |  |  | 
| 266 |  |   if (remove(lkey, lvalue)) | 
| 267 |  |   { | 
| 268 |  |     LOG4CXX_ENCODE_CFSTRING(value, lvalue); | 
| 269 |  |     return value; | 
| 270 |  |   } | 
| 271 |  |  | 
| 272 |  |   return CFSTR(""); | 
| 273 |  | } | 
| 274 |  | #endif | 
| 275 |  |  |