IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
WarningContext.h
Go to the documentation of this file.
1 /**
2  * \file IMP/WarningContext.h
3  * \brief Logging and error reporting support.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_CREATE_WARNING_CONTEXT_H
10 #define IMPKERNEL_CREATE_WARNING_CONTEXT_H
11 
12 #include <IMP/kernel_config.h>
13 #include "showable_macros.h"
14 #include <boost/unordered_set.hpp>
15 
16 IMPKERNEL_BEGIN_NAMESPACE
17 #if IMP_HAS_LOG
18 
19 //! Warnings with the same key within the context are only output once.
20 struct IMPKERNELEXPORT WarningContext {
21  mutable boost::unordered_set<std::string> data_;
22 
23  public:
24  void add_warning(std::string key, std::string warning) const;
25  void clear_warnings() const;
26  void dump_warnings() const;
27  ~WarningContext();
28  IMP_SHOWABLE_INLINE(WarningContext, out << data_.size() << " warnings");
29 };
30 #else
31 struct IMPKERNELEXPORT WarningContext {
32  public:
34  void add_warning(std::string, std::string) const {}
35  void clear_warnings() const {}
36  void dump_warnings() const {}
37  void show(std::ostream &) const {}
38 };
39 #endif
40 
41 IMPKERNEL_END_NAMESPACE
42 
43 #endif /* IMPKERNEL_CREATE_WARNING_CONTEXT_H */
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Warnings with the same key within the context are only output once.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
Macros to help with objects that can be printed to a stream.