Back to index

lightning-sunbird  0.9+nobinonly
nsISupportsObsolete.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is XPCOM.
00015  *
00016  * The Initial Developer of the Original Code is Netscape Communications Corp.
00017  * Portions created by the Initial Developer are Copyright (C) 2001
00018  * the Initial Developer. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  *
00022  * Alternatively, the contents of this file may be used under the terms of
00023  * either the GNU General Public License Version 2 or later (the "GPL"), or
00024  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00025  * in which case the provisions of the GPL or the LGPL are applicable instead
00026  * of those above. If you wish to allow use of your version of this file only
00027  * under the terms of either the GPL or the LGPL, and not to allow others to
00028  * use your version of this file under the terms of the MPL, indicate your
00029  * decision by deleting the provisions above and replace them with the notice
00030  * and other provisions required by the GPL or the LGPL. If you do not delete
00031  * the provisions above, a recipient may use your version of this file under
00032  * the terms of any one of the MPL, the GPL or the LGPL.
00033  *
00034  * ***** END LICENSE BLOCK ***** */
00035 
00036 
00037 #ifndef nsISupportsObsolete_h__
00038 #define nsISupportsObsolete_h__
00039 
00040 #include "prcmon.h"
00041 
00043 
00044 
00045 #define NS_INIT_REFCNT() NS_INIT_ISUPPORTS()
00046 
00062 #define NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(size, array)                    \
00063     NS_FREE_XPCOM_POINTER_ARRAY((size), (array), NS_IF_RELEASE)
00064 
00065 
00067 
00068 /* use these functions to associate get/set methods with a
00069    C++ member variable
00070 */
00071 
00072 #define NS_METHOD_GETTER(_method, _type, _member) \
00073 _method(_type* aResult) \
00074 {\
00075     if (!aResult) return NS_ERROR_NULL_POINTER; \
00076     *aResult = _member; \
00077     return NS_OK; \
00078 }
00079     
00080 #define NS_METHOD_SETTER(_method, _type, _member) \
00081 _method(_type aResult) \
00082 { \
00083     _member = aResult; \
00084     return NS_OK; \
00085 }
00086 
00087 /*
00088  * special for strings to get/set char* strings
00089  * using PL_strdup and PR_FREEIF
00090  */
00091 #define NS_METHOD_GETTER_STR(_method,_member)   \
00092 _method(char* *aString)                         \
00093 {                                               \
00094     if (!aString) return NS_ERROR_NULL_POINTER; \
00095     if (!(*aString = PL_strdup(_member)))       \
00096       return NS_ERROR_OUT_OF_MEMORY;            \
00097     return NS_OK;                               \
00098 }
00099 
00100 #define NS_METHOD_SETTER_STR(_method, _member) \
00101 _method(const char *aString)                   \
00102 {                                              \
00103     if (_member) PR_Free(_member);             \
00104     if (!aString)                              \
00105       _member = nsnull;                        \
00106     else if (!(_member = PL_strdup(aString)))  \
00107       return NS_ERROR_OUT_OF_MEMORY;           \
00108     return NS_OK;                              \
00109 }
00110 
00111 /* Getter/Setter macros.
00112    Usage:
00113    NS_IMPL_[CLASS_]GETTER[_<type>](method, [type,] member);
00114    NS_IMPL_[CLASS_]SETTER[_<type>](method, [type,] member);
00115    NS_IMPL_[CLASS_]GETSET[_<type>]([class, ]postfix, [type,] member);
00116    
00117    where:
00118    CLASS_  - implementation is inside a class definition
00119              (otherwise the class name is needed)
00120              Do NOT use in publicly exported header files, because
00121              the implementation may be included many times over.
00122              Instead, use the non-CLASS_ version.
00123    _<type> - For more complex (STR, IFACE) data types
00124              (otherwise the simple data type is needed)
00125    method  - name of the method, such as GetWidth or SetColor
00126    type    - simple data type if required
00127    member  - class member variable such as m_width or mColor
00128    class   - the class name, such as Window or MyObject
00129    postfix - Method part after Get/Set such as "Width" for "GetWidth"
00130    
00131    Example:
00132    class Window {
00133    public:
00134      NS_IMPL_CLASS_GETSET(Width, int, m_width);
00135      NS_IMPL_CLASS_GETTER_STR(GetColor, m_color);
00136      NS_IMETHOD SetColor(char *color);
00137      
00138    private:
00139      int m_width;     // read/write
00140      char *m_color;   // readonly
00141    };
00142 
00143    // defined outside of class
00144    NS_IMPL_SETTER_STR(Window::GetColor, m_color);
00145 
00146    Questions/Comments to alecf@netscape.com
00147 */
00148 
00149    
00150 /*
00151  * Getter/Setter implementation within a class definition
00152  */
00153 
00154 /* simple data types */
00155 #define NS_IMPL_CLASS_GETTER(_method, _type, _member) \
00156 NS_IMETHOD NS_METHOD_GETTER(_method, _type, _member)
00157 
00158 #define NS_IMPL_CLASS_SETTER(_method, _type, _member) \
00159 NS_IMETHOD NS_METHOD_SETTER(_method, _type, _member)
00160 
00161 #define NS_IMPL_CLASS_GETSET(_postfix, _type, _member) \
00162 NS_IMPL_CLASS_GETTER(Get##_postfix, _type, _member) \
00163 NS_IMPL_CLASS_SETTER(Set##_postfix, _type, _member)
00164 
00165 /* strings */
00166 #define NS_IMPL_CLASS_GETTER_STR(_method, _member) \
00167 NS_IMETHOD NS_METHOD_GETTER_STR(_method, _member)
00168 
00169 #define NS_IMPL_CLASS_SETTER_STR(_method, _member) \
00170 NS_IMETHOD NS_METHOD_SETTER_STR(_method, _member)
00171 
00172 #define NS_IMPL_CLASS_GETSET_STR(_postfix, _member) \
00173 NS_IMPL_CLASS_GETTER_STR(Get##_postfix, _member) \
00174 NS_IMPL_CLASS_SETTER_STR(Set##_postfix, _member)
00175 
00176 /* Getter/Setter implementation outside of a class definition */
00177 
00178 /* simple data types */
00179 #define NS_IMPL_GETTER(_method, _type, _member) \
00180 NS_IMETHODIMP NS_METHOD_GETTER(_method, _type, _member)
00181 
00182 #define NS_IMPL_SETTER(_method, _type, _member) \
00183 NS_IMETHODIMP NS_METHOD_SETTER(_method, _type, _member)
00184 
00185 #define NS_IMPL_GETSET(_class, _postfix, _type, _member) \
00186 NS_IMPL_GETTER(_class::Get##_postfix, _type, _member) \
00187 NS_IMPL_SETTER(_class::Set##_postfix, _type, _member)
00188 
00189 /* strings */
00190 #define NS_IMPL_GETTER_STR(_method, _member) \
00191 NS_IMETHODIMP NS_METHOD_GETTER_STR(_method, _member)
00192 
00193 #define NS_IMPL_SETTER_STR(_method, _member) \
00194 NS_IMETHODIMP NS_METHOD_SETTER_STR(_method, _member)
00195 
00196 #define NS_IMPL_GETSET_STR(_class, _postfix, _member) \
00197 NS_IMPL_GETTER_STR(_class::Get##_postfix, _member) \
00198 NS_IMPL_SETTER_STR(_class::Set##_postfix, _member)
00199 
00207 #define NS_ISTHREADSAFE_IID                                                   \
00208   { 0x88210890, 0x47a6, 0x11d2,                                               \
00209     {0xbe, 0xc3, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
00210 
00211 #define NS_LOCK_INSTANCE()                                                    \
00212   PR_CEnterMonitor((void*)this)
00213 #define NS_UNLOCK_INSTANCE()                                                  \
00214   PR_CExitMonitor((void*)this)
00215 
00226 #if defined(NS_DEBUG)
00227 #define NS_VERIFY_THREADSAFE_INTERFACE(_iface)                                \
00228  if (NULL != (_iface)) {                                                      \
00229    nsISupports* tmp;                                                          \
00230    static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID);               \
00231    NS_PRECONDITION((NS_OK == _iface->QueryInterface(kIsThreadsafeIID,         \
00232                                                     (void**)&tmp)),           \
00233                    "Interface is not threadsafe");                            \
00234  }
00235 #else
00236 #define NS_VERIFY_THREADSAFE_INTERFACE(_iface)
00237 #endif
00238 
00240 
00241 
00242 
00243 #endif