Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/log/sources/basic_logger.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 /* | |
2 * Copyright Andrey Semashev 2007 - 2013. | |
3 * Distributed under the Boost Software License, Version 1.0. | |
4 * (See accompanying file LICENSE_1_0.txt or copy at | |
5 * http://www.boost.org/LICENSE_1_0.txt) | |
6 */ | |
7 /*! | |
8 * \file basic_logger.hpp | |
9 * \author Andrey Semashev | |
10 * \date 08.03.2007 | |
11 * | |
12 * The header contains implementation of a base class for loggers. Convenience macros | |
13 * for defining custom loggers are also provided. | |
14 */ | |
15 | |
16 #ifndef BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_ | |
17 #define BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_ | |
18 | |
19 #include <exception> | |
20 #include <utility> | |
21 #include <ostream> | |
22 #include <boost/assert.hpp> | |
23 #include <boost/move/core.hpp> | |
24 #include <boost/move/utility.hpp> | |
25 #include <boost/utility/addressof.hpp> | |
26 #include <boost/preprocessor/facilities/empty.hpp> | |
27 #include <boost/preprocessor/facilities/identity.hpp> | |
28 #include <boost/preprocessor/repetition/enum_params.hpp> | |
29 #include <boost/preprocessor/repetition/enum_binary_params.hpp> | |
30 #include <boost/preprocessor/repetition/repeat_from_to.hpp> | |
31 #include <boost/preprocessor/seq/enum.hpp> | |
32 #include <boost/log/detail/config.hpp> | |
33 #include <boost/log/detail/parameter_tools.hpp> | |
34 #include <boost/log/attributes/attribute_set.hpp> | |
35 #include <boost/log/attributes/attribute_name.hpp> | |
36 #include <boost/log/attributes/attribute.hpp> | |
37 #include <boost/log/core/core.hpp> | |
38 #include <boost/log/core/record.hpp> | |
39 #include <boost/log/sources/features.hpp> | |
40 #include <boost/log/sources/threading_models.hpp> | |
41 #include <boost/log/detail/header.hpp> | |
42 | |
43 #ifdef BOOST_HAS_PRAGMA_ONCE | |
44 #pragma once | |
45 #endif | |
46 | |
47 namespace boost { | |
48 | |
49 BOOST_LOG_OPEN_NAMESPACE | |
50 | |
51 namespace sources { | |
52 | |
53 /*! | |
54 * \brief Basic logger class | |
55 * | |
56 * The \c basic_logger class template serves as a base class for all loggers | |
57 * provided by the library. It can also be used as a base for user-defined | |
58 * loggers. The template parameters are: | |
59 * | |
60 * \li \c CharT - logging character type | |
61 * \li \c FinalT - final type of the logger that eventually derives from | |
62 * the \c basic_logger. There may be other classes in the hierarchy | |
63 * between the final class and \c basic_logger. | |
64 * \li \c ThreadingModelT - threading model policy. Must provide methods | |
65 * of the Boost.Thread locking concept used in \c basic_logger class | |
66 * and all its derivatives in the hierarchy up to the \c FinalT class. | |
67 * The \c basic_logger class itself requires methods of the | |
68 * SharedLockable concept. The threading model policy must also be | |
69 * default and copy-constructible and support member function \c swap. | |
70 * There are currently two policies provided: \c single_thread_model | |
71 * and \c multi_thread_model. | |
72 * | |
73 * The logger implements fundamental facilities of loggers, such as storing | |
74 * source-specific attribute set and formatting log record messages. The basic | |
75 * logger interacts with the logging core in order to apply filtering and | |
76 * pass records to sinks. | |
77 */ | |
78 template< typename CharT, typename FinalT, typename ThreadingModelT > | |
79 class basic_logger : | |
80 public ThreadingModelT | |
81 { | |
82 typedef basic_logger this_type; | |
83 BOOST_COPYABLE_AND_MOVABLE_ALT(this_type) | |
84 | |
85 public: | |
86 //! Character type | |
87 typedef CharT char_type; | |
88 //! Final logger type | |
89 typedef FinalT final_type; | |
90 //! Threading model type | |
91 typedef ThreadingModelT threading_model; | |
92 | |
93 #if !defined(BOOST_LOG_NO_THREADS) | |
94 //! Lock requirement for the swap_unlocked method | |
95 typedef boost::log::aux::exclusive_lock_guard< threading_model > swap_lock; | |
96 //! Lock requirement for the add_attribute_unlocked method | |
97 typedef boost::log::aux::exclusive_lock_guard< threading_model > add_attribute_lock; | |
98 //! Lock requirement for the remove_attribute_unlocked method | |
99 typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_attribute_lock; | |
100 //! Lock requirement for the remove_all_attributes_unlocked method | |
101 typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_all_attributes_lock; | |
102 //! Lock requirement for the get_attributes method | |
103 typedef boost::log::aux::shared_lock_guard< threading_model > get_attributes_lock; | |
104 //! Lock requirement for the open_record_unlocked method | |
105 typedef boost::log::aux::shared_lock_guard< threading_model > open_record_lock; | |
106 //! Lock requirement for the set_attributes method | |
107 typedef boost::log::aux::exclusive_lock_guard< threading_model > set_attributes_lock; | |
108 #else | |
109 typedef no_lock< threading_model > swap_lock; | |
110 typedef no_lock< threading_model > add_attribute_lock; | |
111 typedef no_lock< threading_model > remove_attribute_lock; | |
112 typedef no_lock< threading_model > remove_all_attributes_lock; | |
113 typedef no_lock< threading_model > get_attributes_lock; | |
114 typedef no_lock< threading_model > open_record_lock; | |
115 typedef no_lock< threading_model > set_attributes_lock; | |
116 #endif | |
117 | |
118 //! Lock requirement for the push_record_unlocked method | |
119 typedef no_lock< threading_model > push_record_lock; | |
120 | |
121 private: | |
122 //! A pointer to the logging system | |
123 core_ptr m_pCore; | |
124 | |
125 //! Logger-specific attribute set | |
126 attribute_set m_Attributes; | |
127 | |
128 public: | |
129 /*! | |
130 * Constructor. Initializes internal data structures of the basic logger class, | |
131 * acquires reference to the logging core. | |
132 */ | |
133 basic_logger() : | |
134 threading_model(), | |
135 m_pCore(core::get()) | |
136 { | |
137 } | |
138 /*! | |
139 * Copy constructor. Copies all attributes from the source logger. | |
140 * | |
141 * \note Not thread-safe. The source logger must be locked in the final class before copying. | |
142 * | |
143 * \param that Source logger | |
144 */ | |
145 basic_logger(basic_logger const& that) : | |
146 threading_model(static_cast< threading_model const& >(that)), | |
147 m_pCore(core::get()), | |
148 m_Attributes(that.m_Attributes) | |
149 { | |
150 } | |
151 /*! | |
152 * Move constructor. Moves all attributes from the source logger. | |
153 * | |
154 * \note Not thread-safe. The source logger must be locked in the final class before copying. | |
155 * | |
156 * \param that Source logger | |
157 */ | |
158 basic_logger(BOOST_RV_REF(basic_logger) that) : | |
159 threading_model(boost::move(static_cast< threading_model& >(that))) | |
160 { | |
161 m_pCore.swap(that.m_pCore); | |
162 m_Attributes.swap(that.m_Attributes); | |
163 } | |
164 /*! | |
165 * Constructor with named arguments. The constructor ignores all arguments. The result of | |
166 * construction is equivalent to default construction. | |
167 */ | |
168 template< typename ArgsT > | |
169 explicit basic_logger(ArgsT const&) : | |
170 threading_model(), | |
171 m_pCore(core::get()) | |
172 { | |
173 } | |
174 | |
175 protected: | |
176 /*! | |
177 * An accessor to the logging system pointer | |
178 */ | |
179 core_ptr const& core() const { return m_pCore; } | |
180 /*! | |
181 * An accessor to the logger attributes | |
182 */ | |
183 attribute_set& attributes() { return m_Attributes; } | |
184 /*! | |
185 * An accessor to the logger attributes | |
186 */ | |
187 attribute_set const& attributes() const { return m_Attributes; } | |
188 /*! | |
189 * An accessor to the threading model base | |
190 */ | |
191 threading_model& get_threading_model() { return *this; } | |
192 /*! | |
193 * An accessor to the threading model base | |
194 */ | |
195 threading_model const& get_threading_model() const { return *this; } | |
196 /*! | |
197 * An accessor to the final logger | |
198 */ | |
199 final_type* final_this() | |
200 { | |
201 BOOST_LOG_ASSUME(this != NULL); | |
202 return static_cast< final_type* >(this); | |
203 } | |
204 /*! | |
205 * An accessor to the final logger | |
206 */ | |
207 final_type const* final_this() const | |
208 { | |
209 BOOST_LOG_ASSUME(this != NULL); | |
210 return static_cast< final_type const* >(this); | |
211 } | |
212 | |
213 /*! | |
214 * Unlocked \c swap | |
215 */ | |
216 void swap_unlocked(basic_logger& that) | |
217 { | |
218 get_threading_model().swap(that.get_threading_model()); | |
219 m_Attributes.swap(that.m_Attributes); | |
220 } | |
221 | |
222 /*! | |
223 * Unlocked \c add_attribute | |
224 */ | |
225 std::pair< attribute_set::iterator, bool > add_attribute_unlocked(attribute_name const& name, attribute const& attr) | |
226 { | |
227 return m_Attributes.insert(name, attr); | |
228 } | |
229 | |
230 /*! | |
231 * Unlocked \c remove_attribute | |
232 */ | |
233 void remove_attribute_unlocked(attribute_set::iterator it) | |
234 { | |
235 m_Attributes.erase(it); | |
236 } | |
237 | |
238 /*! | |
239 * Unlocked \c remove_all_attributes | |
240 */ | |
241 void remove_all_attributes_unlocked() | |
242 { | |
243 m_Attributes.clear(); | |
244 } | |
245 | |
246 /*! | |
247 * Unlocked \c open_record | |
248 */ | |
249 record open_record_unlocked() | |
250 { | |
251 return m_pCore->open_record(m_Attributes); | |
252 } | |
253 /*! | |
254 * Unlocked \c open_record | |
255 */ | |
256 template< typename ArgsT > | |
257 record open_record_unlocked(ArgsT const&) | |
258 { | |
259 return m_pCore->open_record(m_Attributes); | |
260 } | |
261 | |
262 /*! | |
263 * Unlocked \c push_record | |
264 */ | |
265 void push_record_unlocked(BOOST_RV_REF(record) rec) | |
266 { | |
267 m_pCore->push_record(boost::move(rec)); | |
268 } | |
269 | |
270 /*! | |
271 * Unlocked \c get_attributes | |
272 */ | |
273 attribute_set get_attributes_unlocked() const | |
274 { | |
275 return m_Attributes; | |
276 } | |
277 | |
278 /*! | |
279 * Unlocked \c set_attributes | |
280 */ | |
281 void set_attributes_unlocked(attribute_set const& attrs) | |
282 { | |
283 m_Attributes = attrs; | |
284 } | |
285 | |
286 //! Assignment is closed (should be implemented through copy and swap in the final class) | |
287 BOOST_DELETED_FUNCTION(basic_logger& operator= (basic_logger const&)) | |
288 }; | |
289 | |
290 /*! | |
291 * Free-standing swap for all loggers | |
292 */ | |
293 template< typename CharT, typename FinalT, typename ThreadingModelT > | |
294 inline void swap( | |
295 basic_logger< CharT, FinalT, ThreadingModelT >& left, | |
296 basic_logger< CharT, FinalT, ThreadingModelT >& right) | |
297 { | |
298 static_cast< FinalT& >(left).swap(static_cast< FinalT& >(right)); | |
299 } | |
300 | |
301 /*! | |
302 * \brief A composite logger that inherits a number of features | |
303 * | |
304 * The composite logger is a helper class that simplifies feature composition into the final logger. | |
305 * The user's logger class is expected to derive from the composite logger class, instantiated with | |
306 * the character type, the user's logger class, the threading model and the list of the required features. | |
307 * The former three parameters are passed to the \c basic_logger class template. The feature list | |
308 * must be an MPL type sequence, where each element is a unary MPL metafunction class, that upon | |
309 * applying on its argument results in a logging feature class that derives from the argument. | |
310 * Every logger feature provided by the library can participate in the feature list. | |
311 */ | |
312 template< typename CharT, typename FinalT, typename ThreadingModelT, typename FeaturesT > | |
313 class basic_composite_logger : | |
314 public boost::log::sources::aux::inherit_features< | |
315 basic_logger< CharT, FinalT, ThreadingModelT >, | |
316 FeaturesT | |
317 >::type | |
318 { | |
319 private: | |
320 //! Base type (the hierarchy of features) | |
321 typedef typename boost::log::sources::aux::inherit_features< | |
322 basic_logger< CharT, FinalT, ThreadingModelT >, | |
323 FeaturesT | |
324 >::type base_type; | |
325 | |
326 protected: | |
327 //! The composite logger type (for use in the user's logger class) | |
328 typedef basic_composite_logger logger_base; | |
329 BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base) | |
330 | |
331 public: | |
332 //! Threading model being used | |
333 typedef typename base_type::threading_model threading_model; | |
334 | |
335 #if !defined(BOOST_LOG_NO_THREADS) | |
336 | |
337 public: | |
338 /*! | |
339 * Default constructor (default-constructs all features) | |
340 */ | |
341 basic_composite_logger() {} | |
342 /*! | |
343 * Copy constructor | |
344 */ | |
345 basic_composite_logger(basic_composite_logger const& that) : | |
346 base_type | |
347 (( | |
348 boost::log::aux::shared_lock_guard< const threading_model >(that.get_threading_model()), | |
349 static_cast< base_type const& >(that) | |
350 )) | |
351 { | |
352 } | |
353 /*! | |
354 * Move constructor | |
355 */ | |
356 basic_composite_logger(BOOST_RV_REF(logger_base) that) : | |
357 base_type(boost::move(static_cast< base_type& >(that))) | |
358 { | |
359 } | |
360 /*! | |
361 * Constructor with named parameters | |
362 */ | |
363 template< typename ArgsT > | |
364 explicit basic_composite_logger(ArgsT const& args) : base_type(args) | |
365 { | |
366 } | |
367 | |
368 /*! | |
369 * The method adds an attribute to the source-specific attribute set. The attribute will be implicitly added to | |
370 * every log record made with the current logger. | |
371 * | |
372 * \param name The attribute name. | |
373 * \param attr The attribute factory. | |
374 * \return A pair of values. If the second member is \c true, then the attribute is added and the first member points to the | |
375 * attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents | |
376 * addition. | |
377 */ | |
378 std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr) | |
379 { | |
380 typename base_type::add_attribute_lock lock(base_type::get_threading_model()); | |
381 return base_type::add_attribute_unlocked(name, attr); | |
382 } | |
383 /*! | |
384 * The method removes an attribute from the source-specific attribute set. | |
385 * | |
386 * \pre The attribute was added with the add_attribute call for this instance of the logger. | |
387 * \post The attribute is no longer registered as a source-specific attribute for this logger. The iterator is invalidated after removal. | |
388 * | |
389 * \param it Iterator to the previously added attribute. | |
390 */ | |
391 void remove_attribute(attribute_set::iterator it) | |
392 { | |
393 typename base_type::remove_attribute_lock lock(base_type::get_threading_model()); | |
394 base_type::remove_attribute_unlocked(it); | |
395 } | |
396 | |
397 /*! | |
398 * The method removes all attributes from the logger. All iterators and references to the removed attributes are invalidated. | |
399 */ | |
400 void remove_all_attributes() | |
401 { | |
402 typename base_type::remove_all_attributes_lock lock(base_type::get_threading_model()); | |
403 base_type::remove_all_attributes_unlocked(); | |
404 } | |
405 | |
406 /*! | |
407 * The method retrieves a copy of a set with all attributes from the logger. | |
408 * | |
409 * \return The copy of the attribute set. Attributes are shallow-copied. | |
410 */ | |
411 attribute_set get_attributes() const | |
412 { | |
413 typename base_type::get_attributes_lock lock(base_type::get_threading_model()); | |
414 return base_type::get_attributes_unlocked(); | |
415 } | |
416 | |
417 /*! | |
418 * The method installs the whole attribute set into the logger. All iterators and references to elements of | |
419 * the previous set are invalidated. Iterators to the \a attrs set are not valid to be used with the logger (that is, | |
420 * the logger owns a copy of \a attrs after completion). | |
421 * | |
422 * \param attrs The set of attributes to install into the logger. Attributes are shallow-copied. | |
423 */ | |
424 void set_attributes(attribute_set const& attrs) | |
425 { | |
426 typename base_type::set_attributes_lock lock(base_type::get_threading_model()); | |
427 base_type::set_attributes_unlocked(attrs); | |
428 } | |
429 | |
430 /*! | |
431 * The method opens a new log record in the logging core. | |
432 * | |
433 * \return A valid record handle if the logging record is opened successfully, an invalid handle otherwise. | |
434 */ | |
435 record open_record() | |
436 { | |
437 // Perform a quick check first | |
438 if (this->core()->get_logging_enabled()) | |
439 { | |
440 typename base_type::open_record_lock lock(base_type::get_threading_model()); | |
441 return base_type::open_record_unlocked(boost::log::aux::empty_arg_list()); | |
442 } | |
443 else | |
444 return record(); | |
445 } | |
446 /*! | |
447 * The method opens a new log record in the logging core. | |
448 * | |
449 * \param args A set of additional named arguments. The parameter is ignored. | |
450 * \return A valid record handle if the logging record is opened successfully, an invalid handle otherwise. | |
451 */ | |
452 template< typename ArgsT > | |
453 record open_record(ArgsT const& args) | |
454 { | |
455 // Perform a quick check first | |
456 if (this->core()->get_logging_enabled()) | |
457 { | |
458 typename base_type::open_record_lock lock(base_type::get_threading_model()); | |
459 return base_type::open_record_unlocked(args); | |
460 } | |
461 else | |
462 return record(); | |
463 } | |
464 /*! | |
465 * The method pushes the constructed message to the logging core | |
466 * | |
467 * \param rec The log record with the formatted message | |
468 */ | |
469 void push_record(BOOST_RV_REF(record) rec) | |
470 { | |
471 typename base_type::push_record_lock lock(base_type::get_threading_model()); | |
472 base_type::push_record_unlocked(boost::move(rec)); | |
473 } | |
474 /*! | |
475 * Thread-safe implementation of swap | |
476 */ | |
477 void swap(basic_composite_logger& that) | |
478 { | |
479 boost::log::aux::multiple_unique_lock2< | |
480 threading_model, | |
481 threading_model | |
482 > lock(base_type::get_threading_model(), that.get_threading_model()); | |
483 base_type::swap_unlocked(that); | |
484 } | |
485 | |
486 protected: | |
487 /*! | |
488 * Assignment for the final class. Threadsafe, provides strong exception guarantee. | |
489 */ | |
490 FinalT& assign(FinalT const& that) | |
491 { | |
492 BOOST_LOG_ASSUME(this != NULL); | |
493 if (static_cast< FinalT* >(this) != boost::addressof(that)) | |
494 { | |
495 // We'll have to explicitly create the copy in order to make sure it's unlocked when we attempt to lock *this | |
496 FinalT tmp(that); | |
497 boost::log::aux::exclusive_lock_guard< threading_model > lock(base_type::get_threading_model()); | |
498 base_type::swap_unlocked(tmp); | |
499 } | |
500 return static_cast< FinalT& >(*this); | |
501 } | |
502 }; | |
503 | |
504 //! An optimized composite logger version with no multithreading support | |
505 template< typename CharT, typename FinalT, typename FeaturesT > | |
506 class basic_composite_logger< CharT, FinalT, single_thread_model, FeaturesT > : | |
507 public boost::log::sources::aux::inherit_features< | |
508 basic_logger< CharT, FinalT, single_thread_model >, | |
509 FeaturesT | |
510 >::type | |
511 { | |
512 private: | |
513 typedef typename boost::log::sources::aux::inherit_features< | |
514 basic_logger< CharT, FinalT, single_thread_model >, | |
515 FeaturesT | |
516 >::type base_type; | |
517 | |
518 protected: | |
519 typedef basic_composite_logger logger_base; | |
520 BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base) | |
521 | |
522 public: | |
523 typedef typename base_type::threading_model threading_model; | |
524 | |
525 #endif // !defined(BOOST_LOG_NO_THREADS) | |
526 | |
527 public: | |
528 basic_composite_logger() {} | |
529 basic_composite_logger(basic_composite_logger const& that) : | |
530 base_type(static_cast< base_type const& >(that)) | |
531 { | |
532 } | |
533 basic_composite_logger(BOOST_RV_REF(logger_base) that) : | |
534 base_type(boost::move(static_cast< base_type& >(that))) | |
535 { | |
536 } | |
537 template< typename ArgsT > | |
538 explicit basic_composite_logger(ArgsT const& args) : base_type(args) | |
539 { | |
540 } | |
541 | |
542 std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr) | |
543 { | |
544 return base_type::add_attribute_unlocked(name, attr); | |
545 } | |
546 void remove_attribute(attribute_set::iterator it) | |
547 { | |
548 base_type::remove_attribute_unlocked(it); | |
549 } | |
550 void remove_all_attributes() | |
551 { | |
552 base_type::remove_all_attributes_unlocked(); | |
553 } | |
554 attribute_set get_attributes() const | |
555 { | |
556 return base_type::get_attributes_unlocked(); | |
557 } | |
558 void set_attributes(attribute_set const& attrs) | |
559 { | |
560 base_type::set_attributes_unlocked(attrs); | |
561 } | |
562 record open_record() | |
563 { | |
564 // Perform a quick check first | |
565 if (this->core()->get_logging_enabled()) | |
566 return base_type::open_record_unlocked(boost::log::aux::empty_arg_list()); | |
567 else | |
568 return record(); | |
569 } | |
570 template< typename ArgsT > | |
571 record open_record(ArgsT const& args) | |
572 { | |
573 // Perform a quick check first | |
574 if (this->core()->get_logging_enabled()) | |
575 return base_type::open_record_unlocked(args); | |
576 else | |
577 return record(); | |
578 } | |
579 void push_record(BOOST_RV_REF(record) rec) | |
580 { | |
581 base_type::push_record_unlocked(boost::move(rec)); | |
582 } | |
583 void swap(basic_composite_logger& that) | |
584 { | |
585 base_type::swap_unlocked(that); | |
586 } | |
587 | |
588 protected: | |
589 FinalT& assign(FinalT that) | |
590 { | |
591 base_type::swap_unlocked(that); | |
592 return static_cast< FinalT& >(*this); | |
593 } | |
594 }; | |
595 | |
596 | |
597 #ifndef BOOST_LOG_DOXYGEN_PASS | |
598 | |
599 #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, typename_keyword)\ | |
600 public:\ | |
601 BOOST_DEFAULTED_FUNCTION(class_type(), {})\ | |
602 class_type(class_type const& that) : class_type::logger_base(\ | |
603 static_cast< typename_keyword() class_type::logger_base const& >(that)) {}\ | |
604 class_type(BOOST_RV_REF(class_type) that) : class_type::logger_base(\ | |
605 ::boost::move(static_cast< typename_keyword() class_type::logger_base& >(that))) {}\ | |
606 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_FORWARD(class_type, class_type::logger_base)\ | |
607 | |
608 #endif // BOOST_LOG_DOXYGEN_PASS | |
609 | |
610 #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS(class_type)\ | |
611 BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, BOOST_PP_EMPTY) | |
612 | |
613 #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_TEMPLATE(class_type)\ | |
614 BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, BOOST_PP_IDENTITY(typename)) | |
615 | |
616 #define BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT(class_type)\ | |
617 public:\ | |
618 class_type& operator= (BOOST_COPY_ASSIGN_REF(class_type) that)\ | |
619 {\ | |
620 return class_type::logger_base::assign(static_cast< class_type const& >(that));\ | |
621 }\ | |
622 class_type& operator= (BOOST_RV_REF(class_type) that)\ | |
623 {\ | |
624 BOOST_LOG_EXPR_IF_MT(::boost::log::aux::exclusive_lock_guard< class_type::threading_model > lock(this->get_threading_model());)\ | |
625 this->swap_unlocked(that);\ | |
626 return *this;\ | |
627 } | |
628 | |
629 #define BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT_TEMPLATE(class_type)\ | |
630 public:\ | |
631 class_type& operator= (BOOST_COPY_ASSIGN_REF(class_type) that)\ | |
632 {\ | |
633 return class_type::logger_base::assign(static_cast< class_type const& >(that));\ | |
634 }\ | |
635 class_type& operator= (BOOST_RV_REF(class_type) that)\ | |
636 {\ | |
637 BOOST_LOG_EXPR_IF_MT(::boost::log::aux::exclusive_lock_guard< typename class_type::threading_model > lock(this->get_threading_model());)\ | |
638 this->swap_unlocked(that);\ | |
639 return *this;\ | |
640 } | |
641 | |
642 #define BOOST_LOG_FORWARD_LOGGER_MEMBERS(class_type)\ | |
643 BOOST_COPYABLE_AND_MOVABLE(class_type)\ | |
644 BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS(class_type)\ | |
645 BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT(class_type) | |
646 | |
647 #define BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(class_type)\ | |
648 BOOST_COPYABLE_AND_MOVABLE(class_type)\ | |
649 BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_TEMPLATE(class_type)\ | |
650 BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT_TEMPLATE(class_type) | |
651 | |
652 } // namespace sources | |
653 | |
654 BOOST_LOG_CLOSE_NAMESPACE // namespace log | |
655 | |
656 } // namespace boost | |
657 | |
658 /*! | |
659 * \brief The macro declares a logger class that inherits a number of base classes | |
660 * | |
661 * \param type_name The name of the logger class to declare | |
662 * \param char_type The character type of the logger. Either char or wchar_t expected. | |
663 * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates | |
664 * \param threading A threading model class | |
665 */ | |
666 #define BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char_type, base_seq, threading)\ | |
667 class type_name :\ | |
668 public ::boost::log::sources::basic_composite_logger<\ | |
669 char_type,\ | |
670 type_name,\ | |
671 threading,\ | |
672 ::boost::log::sources::features< BOOST_PP_SEQ_ENUM(base_seq) >\ | |
673 >\ | |
674 {\ | |
675 BOOST_LOG_FORWARD_LOGGER_MEMBERS(type_name)\ | |
676 } | |
677 | |
678 | |
679 | |
680 #ifdef BOOST_LOG_USE_CHAR | |
681 | |
682 /*! | |
683 * \brief The macro declares a narrow-char logger class that inherits a number of base classes | |
684 * | |
685 * Equivalent to BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, single_thread_model) | |
686 * | |
687 * \param type_name The name of the logger class to declare | |
688 * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates | |
689 */ | |
690 #define BOOST_LOG_DECLARE_LOGGER(type_name, base_seq)\ | |
691 BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, ::boost::log::sources::single_thread_model) | |
692 | |
693 #if !defined(BOOST_LOG_NO_THREADS) | |
694 | |
695 /*! | |
696 * \brief The macro declares a narrow-char thread-safe logger class that inherits a number of base classes | |
697 * | |
698 * Equivalent to <tt>BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, multi_thread_model< shared_mutex >)</tt> | |
699 * | |
700 * \param type_name The name of the logger class to declare | |
701 * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates | |
702 */ | |
703 #define BOOST_LOG_DECLARE_LOGGER_MT(type_name, base_seq)\ | |
704 BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq,\ | |
705 ::boost::log::sources::multi_thread_model< ::boost::shared_mutex >) | |
706 | |
707 #endif // !defined(BOOST_LOG_NO_THREADS) | |
708 #endif // BOOST_LOG_USE_CHAR | |
709 | |
710 #ifdef BOOST_LOG_USE_WCHAR_T | |
711 | |
712 /*! | |
713 * \brief The macro declares a wide-char logger class that inherits a number of base classes | |
714 * | |
715 * Equivalent to BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, single_thread_model) | |
716 * | |
717 * \param type_name The name of the logger class to declare | |
718 * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates | |
719 */ | |
720 #define BOOST_LOG_DECLARE_WLOGGER(type_name, base_seq)\ | |
721 BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, ::boost::log::sources::single_thread_model) | |
722 | |
723 #if !defined(BOOST_LOG_NO_THREADS) | |
724 | |
725 /*! | |
726 * \brief The macro declares a wide-char thread-safe logger class that inherits a number of base classes | |
727 * | |
728 * Equivalent to <tt>BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, multi_thread_model< shared_mutex >)</tt> | |
729 * | |
730 * \param type_name The name of the logger class to declare | |
731 * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates | |
732 */ | |
733 #define BOOST_LOG_DECLARE_WLOGGER_MT(type_name, base_seq)\ | |
734 BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq,\ | |
735 ::boost::log::sources::multi_thread_model< ::boost::shared_mutex >) | |
736 | |
737 #endif // !defined(BOOST_LOG_NO_THREADS) | |
738 #endif // BOOST_LOG_USE_WCHAR_T | |
739 | |
740 #include <boost/log/detail/footer.hpp> | |
741 | |
742 #endif // BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_ |