Back to index

lightning-sunbird  0.9+nobinonly
iixprivate.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Mike McCabe <mccabe@netscape.com>
00024  *   John Bandhauer <jband@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /* Library-private header for Interface Info extras system. */
00041 
00042 #ifndef iixprivate_h___
00043 #define iixprivate_h___
00044 
00045 #include "nsCOMPtr.h"
00046 #include "nsVoidArray.h"
00047 #include "nsSupportsArray.h"
00048 #include "nsString.h"
00049 #include "nsCRT.h"
00050 #include "nsReadableUtils.h"
00051 #include "nsWeakReference.h"
00052 #include "nsIGenericFactory.h"
00053 #include "nsVariant.h"
00054 
00055 #include "nsIInterfaceInfo.h"
00056 #include "nsIInterfaceInfoManager.h"
00057 #include "xpt_struct.h"
00058 #include "xptinfo.h"
00059 #include "xptcall.h"
00060 
00061 #include "nsIGenericInterfaceInfoSet.h"
00062 #include "nsIScriptableInterfaceInfo.h"
00063 
00064 /***************************************************************************/
00065 
00066 class nsGenericInterfaceInfoSet : public nsIGenericInterfaceInfoSet,
00067                                   public nsSupportsWeakReference
00068 {
00069 public:
00070     NS_DECL_ISUPPORTS
00071     NS_DECL_NSIINTERFACEINFOMANAGER
00072     NS_DECL_NSIGENERICINTERFACEINFOSET
00073 
00074     nsGenericInterfaceInfoSet();
00075     virtual ~nsGenericInterfaceInfoSet();
00076 
00077     XPTArena* GetArena()
00078     {
00079         return mArena;
00080     }
00081 
00082     const XPTTypeDescriptor* GetAdditionalTypeAt(PRUint16 aIndex)
00083     {
00084         NS_ASSERTION(aIndex < (PRUint16) mAdditionalTypes.Count(), "bad index");
00085         return (const XPTTypeDescriptor*) mAdditionalTypes.ElementAt(aIndex);
00086     }
00087 
00088     nsIInterfaceInfo* InfoAtNoAddRef(PRUint16 aIndex)
00089     {
00090         NS_ASSERTION(aIndex < (PRUint16) mInterfaces.Count(), "bad index");
00091         return (nsIInterfaceInfo*) ClearOwnedFlag(mInterfaces.ElementAt(aIndex));
00092     }
00093 
00094 private:
00095     nsresult IndexOfIID(const nsIID & aIID, PRUint16 *_retval);
00096     nsresult IndexOfName(const char* aName, PRUint16 *_retval);
00097 
00098     void* SetOwnedFlag(void* p)
00099     {
00100         NS_ASSERTION(sizeof(void *) == sizeof(long),
00101                      "The size of a pointer != size of long!");
00102         return (void*) ((long)p | 1);
00103     }
00104     void* ClearOwnedFlag(void* p)
00105     {
00106         return (void*) ((long)p & ~(long)1);
00107     }
00108     PRBool CheckOwnedFlag(void* p)
00109     {
00110         return (PRBool) ((long)p & (long)1);
00111     }
00112 
00113 private:
00114     nsVoidArray mInterfaces;
00115     nsVoidArray mAdditionalTypes;
00116     XPTArena* mArena;
00117 };
00118 
00119 /***************************************************************************/
00120 
00121 class nsGenericInterfaceInfo : public nsIGenericInterfaceInfo
00122 {
00123 public:
00124     NS_DECL_ISUPPORTS
00125     NS_DECL_NSIINTERFACEINFO
00126     NS_DECL_NSIGENERICINTERFACEINFO
00127 
00128     nsGenericInterfaceInfo(nsGenericInterfaceInfoSet* aSet,
00129                            const char *aName, 
00130                            const nsIID & aIID, 
00131                            nsIInterfaceInfo* aParent,
00132                            PRUint8 aFlags); 
00133     virtual ~nsGenericInterfaceInfo()
00134     {
00135     }
00136 
00137 private:
00138     nsGenericInterfaceInfo(); // not implemented
00139 
00140     const XPTTypeDescriptor* GetPossiblyNestedType(const XPTParamDescriptor* param)
00141     {
00142         const XPTTypeDescriptor* td = &param->type;
00143         while(XPT_TDP_TAG(td->prefix) == TD_ARRAY)
00144             td = mSet->GetAdditionalTypeAt(td->type.additional_type);
00145         return td;
00146     }
00147 
00148     const XPTTypeDescriptor* GetTypeInArray(const XPTParamDescriptor* param,
00149                                             PRUint16 dimension)
00150     {
00151         const XPTTypeDescriptor* td = &param->type;
00152         for(PRUint16 i = 0; i < dimension; i++)
00153         {
00154             NS_ASSERTION(XPT_TDP_TAG(td->prefix) == TD_ARRAY, "bad dimension");
00155             td = mSet->GetAdditionalTypeAt(td->type.additional_type);
00156         }
00157         return td;
00158     }
00159 
00160 private:
00161     char* mName;
00162     nsIID mIID;
00163     nsVoidArray mMethods;
00164     nsVoidArray mConstants;
00165     nsGenericInterfaceInfoSet* mSet;
00166     nsIInterfaceInfo* mParent; // weak reference (it must be held in set table)
00167     PRUint16 mMethodBaseIndex;
00168     PRUint16 mConstantBaseIndex;
00169     PRUint8 mFlags;
00170 };
00171 
00172 /***************************************************************************/
00173 
00174 class nsScriptableInterfaceInfo : public nsIScriptableInterfaceInfo
00175 {
00176 public:
00177     NS_DECL_ISUPPORTS
00178     NS_DECL_NSISCRIPTABLEINTERFACEINFO
00179 
00180     static nsresult Create(nsIInterfaceInfo* aInfo,
00181                            nsIScriptableInterfaceInfo** aResult);
00182 
00183     nsScriptableInterfaceInfo();
00184     nsScriptableInterfaceInfo(nsIInterfaceInfo* aInfo);
00185     virtual ~nsScriptableInterfaceInfo();
00186 
00187 private:
00188     nsCOMPtr<nsIInterfaceInfo> mInfo;
00189 };
00190 
00191 /***************************************************************************/
00192 
00193 #endif /* iixprivate_h___ */