Panda3D
 All Classes Functions Variables Enumerations
notifyCategoryProxy.I
1 // Filename: notifyCategoryProxy.I
2 // Created by: drose (04Mar00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: NotifyCategoryProxy::init()
17 // Access: Public
18 // Description: Initializes the proxy object by calling
19 // get_category() on the template class.
20 ////////////////////////////////////////////////////////////////////
21 template<class GetCategory>
23 init() {
24  if (_ptr == (NotifyCategory *)NULL) {
25  _ptr = GetCategory::get_category();
26  }
27  return _ptr;
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: NotifyCategoryProxy::get_unsafe_ptr()
32 // Access: Public
33 // Description: Returns a pointer which is assumed to have been
34 // already initialized. This function should only be
35 // used in functions that will certainly not execute at
36 // static init time. All of the category methods that
37 // are accessed via the dot operator, e.g. proxy.info(),
38 // use this method.
39 ////////////////////////////////////////////////////////////////////
40 template<class GetCategory>
43  nassertd(_ptr != (NotifyCategory *)NULL) {
44  init();
45  nout << "Uninitialized notify proxy: " << _ptr->get_fullname() << "\n";
46  }
47  return _ptr;
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: NotifyCategoryProxy::get_safe_ptr()
52 // Access: Public
53 // Description: Returns a pointer which is *not* assumed to have been
54 // already initialized; if necessary, it will be
55 // initialized before it returns. This function may be
56 // used in functions that might execute at static init
57 // time. All of the category methods that are accessed
58 // via the arrow operator, e.g. proxy->info(), use this
59 // method.
60 ////////////////////////////////////////////////////////////////////
61 template<class GetCategory>
64  return init();
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: NotifyCategoryProxy::is_on
69 // Access: Public
70 // Description:
71 ////////////////////////////////////////////////////////////////////
72 template<class GetCategory>
74 is_on(NotifySeverity severity) {
75  return get_unsafe_ptr()->is_on(severity);
76 }
77 
78 ////////////////////////////////////////////////////////////////////
79 // Function: NotifyCategoryProxy::is_spam
80 // Access: Public
81 // Description:
82 ////////////////////////////////////////////////////////////////////
83 #ifdef NOTIFY_DEBUG
84 template<class GetCategory>
86 is_spam() {
87  return get_unsafe_ptr()->is_spam();
88 }
89 #else
90 template<class GetCategory>
92 is_spam() {
93  return false;
94 }
95 #endif
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: NotifyCategoryProxy::is_debug
99 // Access: Public
100 // Description:
101 ////////////////////////////////////////////////////////////////////
102 #ifdef NOTIFY_DEBUG
103 template<class GetCategory>
105 is_debug() {
106  return get_unsafe_ptr()->is_debug();
107 }
108 #else
109 template<class GetCategory>
111 is_debug() {
112  return false;
113 }
114 #endif
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: NotifyCategoryProxy::is_info
118 // Access: Public
119 // Description:
120 ////////////////////////////////////////////////////////////////////
121 template<class GetCategory>
123 is_info() {
124  return get_unsafe_ptr()->is_info();
125 }
126 
127 ////////////////////////////////////////////////////////////////////
128 // Function: NotifyCategoryProxy::is_warning
129 // Access: Public
130 // Description:
131 ////////////////////////////////////////////////////////////////////
132 template<class GetCategory>
134 is_warning() {
135  return get_unsafe_ptr()->is_warning();
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: NotifyCategoryProxy::is_error
140 // Access: Public
141 // Description:
142 ////////////////////////////////////////////////////////////////////
143 template<class GetCategory>
145 is_error() {
146  return get_unsafe_ptr()->is_error();
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: NotifyCategoryProxy::is_fatal
151 // Access: Public
152 // Description:
153 ////////////////////////////////////////////////////////////////////
154 template<class GetCategory>
156 is_fatal() {
157  return get_unsafe_ptr()->is_fatal();
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: NotifyCategoryProxy::out
162 // Access: Public
163 // Description:
164 ////////////////////////////////////////////////////////////////////
165 template<class GetCategory>
167 out(NotifySeverity severity, bool prefix) {
168  return get_unsafe_ptr()->out(severity, prefix);
169 }
170 
171 ////////////////////////////////////////////////////////////////////
172 // Function: NotifyCategoryProxy::spam
173 // Access: Public
174 // Description:
175 ////////////////////////////////////////////////////////////////////
176 template<class GetCategory>
178 spam(bool prefix) {
179  return get_unsafe_ptr()->spam(prefix);
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: NotifyCategoryProxy::debug
184 // Access: Public
185 // Description:
186 ////////////////////////////////////////////////////////////////////
187 template<class GetCategory>
189 debug(bool prefix) {
190  return get_unsafe_ptr()->debug(prefix);
191 }
192 
193 ////////////////////////////////////////////////////////////////////
194 // Function: NotifyCategoryProxy::info
195 // Access: Public
196 // Description:
197 ////////////////////////////////////////////////////////////////////
198 template<class GetCategory>
200 info(bool prefix) {
201  return get_unsafe_ptr()->info(prefix);
202 }
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: NotifyCategoryProxy::warning
206 // Access: Public
207 // Description:
208 ////////////////////////////////////////////////////////////////////
209 template<class GetCategory>
211 warning(bool prefix) {
212  return get_unsafe_ptr()->warning(prefix);
213 }
214 
215 ////////////////////////////////////////////////////////////////////
216 // Function: NotifyCategoryProxy::error
217 // Access: Public
218 // Description:
219 ////////////////////////////////////////////////////////////////////
220 template<class GetCategory>
222 error(bool prefix) {
223  return get_unsafe_ptr()->error(prefix);
224 }
225 
226 ////////////////////////////////////////////////////////////////////
227 // Function: NotifyCategoryProxy::fatal
228 // Access: Public
229 // Description:
230 ////////////////////////////////////////////////////////////////////
231 template<class GetCategory>
233 fatal(bool prefix) {
234  return get_unsafe_ptr()->fatal(prefix);
235 }
236 
237 ////////////////////////////////////////////////////////////////////
238 // Function: NotifyCategoryProxy::Member Access Operator
239 // Access: Public
240 // Description: This magic operator function defines the syntax
241 // proxy->info(), etc., for all of the methods that are
242 // defined for NotifyCategory. It's designed to vector
243 // through get_safe_ptr(), so this syntax is safe for
244 // functions that may execute at static init time.
245 ////////////////////////////////////////////////////////////////////
246 template<class GetCategory>
249  return get_safe_ptr();
250 }
251 
252 ////////////////////////////////////////////////////////////////////
253 // Function: NotifyCategoryProxy::Dereference Operator
254 // Access: Public
255 // Description: This operator handles the case of dereferencing the
256 // proxy object as if it were a pointer,
257 // e.g. (*proxy).info(). It works the same way as the
258 // -> operator, above.
259 ////////////////////////////////////////////////////////////////////
260 template<class GetCategory>
263  return *get_safe_ptr();
264 }
265 
266 ////////////////////////////////////////////////////////////////////
267 // Function: NotifyCategoryProxy::Typecast Operator
268 // Access: Public
269 // Description: This operator handles the case of passing the
270 // proxy object to a function that accepts a
271 // NotifyCategory pointer. It works the same way as the
272 // -> and * operators, above.
273 ////////////////////////////////////////////////////////////////////
274 template<class GetCategory>
276 operator NotifyCategory * () {
277  return get_safe_ptr();
278 }
NotifyCategory & operator*()
This operator handles the case of dereferencing the proxy object as if it were a pointer, e.g.
ostream & spam(bool prefix=true) const
A shorthand way to write out(NS_spam).
ostream & fatal(bool prefix=true) const
A shorthand way to write out(NS_fatal).
bool is_warning() const
A shorthand way to write is_on(NS_warning).
NotifyCategory * get_unsafe_ptr()
Returns a pointer which is assumed to have been already initialized.
ostream & info(bool prefix=true) const
A shorthand way to write out(NS_info).
bool is_fatal() const
A shorthand way to write is_on(NS_fatal).
A handy wrapper around a NotifyCategory pointer.
static CONSTEXPR bool is_debug()
When NOTIFY_DEBUG is not defined, the categories are never set to &quot;spam&quot; or &quot;debug&quot; severities...
ostream & warning(bool prefix=true) const
A shorthand way to write out(NS_warning).
A particular category of error messages.
NotifyCategory * operator->()
This magic operator function defines the syntax proxy-&gt;info(), etc., for all of the methods that are ...
bool is_on(NotifySeverity severity) const
Returns true if messages of the indicated severity level ought to be reported for this Category...
ostream & error(bool prefix=true) const
A shorthand way to write out(NS_error).
NotifyCategory * get_safe_ptr()
Returns a pointer which is *not* assumed to have been already initialized; if necessary, it will be initialized before it returns.
bool is_error() const
A shorthand way to write is_on(NS_error).
ostream & debug(bool prefix=true) const
A shorthand way to write out(NS_debug).
bool is_info() const
A shorthand way to write is_on(NS_info).
static CONSTEXPR bool is_spam()
When NOTIFY_DEBUG is not defined, the categories are never set to &quot;spam&quot; or &quot;debug&quot; severities...
ostream & out(NotifySeverity severity, bool prefix=true) const
Begins a new message to this Category at the indicated severity level.
NotifyCategory * init()
Initializes the proxy object by calling get_category() on the template class.