Panda3D
|
00001 // Filename: notifyCategoryProxy.I 00002 // Created by: drose (04Mar00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 //////////////////////////////////////////////////////////////////// 00016 // Function: NotifyCategoryProxy::init() 00017 // Access: Public 00018 // Description: Initializes the proxy object by calling 00019 // get_category() on the template class. 00020 //////////////////////////////////////////////////////////////////// 00021 template<class GetCategory> 00022 NotifyCategory *NotifyCategoryProxy<GetCategory>:: 00023 init() { 00024 if (_ptr == (NotifyCategory *)NULL) { 00025 _ptr = GetCategory::get_category(); 00026 } 00027 return _ptr; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: NotifyCategoryProxy::get_unsafe_ptr() 00032 // Access: Public 00033 // Description: Returns a pointer which is assumed to have been 00034 // already initialized. This function should only be 00035 // used in functions that will certainly not execute at 00036 // static init time. All of the category methods that 00037 // are accessed via the dot operator, e.g. proxy.info(), 00038 // use this method. 00039 //////////////////////////////////////////////////////////////////// 00040 template<class GetCategory> 00041 INLINE NotifyCategory *NotifyCategoryProxy<GetCategory>:: 00042 get_unsafe_ptr() { 00043 nassertd(_ptr != (NotifyCategory *)NULL) { 00044 init(); 00045 nout << "Uninitialized notify proxy: " << _ptr->get_fullname() << "\n"; 00046 } 00047 return _ptr; 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: NotifyCategoryProxy::get_safe_ptr() 00052 // Access: Public 00053 // Description: Returns a pointer which is *not* assumed to have been 00054 // already initialized; if necessary, it will be 00055 // initialized before it returns. This function may be 00056 // used in functions that might execute at static init 00057 // time. All of the category methods that are accessed 00058 // via the arrow operator, e.g. proxy->info(), use this 00059 // method. 00060 //////////////////////////////////////////////////////////////////// 00061 template<class GetCategory> 00062 INLINE NotifyCategory *NotifyCategoryProxy<GetCategory>:: 00063 get_safe_ptr() { 00064 return init(); 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: NotifyCategoryProxy::is_on 00069 // Access: Public 00070 // Description: 00071 //////////////////////////////////////////////////////////////////// 00072 template<class GetCategory> 00073 INLINE bool NotifyCategoryProxy<GetCategory>:: 00074 is_on(NotifySeverity severity) { 00075 return get_unsafe_ptr()->is_on(severity); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: NotifyCategoryProxy::is_spam 00080 // Access: Public 00081 // Description: 00082 //////////////////////////////////////////////////////////////////// 00083 template<class GetCategory> 00084 INLINE bool NotifyCategoryProxy<GetCategory>:: 00085 is_spam() { 00086 #ifdef NOTIFY_DEBUG 00087 return get_unsafe_ptr()->is_spam(); 00088 #else 00089 return false; 00090 #endif 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: NotifyCategoryProxy::is_debug 00095 // Access: Public 00096 // Description: 00097 //////////////////////////////////////////////////////////////////// 00098 template<class GetCategory> 00099 INLINE bool NotifyCategoryProxy<GetCategory>:: 00100 is_debug() { 00101 #ifdef NOTIFY_DEBUG 00102 return get_unsafe_ptr()->is_debug(); 00103 #else 00104 return false; 00105 #endif 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: NotifyCategoryProxy::is_info 00110 // Access: Public 00111 // Description: 00112 //////////////////////////////////////////////////////////////////// 00113 template<class GetCategory> 00114 INLINE bool NotifyCategoryProxy<GetCategory>:: 00115 is_info() { 00116 return get_unsafe_ptr()->is_info(); 00117 } 00118 00119 //////////////////////////////////////////////////////////////////// 00120 // Function: NotifyCategoryProxy::is_warning 00121 // Access: Public 00122 // Description: 00123 //////////////////////////////////////////////////////////////////// 00124 template<class GetCategory> 00125 INLINE bool NotifyCategoryProxy<GetCategory>:: 00126 is_warning() { 00127 return get_unsafe_ptr()->is_warning(); 00128 } 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Function: NotifyCategoryProxy::is_error 00132 // Access: Public 00133 // Description: 00134 //////////////////////////////////////////////////////////////////// 00135 template<class GetCategory> 00136 INLINE bool NotifyCategoryProxy<GetCategory>:: 00137 is_error() { 00138 return get_unsafe_ptr()->is_error(); 00139 } 00140 00141 //////////////////////////////////////////////////////////////////// 00142 // Function: NotifyCategoryProxy::is_fatal 00143 // Access: Public 00144 // Description: 00145 //////////////////////////////////////////////////////////////////// 00146 template<class GetCategory> 00147 INLINE bool NotifyCategoryProxy<GetCategory>:: 00148 is_fatal() { 00149 return get_unsafe_ptr()->is_fatal(); 00150 } 00151 00152 //////////////////////////////////////////////////////////////////// 00153 // Function: NotifyCategoryProxy::out 00154 // Access: Public 00155 // Description: 00156 //////////////////////////////////////////////////////////////////// 00157 template<class GetCategory> 00158 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00159 out(NotifySeverity severity, bool prefix) { 00160 return get_unsafe_ptr()->out(severity, prefix); 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function: NotifyCategoryProxy::spam 00165 // Access: Public 00166 // Description: 00167 //////////////////////////////////////////////////////////////////// 00168 template<class GetCategory> 00169 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00170 spam(bool prefix) { 00171 return get_unsafe_ptr()->spam(prefix); 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: NotifyCategoryProxy::debug 00176 // Access: Public 00177 // Description: 00178 //////////////////////////////////////////////////////////////////// 00179 template<class GetCategory> 00180 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00181 debug(bool prefix) { 00182 return get_unsafe_ptr()->debug(prefix); 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function: NotifyCategoryProxy::info 00187 // Access: Public 00188 // Description: 00189 //////////////////////////////////////////////////////////////////// 00190 template<class GetCategory> 00191 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00192 info(bool prefix) { 00193 return get_unsafe_ptr()->info(prefix); 00194 } 00195 00196 //////////////////////////////////////////////////////////////////// 00197 // Function: NotifyCategoryProxy::warning 00198 // Access: Public 00199 // Description: 00200 //////////////////////////////////////////////////////////////////// 00201 template<class GetCategory> 00202 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00203 warning(bool prefix) { 00204 return get_unsafe_ptr()->warning(prefix); 00205 } 00206 00207 //////////////////////////////////////////////////////////////////// 00208 // Function: NotifyCategoryProxy::error 00209 // Access: Public 00210 // Description: 00211 //////////////////////////////////////////////////////////////////// 00212 template<class GetCategory> 00213 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00214 error(bool prefix) { 00215 return get_unsafe_ptr()->error(prefix); 00216 } 00217 00218 //////////////////////////////////////////////////////////////////// 00219 // Function: NotifyCategoryProxy::fatal 00220 // Access: Public 00221 // Description: 00222 //////////////////////////////////////////////////////////////////// 00223 template<class GetCategory> 00224 INLINE ostream &NotifyCategoryProxy<GetCategory>:: 00225 fatal(bool prefix) { 00226 return get_unsafe_ptr()->fatal(prefix); 00227 } 00228 00229 //////////////////////////////////////////////////////////////////// 00230 // Function: NotifyCategoryProxy::Member Access Operator 00231 // Access: Public 00232 // Description: This magic operator function defines the syntax 00233 // proxy->info(), etc., for all of the methods that are 00234 // defined for NotifyCategory. It's designed to vector 00235 // through get_safe_ptr(), so this syntax is safe for 00236 // functions that may execute at static init time. 00237 //////////////////////////////////////////////////////////////////// 00238 template<class GetCategory> 00239 INLINE NotifyCategory *NotifyCategoryProxy<GetCategory>:: 00240 operator -> () { 00241 return get_safe_ptr(); 00242 } 00243 00244 //////////////////////////////////////////////////////////////////// 00245 // Function: NotifyCategoryProxy::Dereference Operator 00246 // Access: Public 00247 // Description: This operator handles the case of dereferencing the 00248 // proxy object as if it were a pointer, 00249 // e.g. (*proxy).info(). It works the same way as the 00250 // -> operator, above. 00251 //////////////////////////////////////////////////////////////////// 00252 template<class GetCategory> 00253 INLINE NotifyCategory &NotifyCategoryProxy<GetCategory>:: 00254 operator * () { 00255 return *get_safe_ptr(); 00256 } 00257 00258 //////////////////////////////////////////////////////////////////// 00259 // Function: NotifyCategoryProxy::Typecast Operator 00260 // Access: Public 00261 // Description: This operator handles the case of passing the 00262 // proxy object to a function that accepts a 00263 // NotifyCategory pointer. It works the same way as the 00264 // -> and * operators, above. 00265 //////////////////////////////////////////////////////////////////// 00266 template<class GetCategory> 00267 INLINE NotifyCategoryProxy<GetCategory>:: 00268 operator NotifyCategory * () { 00269 return get_safe_ptr(); 00270 }