~ubuntu-branches/debian/sid/gsmartcontrol/sid

« back to all changes in this revision

Viewing changes to src/libdebug/dstate.h

  • Committer: Package Import Robot
  • Author(s): Giuseppe Iuculano
  • Date: 2013-05-31 11:41:52 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130531114152-5ljhkuswwpt4kdwo
Tags: 0.8.7-1
* [314881d] Updated debian/watch
* [18ebada] Imported Upstream version 0.8.7
* [c2a1f1b] debian/rules: Provide build-arch and build-indep
* [d3036a4] Enabled Hardening Options
* [2edfb87] Refreshed patches and removed patches apllied upstream
* [ac3b953] Bump to standard versions 3.9.4
* [292c276] Remove quilt from depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**************************************************************************
2
2
 Copyright:
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
***************************************************************************/
 
6
/// \file
 
7
/// \author Alexander Shaduri
 
8
/// \ingroup libdebug
 
9
/// \weakgroup libdebug
 
10
/// @{
6
11
 
7
12
#ifndef LIBDEBUG_DSTATE_H
8
13
#define LIBDEBUG_DSTATE_H
30
35
        // domain name "all" - used for manipulating all domains.
31
36
 
32
37
 
 
38
        /// Libdebug global state
33
39
        class DebugState {
34
40
                public:
35
41
 
 
42
                        /// Debug output stream strong reference-holding pointer
36
43
                        typedef hz::intrusive_ptr<DebugOutStream> out_stream_ptr;
 
44
 
 
45
                        /// A mapping of debug levels to respective streams
37
46
                        typedef std::map<debug_level::flag, out_stream_ptr> level_map_t;
 
47
 
 
48
                        /// A mapping of domains to debug level maps with streams
38
49
                        typedef std::map<std::string, level_map_t> domain_map_t;
39
50
 
40
51
 
 
52
                        /// Constructor (statically called), calls setup_default_state().
41
53
                        DebugState()
42
54
                        {
43
55
                                setup_default_state();
44
56
                        }
45
57
 
46
58
 
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();
51
63
 
52
64
 
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()
55
68
                        {
56
69
                                return domain_map;
57
70
                        }
58
71
 
59
72
 
60
 
                        // This is function thread-safe.
 
73
                        /// Get current indentation level. This is function thread-safe.
61
74
                        int get_indent_level() const
62
75
                        {
63
76
                                if (!indent_level_.get())
65
78
                                return *indent_level_;
66
79
                        }
67
80
 
68
 
                        // This is function thread-safe.
 
81
                        /// Set current indentation level. This is function thread-safe.
69
82
                        void set_indent_level(int indent_level)
70
83
                        {
71
84
                                if (!indent_level_.get()) {
75
88
                                }
76
89
                        }
77
90
 
78
 
                        // This is function thread-safe.
 
91
                        /// Open a debug_begin() context. This is function thread-safe.
79
92
                        void push_inside_begin(bool value = true)
80
93
                        {
81
94
                                if (!inside_begin_.get())
83
96
                                inside_begin_->push(value);
84
97
                        }
85
98
 
86
 
                        // This is function thread-safe.
 
99
                        /// Close a debug_begin() context. This is function thread-safe.
87
100
                        bool pop_inside_begin()
88
101
                        {
89
102
                                if (!inside_begin_.get())
96
109
                                return val;
97
110
                        }
98
111
 
99
 
                        // This is function thread-safe.
 
112
                        /// Check if we're inside a debug_begin() context. This is function thread-safe.
100
113
                        bool get_inside_begin() const
101
114
                        {
102
115
                                if (!inside_begin_.get())
108
121
                        }
109
122
 
110
123
 
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()
114
127
                        {
115
128
                                for(domain_map_t::iterator iter = domain_map.begin(); iter != domain_map.end(); ++iter) {
121
134
 
122
135
                private:
123
136
 
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
130
 
 
131
 
                        domain_map_t domain_map;
 
141
 
 
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
 
144
 
 
145
                        domain_map_t domain_map;  ///< Domain / debug level mapping.
132
146
 
133
147
        };
134
148
 
135
149
 
136
150
 
 
151
        /// Get global libdebug state
137
152
        DebugState& get_debug_state();
138
153
 
139
154
 
147
162
 
148
163
 
149
164
#endif
 
165
 
 
166
/// @}