1999-05-18 21:43:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-05-18 21:43:13 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-05-18 21:43:13 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-05-18 21:43:13 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-05-18 21:43:13 +00:00
|
|
|
*/
|
|
|
|
#ifndef nscore_h___
|
|
|
|
#define nscore_h___
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define NS_WIN32 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__unix)
|
|
|
|
#define NS_UNIX 1
|
|
|
|
#endif
|
|
|
|
|
2000-02-29 15:50:48 +00:00
|
|
|
#if defined(XP_OS2)
|
|
|
|
#define NS_OS2 1
|
|
|
|
#endif
|
|
|
|
|
1999-05-18 21:43:13 +00:00
|
|
|
#include "prtypes.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#endif
|
|
|
|
|
1999-06-04 02:00:19 +00:00
|
|
|
/* The preferred symbol for null. */
|
1999-05-18 21:43:13 +00:00
|
|
|
#define nsnull 0
|
|
|
|
|
|
|
|
/* Define brackets for protecting C code from C++ */
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define NS_BEGIN_EXTERN_C extern "C" {
|
|
|
|
#define NS_END_EXTERN_C }
|
|
|
|
#else
|
|
|
|
#define NS_BEGIN_EXTERN_C
|
|
|
|
#define NS_END_EXTERN_C
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
/* Import/export defines */
|
|
|
|
|
|
|
|
#ifdef NS_WIN32
|
|
|
|
#define NS_IMPORT _declspec(dllimport)
|
|
|
|
#define NS_IMPORT_(type) type _declspec(dllimport) __stdcall
|
|
|
|
#define NS_EXPORT _declspec(dllexport)
|
1999-06-04 02:00:19 +00:00
|
|
|
/* XXX NS_EXPORT_ defined in nsCOm.h (xpcom) differs in where the __declspec
|
|
|
|
is placed. It needs to be done this way to make the 4.x compiler happy... */
|
1999-05-18 21:43:13 +00:00
|
|
|
#undef NS_EXPORT_
|
|
|
|
#define NS_EXPORT_(type) type _declspec(dllexport) __stdcall
|
|
|
|
#elif defined(XP_MAC)
|
|
|
|
|
|
|
|
#define NS_IMPORT
|
|
|
|
#define NS_IMPORT_(type) type
|
|
|
|
|
1999-06-04 02:00:19 +00:00
|
|
|
/* XXX NS_EXPORT_ defined in nsCom.h actually does an export. Here it's just sugar. */
|
1999-05-18 21:43:13 +00:00
|
|
|
#undef NS_EXPORT
|
|
|
|
#undef NS_EXPORT_
|
|
|
|
|
|
|
|
#define NS_EXPORT __declspec(export)
|
|
|
|
#define NS_EXPORT_(type) __declspec(export) type
|
|
|
|
|
|
|
|
#else
|
|
|
|
/* XXX do something useful? */
|
|
|
|
#define NS_IMPORT
|
|
|
|
#define NS_IMPORT_(type) type
|
|
|
|
#define NS_EXPORT
|
|
|
|
#define NS_EXPORT_(type) type
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_BASE
|
|
|
|
#define NS_BASE NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_BASE NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_NET
|
|
|
|
#define NS_NET NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_NET NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_DOM
|
|
|
|
#define NS_DOM NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_DOM NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_WIDGET
|
|
|
|
#define NS_WIDGET NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_WIDGET NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_VIEW
|
|
|
|
#define NS_VIEW NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_VIEW NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_GFXNONXP
|
|
|
|
#define NS_GFXNONXP NS_EXPORT
|
|
|
|
#define NS_GFXNONXP_(type) NS_EXPORT_(type)
|
|
|
|
#else
|
|
|
|
#define NS_GFXNONXP NS_IMPORT
|
|
|
|
#define NS_GFXNONXP_(type) NS_IMPORT_(type)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_GFX
|
|
|
|
#define NS_GFX NS_EXPORT
|
|
|
|
#define NS_GFX_(type) NS_EXPORT_(type)
|
|
|
|
#else
|
|
|
|
#define NS_GFX NS_IMPORT
|
|
|
|
#define NS_GFX_(type) NS_IMPORT_(type)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_PLUGIN
|
|
|
|
#define NS_PLUGIN NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_PLUGIN NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _IMPL_NS_APPSHELL
|
|
|
|
#define NS_APPSHELL NS_EXPORT
|
|
|
|
#else
|
|
|
|
#define NS_APPSHELL NS_IMPORT
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
1999-06-04 02:00:19 +00:00
|
|
|
/* Casting macros for hiding C++ features from older compilers */
|
1999-05-18 21:43:13 +00:00
|
|
|
|
2000-01-13 05:48:47 +00:00
|
|
|
/*
|
|
|
|
All our compiler support template specialization, but not all support the
|
|
|
|
|template <>| notation. The compiler that don't understand this notation
|
|
|
|
just omit it for specialization.
|
|
|
|
|
|
|
|
Need to add an autoconf test for this.
|
|
|
|
*/
|
|
|
|
|
2000-01-13 23:06:47 +00:00
|
|
|
/* under Metrowerks (Mac), we don't have autoconf yet */
|
2000-01-13 05:48:47 +00:00
|
|
|
#ifdef __MWERKS__
|
|
|
|
#define HAVE_CPP_SPECIALIZATION
|
2000-04-26 00:55:37 +00:00
|
|
|
#define HAVE_CPP_PARTIAL_SPECIALIZATION
|
2000-01-13 05:48:47 +00:00
|
|
|
#define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
2000-03-17 23:08:29 +00:00
|
|
|
|
2000-06-05 00:46:37 +00:00
|
|
|
#define HAVE_CPP_ACCESS_CHANGING_USING
|
|
|
|
#define HAVE_CPP_AMBIGUITY_RESOLVING_USING
|
2000-03-17 23:08:29 +00:00
|
|
|
#define HAVE_CPP_EXPLICIT
|
2000-06-18 05:00:31 +00:00
|
|
|
#define HAVE_CPP_TYPENAME
|
2000-03-17 23:08:29 +00:00
|
|
|
#define HAVE_CPP_BOOL
|
2000-03-28 07:01:37 +00:00
|
|
|
#define HAVE_CPP_NAMESPACE_STD
|
2000-04-04 06:38:12 +00:00
|
|
|
#define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
|
2000-06-21 01:31:09 +00:00
|
|
|
#define HAVE_CPP_2BYTE_WCHAR_T
|
2000-03-28 07:01:37 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-13 23:06:47 +00:00
|
|
|
/* under VC++ (Windows), we don't have autoconf yet */
|
2000-01-13 05:48:47 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER>=1100)
|
2000-01-13 23:06:47 +00:00
|
|
|
/* VC++ 5.0 and greater implement template specialization, 4.2 is unknown */
|
2000-01-13 05:48:47 +00:00
|
|
|
#define HAVE_CPP_SPECIALIZATION
|
|
|
|
#define HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
2000-03-17 23:08:29 +00:00
|
|
|
|
|
|
|
#define HAVE_CPP_EXPLICIT
|
2000-06-18 05:00:31 +00:00
|
|
|
#define HAVE_CPP_TYPENAME
|
2000-06-05 00:46:37 +00:00
|
|
|
#define HAVE_CPP_ACCESS_CHANGING_USING
|
2000-03-17 23:08:29 +00:00
|
|
|
|
|
|
|
#if (_MSC_VER<1100)
|
2000-09-13 12:22:17 +00:00
|
|
|
/* before 5.0, VC++ couldn't handle explicit */
|
2000-03-17 23:08:29 +00:00
|
|
|
#undef HAVE_CPP_EXPLICIT
|
|
|
|
#elif (_MSC_VER==1100)
|
2000-09-13 12:22:17 +00:00
|
|
|
/* VC++5.0 has an internal compiler error (sometimes) without this */
|
2000-06-05 00:46:37 +00:00
|
|
|
#undef HAVE_CPP_ACCESS_CHANGING_USING
|
2000-03-17 23:08:29 +00:00
|
|
|
#endif
|
2000-03-24 00:38:52 +00:00
|
|
|
|
2000-03-28 07:44:26 +00:00
|
|
|
#define HAVE_CPP_NAMESPACE_STD
|
2000-04-04 06:38:12 +00:00
|
|
|
#define HAVE_CPP_UNAMBIGUOUS_STD_NOTEQUAL
|
2000-09-03 02:24:58 +00:00
|
|
|
#define HAVE_CPP_2BYTE_WCHAR_T
|
2000-06-13 00:05:18 +00:00
|
|
|
#endif
|
|
|
|
|
2000-06-18 21:27:27 +00:00
|
|
|
/* until we get an autoconf test for this, we'll assume it's on (since we're using it already) */
|
2000-06-18 05:00:31 +00:00
|
|
|
#define HAVE_CPP_TYPENAME
|
|
|
|
|
|
|
|
/* waiting to find out if OS/2 VisualAge participates in autoconf */
|
2000-08-19 08:01:28 +00:00
|
|
|
#if defined(XP_OS2_VACPP) || defined(AIX) || (defined(IRIX) && !defined(__GNUC__))
|
2000-06-18 05:00:31 +00:00
|
|
|
#undef HAVE_CPP_TYPENAME
|
|
|
|
#endif
|
|
|
|
|
2000-06-13 00:05:18 +00:00
|
|
|
|
|
|
|
#ifndef __PRUNICHAR__
|
|
|
|
#define __PRUNICHAR__
|
|
|
|
#ifdef HAVE_CPP_2BYTE_WCHAR_T
|
|
|
|
typedef wchar_t PRUnichar;
|
|
|
|
#else
|
|
|
|
typedef PRUint16 PRUnichar;
|
|
|
|
#endif
|
2000-01-13 05:48:47 +00:00
|
|
|
#endif
|
|
|
|
|
2000-06-10 09:58:15 +00:00
|
|
|
/*
|
|
|
|
If the compiler doesn't support |explicit|, we'll just make it go away, trusting
|
|
|
|
that the builds under compilers that do have it will keep us on the straight and narrow.
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_CPP_EXPLICIT
|
|
|
|
#define explicit
|
|
|
|
#endif
|
|
|
|
|
2000-06-18 05:00:31 +00:00
|
|
|
#ifndef HAVE_CPP_TYPENAME
|
|
|
|
#define typename
|
|
|
|
#endif
|
|
|
|
|
2000-01-13 05:48:47 +00:00
|
|
|
#ifdef HAVE_CPP_MODERN_SPECIALIZE_TEMPLATE_SYNTAX
|
|
|
|
#define NS_SPECIALIZE_TEMPLATE template <>
|
|
|
|
#else
|
|
|
|
#define NS_SPECIALIZE_TEMPLATE
|
|
|
|
#endif
|
|
|
|
|
1999-07-27 21:22:56 +00:00
|
|
|
/* unix and beos now determine this automatically */
|
2000-02-29 15:50:48 +00:00
|
|
|
#if ! defined XP_UNIX && ! defined XP_BEOS && !defined(XP_OS2)
|
1999-06-04 02:00:19 +00:00
|
|
|
#define HAVE_CPP_NEW_CASTS /* we'll be optimistic. */
|
1999-05-18 21:43:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_CPP_NEW_CASTS)
|
2000-03-17 23:08:29 +00:00
|
|
|
#define NS_STATIC_CAST(__type, __ptr) static_cast< __type >(__ptr)
|
|
|
|
#define NS_CONST_CAST(__type, __ptr) const_cast< __type >(__ptr)
|
2000-01-13 05:48:47 +00:00
|
|
|
|
2000-03-17 23:08:29 +00:00
|
|
|
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) reinterpret_cast< __type >(__ptr)
|
|
|
|
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) reinterpret_cast< __type >(__obj)
|
|
|
|
#define NS_REINTERPRET_CAST(__type, __expr) reinterpret_cast< __type >(__expr)
|
2000-01-13 05:48:47 +00:00
|
|
|
|
1999-05-18 21:43:13 +00:00
|
|
|
#else
|
|
|
|
#define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
|
|
|
|
#define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
|
1999-12-08 01:41:28 +00:00
|
|
|
|
2000-01-13 05:48:47 +00:00
|
|
|
#define NS_REINTERPRET_POINTER_CAST(__type, __ptr) ((__type)((void*)(__ptr)))
|
|
|
|
#define NS_REINTERPRET_NONPOINTER_CAST(__type, __obj) ((__type)(__obj))
|
|
|
|
|
1999-12-08 01:41:28 +00:00
|
|
|
/* Note: the following is only appropriate for pointers. */
|
2000-01-13 05:48:47 +00:00
|
|
|
#define NS_REINTERPRET_CAST(__type, __expr) NS_REINTERPRET_POINTER_CAST(__type, __expr)
|
1999-12-08 01:41:28 +00:00
|
|
|
/*
|
2000-01-13 05:48:47 +00:00
|
|
|
Why cast to a |void*| first? Well, when old-style casting from
|
|
|
|
a pointer to a base to a pointer to a derived class, the cast will be
|
|
|
|
ambiguous if the source pointer type appears multiple times in the
|
|
|
|
destination, e.g.,
|
|
|
|
|
|
|
|
class Base {};
|
|
|
|
class Derived : public Base, public Base {};
|
|
|
|
|
|
|
|
void foo( Base* b )
|
|
|
|
{
|
2000-09-02 04:17:11 +00:00
|
|
|
((Derived*)b)->some_derived_member ... // Error: Ambiguous, expand from which |Base|?
|
2000-01-13 05:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
an old-style cast (like |static_cast|) will change the pointer, but
|
|
|
|
here, doesn't know how. The cast to |void*| prevents it from thinking
|
|
|
|
it needs to expand the original pointer.
|
1999-12-08 01:41:28 +00:00
|
|
|
|
|
|
|
The cost is, |NS_REINTERPRET_CAST| is no longer appropriate for non-pointer
|
|
|
|
conversions. Also, mis-applying |NS_REINTERPRET_CAST| to cast |this| to something
|
|
|
|
will still expand the pointer to the outer object in standards complying compilers.
|
|
|
|
*/
|
1999-05-18 21:43:13 +00:00
|
|
|
|
2000-06-13 00:05:18 +00:00
|
|
|
/*
|
|
|
|
No sense in making an NS_DYNAMIC_CAST() macro: you can't duplicate
|
|
|
|
the semantics. So if you want to dynamic_cast, then just use it
|
|
|
|
"straight", no macro.
|
|
|
|
*/
|
|
|
|
#endif
|
1999-05-18 21:43:13 +00:00
|
|
|
|
|
|
|
#endif /* nscore_h___ */
|