IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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
16IMPKERNEL_BEGIN_NAMESPACE
17class Object;
18
19//! A class to change and restore log state
20/**
21 To use, create an instance of this class with the log level you
22 want. When it goes out of scope, it will restore the old level.
23
24
25 \note This will not keep objects alive; make sure there is also some
26 other ref-counted pointer to them.
27
28 \ingroup logging
29 */
30class IMPKERNELEXPORT SetLogState : public RAII {
31 LogLevel level_;
32 Object *obj_;
33 void do_set(Object *o, LogLevel l);
34 void do_reset();
35 void do_show(std::ostream &out) const;
36
37 public:
38 IMP_RAII(SetLogState, (Object *o, LogLevel l), {
39 level_ = DEFAULT;
40 obj_ = nullptr;
41 },
42 { do_set(o, l); }, { if (level_ != DEFAULT) do_reset(); }, do_show(out););
43
44 //! Construct with the desired level and target
46 obj_ = nullptr;
47 level_ = DEFAULT;
48 if (l != DEFAULT) set(l);
49 }
50 void set(LogLevel l);
51};
52
54
55IMPKERNEL_END_NAMESPACE
56
57#endif /* IMPKERNEL_SET_LOG_STATE_H */
Common base class for heavy weight IMP objects.
Definition Object.h:111
A class to change and restore log state.
Definition SetLogState.h:30
SetLogState(LogLevel l)
Construct with the desired level and target.
Definition SetLogState.h:45
void set(Object *o, LogLevel l)
Assign new properties to the class.
Definition SetLogState.h:42
Basic enumeration types used by IMP.
IMP::Vector< SetLogState > SetLogStates
Definition SetLogState.h:53
LogLevel
The log levels supported by IMP.
Definition enums.h:19
@ DEFAULT
Definition enums.h:22
Macros to aid in writing RAII-style classes.
#define IMP_RAII(Name, args, Initialize, Set, Reset, Show)
Declares RAII-style methods in a class.
Definition raii_macros.h:34
Macros to help in implementing Value objects.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.