1
1
/**************************************************************************
3
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
3
(C) 2008 - 2012 Alexander Shaduri <ashaduri 'at' gmail.com>
4
4
License: See LICENSE_zlib.txt file
5
5
***************************************************************************/
7
/// \author Alexander Shaduri
9
/// \weakgroup libdebug
7
12
#ifndef LIBDEBUG_DSTATE_H
8
13
#define LIBDEBUG_DSTATE_H
30
35
// domain name "all" - used for manipulating all domains.
38
/// Libdebug global state
42
/// Debug output stream strong reference-holding pointer
36
43
typedef hz::intrusive_ptr<DebugOutStream> out_stream_ptr;
45
/// A mapping of debug levels to respective streams
37
46
typedef std::map<debug_level::flag, out_stream_ptr> level_map_t;
48
/// A mapping of domains to debug level maps with streams
38
49
typedef std::map<std::string, level_map_t> domain_map_t;
52
/// Constructor (statically called), calls setup_default_state().
43
55
setup_default_state();
47
// This function is NOT thread-safe. Call it before using any
48
// other functions in MT environment.
49
// Automatically called by constructor, so usually no problem there.
59
/// Initialize the "default" template domain, set the default enabled levels / format flags.
60
/// This function is NOT thread-safe. Call it before using any
61
/// other functions in MT environment. Automatically called by constructor.
50
62
void setup_default_state();
53
// This is function thread-safe in read-only context.
65
/// Get the domain/level mapping.
66
/// This is function thread-safe in read-only context.
54
67
domain_map_t& get_domain_map()
60
// This is function thread-safe.
73
/// Get current indentation level. This is function thread-safe.
61
74
int get_indent_level() const
63
76
if (!indent_level_.get())
111
// Flush all the buffers. This will write prefixes too.
112
// This is function thread-safe in read-only context.
124
/// Flush all the stream buffers. This will write prefixes too.
125
/// This is function thread-safe in read-only context.
113
126
void force_output()
115
128
for(domain_map_t::iterator iter = domain_map.begin(); iter != domain_map.end(); ++iter) {
124
// without mutable there's no on-demand allocation for these
137
// Without mutable there's no on-demand allocation for these.
125
138
// It's thread-local because it is not shared between different flows.
126
// we can't provide any manual cleanup, because the only one we can do
139
// We can't provide any manual cleanup, because the only one we can do
127
140
// is in main thread, and it's already being done with the destructor.
128
mutable hz::thread_local_ptr<int> indent_level_;
129
mutable hz::thread_local_ptr<std::stack<bool> > inside_begin_; // true if inside begin() / end() block
131
domain_map_t domain_map;
142
mutable hz::thread_local_ptr<int> indent_level_; ///< Current indentation level
143
mutable hz::thread_local_ptr<std::stack<bool> > inside_begin_; ///< True if inside debug_begin() / debug_end() block
145
domain_map_t domain_map; ///< Domain / debug level mapping.
151
/// Get global libdebug state
137
152
DebugState& get_debug_state();