Back to index

lightning-sunbird  0.9+nobinonly
xptinfo.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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* XPTI_PUBLIC_API and XPTI_GetInterfaceInfoManager declarations. */
00039 
00040 #ifndef xptiinfo_h___
00041 #define xptiinfo_h___
00042 
00043 #include "prtypes.h"
00044 #include "xpt_struct.h"
00045 
00046 /*
00047  * The linkage of XPTI API functions differs depending on whether the file is
00048  * used within the XPTI library or not.  Any source file within the XPTI
00049  * library should define EXPORT_XPTI_API whereas any client of the library
00050  * should not.
00051  */
00052 #ifdef EXPORT_XPTI_API
00053 #define XPTI_PUBLIC_API(t)    PR_IMPLEMENT(t)
00054 #define XPTI_PUBLIC_DATA(t)   PR_IMPLEMENT_DATA(t)
00055 #ifdef _WIN32
00056 #    define XPTI_EXPORT           __declspec(dllexport)
00057 #else
00058 #    define XPTI_EXPORT
00059 #endif
00060 #else
00061 #ifdef _WIN32
00062 #    define XPTI_PUBLIC_API(t)    __declspec(dllimport) t
00063 #    define XPTI_PUBLIC_DATA(t)   __declspec(dllimport) t
00064 #    define XPTI_EXPORT           __declspec(dllimport)
00065 #else
00066 #    define XPTI_PUBLIC_API(t)    PR_IMPLEMENT(t)
00067 #    define XPTI_PUBLIC_DATA(t)   t
00068 #    define XPTI_EXPORT
00069 #endif
00070 #endif
00071 #define XPTI_FRIEND_API(t)    XPTI_PUBLIC_API(t)
00072 #define XPTI_FRIEND_DATA(t)   XPTI_PUBLIC_DATA(t)
00073 
00074 class nsIInterfaceInfoManager;
00075 PR_BEGIN_EXTERN_C
00076 // Even if this is a service, it is cool to provide a direct accessor
00077 XPTI_PUBLIC_API(nsIInterfaceInfoManager*)
00078 XPTI_GetInterfaceInfoManager();
00079 
00080 // Even if this is a service, it is cool to provide a direct accessor
00081 XPTI_PUBLIC_API(void)
00082 XPTI_FreeInterfaceInfoManager();
00083 PR_END_EXTERN_C
00084 
00085 
00086 
00087 // Flyweight wrapper classes for xpt_struct.h structs. 
00088 // Everything here is dependent upon - and sensitive to changes in -
00089 // xpcom/typelib/xpt/public/xpt_struct.h!
00090 
00091 class nsXPTType : public XPTTypeDescriptorPrefix
00092 {
00093 // NO DATA - this a flyweight wrapper
00094 public:
00095     nsXPTType()
00096         {}    // random contents
00097     nsXPTType(const XPTTypeDescriptorPrefix& prefix)
00098         {*(XPTTypeDescriptorPrefix*)this = prefix;}
00099 
00100     nsXPTType(const uint8& prefix)
00101         {*(uint8*)this = prefix;}
00102 
00103     nsXPTType& operator=(uint8 val)
00104         {flags = val; return *this;}
00105 
00106     nsXPTType& operator=(const nsXPTType& other)
00107         {flags = other.flags; return *this;}
00108 
00109     operator uint8() const
00110         {return flags;}
00111 
00112     PRBool IsPointer() const
00113         {return 0 != (XPT_TDP_IS_POINTER(flags));}
00114 
00115     PRBool IsUniquePointer() const
00116         {return 0 != (XPT_TDP_IS_UNIQUE_POINTER(flags));}
00117 
00118     PRBool IsReference() const
00119         {return 0 != (XPT_TDP_IS_REFERENCE(flags));}
00120 
00121     PRBool IsArithmetic() const     // terminology from Harbison/Steele
00122         {return flags <= T_WCHAR;}
00123 
00124     PRBool IsInterfacePointer() const
00125         {  switch (TagPart()) {
00126              default:
00127                return PR_FALSE;
00128              case T_INTERFACE:
00129              case T_INTERFACE_IS:
00130                return PR_TRUE;
00131            }
00132         }
00133 
00134     PRBool IsArray() const
00135         {return (PRBool) TagPart() == T_ARRAY;}
00136 
00137     // 'Dependent' means that params of this type are dependent upon other 
00138     // params. e.g. an T_INTERFACE_IS is dependent upon some other param at 
00139     // runtime to say what the interface type of this param really is.
00140     PRBool IsDependent() const
00141         {  switch (TagPart()) {
00142              default:
00143                return PR_FALSE;
00144              case T_INTERFACE_IS:
00145              case TD_ARRAY:
00146              case T_PSTRING_SIZE_IS:
00147              case T_PWSTRING_SIZE_IS:
00148                return PR_TRUE;
00149            }
00150         }
00151 
00152     uint8 TagPart() const
00153         {return (uint8) (flags & XPT_TDP_TAGMASK);}
00154 
00155     enum
00156     {
00157         T_I8                = TD_INT8             ,
00158         T_I16               = TD_INT16            ,
00159         T_I32               = TD_INT32            ,
00160         T_I64               = TD_INT64            ,
00161         T_U8                = TD_UINT8            ,
00162         T_U16               = TD_UINT16           ,
00163         T_U32               = TD_UINT32           ,
00164         T_U64               = TD_UINT64           ,
00165         T_FLOAT             = TD_FLOAT            ,
00166         T_DOUBLE            = TD_DOUBLE           ,
00167         T_BOOL              = TD_BOOL             ,
00168         T_CHAR              = TD_CHAR             ,
00169         T_WCHAR             = TD_WCHAR            ,
00170         T_VOID              = TD_VOID             ,
00171         T_IID               = TD_PNSIID           ,
00172         T_DOMSTRING         = TD_DOMSTRING        ,
00173         T_CHAR_STR          = TD_PSTRING          ,
00174         T_WCHAR_STR         = TD_PWSTRING         ,
00175         T_INTERFACE         = TD_INTERFACE_TYPE   ,
00176         T_INTERFACE_IS      = TD_INTERFACE_IS_TYPE,
00177         T_ARRAY             = TD_ARRAY            ,
00178         T_PSTRING_SIZE_IS   = TD_PSTRING_SIZE_IS  ,
00179         T_PWSTRING_SIZE_IS  = TD_PWSTRING_SIZE_IS ,
00180         T_UTF8STRING        = TD_UTF8STRING       ,
00181         T_CSTRING           = TD_CSTRING          ,
00182         T_ASTRING           = TD_ASTRING
00183     };
00184 // NO DATA - this a flyweight wrapper
00185 };
00186 
00187 class nsXPTParamInfo : public XPTParamDescriptor
00188 {
00189 // NO DATA - this a flyweight wrapper
00190 public:
00191     nsXPTParamInfo(const XPTParamDescriptor& desc)
00192         {*(XPTParamDescriptor*)this = desc;}
00193 
00194 
00195     PRBool IsIn()  const    {return 0 != (XPT_PD_IS_IN(flags));}
00196     PRBool IsOut() const    {return 0 != (XPT_PD_IS_OUT(flags));}
00197     PRBool IsRetval() const {return 0 != (XPT_PD_IS_RETVAL(flags));}
00198     PRBool IsShared() const {return 0 != (XPT_PD_IS_SHARED(flags));}
00199     PRBool IsDipper() const {return 0 != (XPT_PD_IS_DIPPER(flags));}
00200     const nsXPTType GetType() const {return type.prefix;}
00201 
00202     // NOTE: other activities on types are done via methods on nsIInterfaceInfo
00203 
00204 private:
00205     nsXPTParamInfo();   // no implementation
00206 // NO DATA - this a flyweight wrapper
00207 };
00208 
00209 class nsXPTMethodInfo : public XPTMethodDescriptor
00210 {
00211 // NO DATA - this a flyweight wrapper
00212 public:
00213     nsXPTMethodInfo(const XPTMethodDescriptor& desc)
00214         {*(XPTMethodDescriptor*)this = desc;}
00215 
00216     PRBool IsGetter()      const {return 0 != (XPT_MD_IS_GETTER(flags) );}
00217     PRBool IsSetter()      const {return 0 != (XPT_MD_IS_SETTER(flags) );}
00218     PRBool IsNotXPCOM()    const {return 0 != (XPT_MD_IS_NOTXPCOM(flags));}
00219     PRBool IsConstructor() const {return 0 != (XPT_MD_IS_CTOR(flags)   );}
00220     PRBool IsHidden()      const {return 0 != (XPT_MD_IS_HIDDEN(flags) );}
00221     const char* GetName()  const {return name;}
00222     uint8 GetParamCount()  const {return num_args;}
00223     /* idx was index before I got _sick_ of the warnings on Unix, sorry jband */
00224     const nsXPTParamInfo GetParam(uint8 idx) const
00225         {
00226             NS_PRECONDITION(idx < GetParamCount(),"bad arg");
00227             return params[idx];
00228         }
00229     const nsXPTParamInfo GetResult() const
00230         {return *result;}
00231 private:
00232     nsXPTMethodInfo();  // no implementation
00233 // NO DATA - this a flyweight wrapper
00234 };
00235 
00236 
00237 // forward declaration
00238 struct nsXPTCMiniVariant;
00239 
00240 class nsXPTConstant : public XPTConstDescriptor
00241 {
00242 // NO DATA - this a flyweight wrapper
00243 public:
00244     nsXPTConstant(const XPTConstDescriptor& desc)
00245         {*(XPTConstDescriptor*)this = desc;}
00246 
00247     const char* GetName() const
00248         {return name;}
00249 
00250     const nsXPTType GetType() const
00251         {return type.prefix;}
00252 
00253     // XXX this is ugly. But sometimes you gotta do what you gotta do.
00254     // A reinterpret_cast won't do the trick here. And this plain C cast
00255     // works correctly and is safe enough.
00256     // See http://bugzilla.mozilla.org/show_bug.cgi?id=49641
00257     const nsXPTCMiniVariant* GetValue() const
00258         {return (nsXPTCMiniVariant*) &value;}
00259 private:
00260     nsXPTConstant();    // no implementation
00261 // NO DATA - this a flyweight wrapper
00262 };
00263 
00264 #endif /* xptiinfo_h___ */