Panda3D
notifyCategoryProxy.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file notifyCategoryProxy.I
10  * @author drose
11  * @date 2000-03-04
12  */
13 
14 /**
15  * Initializes the proxy object by calling get_category() on the template
16  * class.
17  */
18 template<class GetCategory>
20 init() {
21  if (_ptr == nullptr) {
22  _ptr = GetCategory::get_category();
23  }
24  return _ptr;
25 }
26 
27 /**
28  * Returns a pointer which is assumed to have been already initialized. This
29  * function should only be used in functions that will certainly not execute
30  * at static init time. All of the category methods that are accessed via the
31  * dot operator, e.g. proxy.info(), use this method.
32  */
33 template<class GetCategory>
36  nassertd(_ptr != nullptr) {
37  init();
38  nout << "Uninitialized notify proxy: " << _ptr->get_fullname() << "\n";
39  }
40  return _ptr;
41 }
42 
43 /**
44  * Returns a pointer which is *not* assumed to have been already initialized;
45  * if necessary, it will be initialized before it returns. This function may
46  * be used in functions that might execute at static init time. All of the
47  * category methods that are accessed via the arrow operator, e.g.
48  * proxy->info(), use this method.
49  */
50 template<class GetCategory>
53  return init();
54 }
55 
56 /**
57  *
58  */
59 template<class GetCategory>
61 is_on(NotifySeverity severity) {
62  return get_unsafe_ptr()->is_on(severity);
63 }
64 
65 /**
66  *
67  */
68 #ifdef NOTIFY_DEBUG
69 template<class GetCategory>
71 is_spam() {
72  // Instruct the compiler to optimize for the usual case.
73  return UNLIKELY(get_unsafe_ptr()->is_spam());
74 }
75 #endif
76 
77 /**
78  *
79  */
80 #ifdef NOTIFY_DEBUG
81 template<class GetCategory>
83 is_debug() {
84  // Instruct the compiler to optimize for the usual case.
85  return UNLIKELY(get_unsafe_ptr()->is_debug());
86 }
87 #endif
88 
89 /**
90  *
91  */
92 template<class GetCategory>
94 is_info() {
95  return get_unsafe_ptr()->is_info();
96 }
97 
98 /**
99  *
100  */
101 template<class GetCategory>
103 is_warning() {
104  return get_unsafe_ptr()->is_warning();
105 }
106 
107 /**
108  *
109  */
110 template<class GetCategory>
112 is_error() {
113  return get_unsafe_ptr()->is_error();
114 }
115 
116 /**
117  *
118  */
119 template<class GetCategory>
121 is_fatal() {
122  return get_unsafe_ptr()->is_fatal();
123 }
124 
125 /**
126  *
127  */
128 template<class GetCategory>
129 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
130 out(NotifySeverity severity, bool prefix) {
131  return get_unsafe_ptr()->out(severity, prefix);
132 }
133 
134 /**
135  *
136  */
137 template<class GetCategory>
138 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
139 spam(bool prefix) {
140  return get_unsafe_ptr()->spam(prefix);
141 }
142 
143 /**
144  *
145  */
146 template<class GetCategory>
147 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
148 debug(bool prefix) {
149  return get_unsafe_ptr()->debug(prefix);
150 }
151 
152 /**
153  *
154  */
155 template<class GetCategory>
156 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
157 info(bool prefix) {
158  return get_unsafe_ptr()->info(prefix);
159 }
160 
161 /**
162  *
163  */
164 template<class GetCategory>
165 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
166 warning(bool prefix) {
167  return get_unsafe_ptr()->warning(prefix);
168 }
169 
170 /**
171  *
172  */
173 template<class GetCategory>
174 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
175 error(bool prefix) {
176  return get_unsafe_ptr()->error(prefix);
177 }
178 
179 /**
180  *
181  */
182 template<class GetCategory>
183 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
184 fatal(bool prefix) {
185  return get_unsafe_ptr()->fatal(prefix);
186 }
187 
188 /**
189  * This magic operator function defines the syntax proxy->info(), etc., for
190  * all of the methods that are defined for NotifyCategory. It's designed to
191  * vector through get_safe_ptr(), so this syntax is safe for functions that
192  * may execute at static init time.
193  */
194 template<class GetCategory>
197  return get_safe_ptr();
198 }
199 
200 /**
201  * This operator handles the case of dereferencing the proxy object as if it
202  * were a pointer, e.g. (*proxy).info(). It works the same way as the ->
203  * operator, above.
204  */
205 template<class GetCategory>
208  return *get_safe_ptr();
209 }
210 
211 /**
212  * This operator handles the case of passing the proxy object to a function
213  * that accepts a NotifyCategory pointer. It works the same way as the -> and
214  * * operators, above.
215  */
216 template<class GetCategory>
218 operator NotifyCategory * () {
219  return get_safe_ptr();
220 }
NotifyCategory * get_unsafe_ptr()
Returns a pointer which is assumed to have been already initialized.
A handy wrapper around a NotifyCategory pointer.
A particular category of error messages.
NotifyCategory * operator ->()
This magic operator function defines the syntax proxy->info(), etc., for all of the methods that are ...
NotifyCategory & operator *()
This operator handles the case of dereferencing the proxy object as if it were a pointer,...
NotifyCategory * get_safe_ptr()
Returns a pointer which is *not* assumed to have been already initialized; if necessary,...
NotifyCategory * init()
Initializes the proxy object by calling get_category() on the template class.