IMP logo
IMP Reference Guide  2.16.0
The Integrative Modeling Platform
SetLogState.h
Go to the documentation of this file.
1 /**
2  * \file IMP/SetLogState.h \brief A class to change and restore log state
3  *
4  * Copyright 2007-2021 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPKERNEL_SET_LOG_STATE_H
9 #define IMPKERNEL_SET_LOG_STATE_H
10 
11 #include <IMP/kernel_config.h>
12 #include "enums.h"
13 #include "raii_macros.h"
14 #include "value_macros.h"
15 #include <IMP/nullptr.h>
16 
17 IMPKERNEL_BEGIN_NAMESPACE
18 class Object;
19 
20 //! A class to change and restore log state
21 /**
22  To use, create an instance of this class with the log level you
23  want. When it goes out of scope, it will restore the old level.
24 
25 
26  \note This will not keep objects alive; make sure there is also some
27  other ref-counted pointer to them.
28 
29  \ingroup logging
30  */
31 class IMPKERNELEXPORT SetLogState : public RAII {
32  LogLevel level_;
33  Object *obj_;
34  void do_set(Object *o, LogLevel l);
35  void do_reset();
36  void do_show(std::ostream &out) const;
37 
38  public:
40  level_ = DEFAULT;
41  obj_ = nullptr;
42  },
43  { do_set(o, l); }, { do_reset(); }, do_show(out););
44 
45  //! Construct with the desired level and target
46  SetLogState(LogLevel l);
47  void set(LogLevel l);
48 };
49 
51 
52 IMPKERNEL_END_NAMESPACE
53 
54 #endif /* IMPKERNEL_SET_LOG_STATE_H */
Temporarily change something; undo the change when this object is destroyed.
Definition: RAII.h:28
#define IMP_RAII(Name, args, Initialize, Set, Reset, Show)
Declares RAII-style methods in a class.
Definition: raii_macros.h:34
LogLevel
The log levels supported by IMP.
Definition: enums.h:19
A more IMP-like version of the std::vector.
Definition: Vector.h:40
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
Provide a nullptr keyword analog.
Common base class for heavy weight IMP objects.
Definition: Object.h:106
A class to change and restore log state.
Definition: SetLogState.h:31
Basic enumeration types used by IMP.
Macros to help in implementing Value objects.
Macros to aid in writing RAII-style classes.