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>
52 get_safe_ptr() {
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 template<class GetCategory>
70 is_spam() {
71 #ifdef NOTIFY_DEBUG
72  // Instruct the compiler to optimize for the usual case.
73  return UNLIKELY(get_unsafe_ptr()->is_spam());
74 #else
75  return false;
76 #endif
77 }
78 
79 /**
80  *
81  */
82 template<class GetCategory>
84 is_debug() {
85 #ifdef NOTIFY_DEBUG
86  // Instruct the compiler to optimize for the usual case.
87  return UNLIKELY(get_unsafe_ptr()->is_debug());
88 #else
89  return false;
90 #endif
91 }
92 
93 /**
94  *
95  */
96 template<class GetCategory>
98 is_info() {
99  return get_unsafe_ptr()->is_info();
100 }
101 
102 /**
103  *
104  */
105 template<class GetCategory>
107 is_warning() {
108  return get_unsafe_ptr()->is_warning();
109 }
110 
111 /**
112  *
113  */
114 template<class GetCategory>
116 is_error() {
117  return get_unsafe_ptr()->is_error();
118 }
119 
120 /**
121  *
122  */
123 template<class GetCategory>
125 is_fatal() {
126  return get_unsafe_ptr()->is_fatal();
127 }
128 
129 /**
130  *
131  */
132 template<class GetCategory>
133 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
134 out(NotifySeverity severity, bool prefix) {
135  return get_unsafe_ptr()->out(severity, prefix);
136 }
137 
138 /**
139  *
140  */
141 template<class GetCategory>
142 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
143 spam(bool prefix) {
144  return get_unsafe_ptr()->spam(prefix);
145 }
146 
147 /**
148  *
149  */
150 template<class GetCategory>
151 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
152 debug(bool prefix) {
153  return get_unsafe_ptr()->debug(prefix);
154 }
155 
156 /**
157  *
158  */
159 template<class GetCategory>
160 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
161 info(bool prefix) {
162  return get_unsafe_ptr()->info(prefix);
163 }
164 
165 /**
166  *
167  */
168 template<class GetCategory>
169 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
170 warning(bool prefix) {
171  return get_unsafe_ptr()->warning(prefix);
172 }
173 
174 /**
175  *
176  */
177 template<class GetCategory>
178 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
179 error(bool prefix) {
180  return get_unsafe_ptr()->error(prefix);
181 }
182 
183 /**
184  *
185  */
186 template<class GetCategory>
187 INLINE std::ostream &NotifyCategoryProxy<GetCategory>::
188 fatal(bool prefix) {
189  return get_unsafe_ptr()->fatal(prefix);
190 }
191 
192 /**
193  * This magic operator function defines the syntax proxy->info(), etc., for
194  * all of the methods that are defined for NotifyCategory. It's designed to
195  * vector through get_safe_ptr(), so this syntax is safe for functions that
196  * may execute at static init time.
197  */
198 template<class GetCategory>
200 operator -> () {
201  return get_safe_ptr();
202 }
203 
204 /**
205  * This operator handles the case of dereferencing the proxy object as if it
206  * were a pointer, e.g. (*proxy).info(). It works the same way as the ->
207  * operator, above.
208  */
209 template<class GetCategory>
211 operator * () {
212  return *get_safe_ptr();
213 }
214 
215 /**
216  * This operator handles the case of passing the proxy object to a function
217  * that accepts a NotifyCategory pointer. It works the same way as the -> and
218  * * operators, above.
219  */
220 template<class GetCategory>
222 operator NotifyCategory * () {
223  return get_safe_ptr();
224 }
A handy wrapper around a NotifyCategory pointer.
NotifyCategory & operator*()
This operator handles the case of dereferencing the proxy object as if it were a pointer,...
NotifyCategory * get_unsafe_ptr()
Returns a pointer which is assumed to have been already initialized.
NotifyCategory * init()
Initializes the proxy object by calling get_category() on the template class.
NotifyCategory * get_safe_ptr()
Returns a pointer which is *not* assumed to have been already initialized; if necessary,...
NotifyCategory * operator->()
This magic operator function defines the syntax proxy->info(), etc., for all of the methods that are ...
A particular category of error messages.
std::ostream & fatal(bool prefix=true) const
A shorthand way to write out(NS_fatal).
bool is_error() const
A shorthand way to write is_on(NS_error).
bool is_on(NotifySeverity severity) const
Returns true if messages of the indicated severity level ought to be reported for this Category.
std::ostream & debug(bool prefix=true) const
A shorthand way to write out(NS_debug).
std::ostream & info(bool prefix=true) const
A shorthand way to write out(NS_info).
std::ostream & out(NotifySeverity severity, bool prefix=true) const
Begins a new message to this Category at the indicated severity level.
std::ostream & spam(bool prefix=true) const
A shorthand way to write out(NS_spam).
std::ostream & warning(bool prefix=true) const
A shorthand way to write out(NS_warning).
bool is_info() const
A shorthand way to write is_on(NS_info).
std::ostream & error(bool prefix=true) const
A shorthand way to write out(NS_error).
bool is_fatal() const
A shorthand way to write is_on(NS_fatal).
bool is_warning() const
A shorthand way to write is_on(NS_warning).