epoc32/include/stdapis/stlport/stl/_new.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #ifndef _STLP_NEW_H_HEADER
    20 # define _STLP_NEW_H_HEADER
    21 
    22 # ifdef _STLP_NO_BAD_ALLOC
    23 # ifndef _STLP_NEW_DONT_THROW
    24 #   define _STLP_NEW_DONT_THROW 1
    25 # endif /* _STLP_NEW_DONT_THROW */
    26 
    27 #  include <exception>
    28 
    29 
    30 _STLP_BEGIN_NAMESPACE
    31 
    32 #if defined(__SYMBIAN32__) && ( defined( __WINSCW__) || defined(__GCCXML__)) 
    33 
    34 // already defined symcpp.h included from rvct2_2.h
    35 struct nothrow_t {};
    36 #endif
    37 
    38 
    39 
    40 # ifdef _STLP_OWN_IOSTREAMS
    41 #ifdef __ARMCC__
    42 extern _STLP_DECLSPEC const nothrow_t nothrow;
    43 #else
    44 extern IMPORT_C const nothrow_t& GetNoThrowObj();
    45 #define nothrow GetNoThrowObj()
    46 #endif
    47 # else
    48 #  define nothrow nothrow_t()
    49 # endif
    50 #ifndef _STLP_EXCEPTION_BASE
    51 #  define _STLP_EXCEPTION_BASE exception
    52 #endif
    53 
    54 class bad_alloc : public _STLP_EXCEPTION_BASE { 
    55 public:
    56   bad_alloc () _STLP_NOTHROW_INHERENTLY { }
    57   bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
    58   bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
    59   ~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
    60   const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
    61 };
    62 
    63 _STLP_END_NAMESPACE
    64 
    65 #endif /* _STLP_NO_BAD_ALLOC */
    66 
    67 #if defined (_STLP_WINCE)
    68 _STLP_BEGIN_NAMESPACE
    69 
    70 inline void* _STLP_CALL __stl_new(size_t __n) {
    71   return ::malloc(__n);
    72 }
    73 
    74 inline void _STLP_CALL __stl_delete(void* __p) {
    75   free(__p);
    76 }
    77 
    78 #ifndef __cdecl
    79 # define __cdecl
    80 #endif
    81 
    82 _STLP_END_NAMESPACE
    83 
    84 #else /* _STLP_WINCE */
    85 
    86 #include <new>
    87 
    88 # ifndef _STLP_NO_BAD_ALLOC
    89 #  ifdef _STLP_USE_OWN_NAMESPACE
    90 
    91     _STLP_BEGIN_NAMESPACE
    92     using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
    93     using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
    94     using _STLP_VENDOR_EXCEPT_STD::nothrow;
    95 
    96 #  if defined (_STLP_GLOBAL_NEW_HANDLER)
    97     using ::new_handler;
    98     using ::set_new_handler;
    99 #  else
   100     using _STLP_VENDOR_EXCEPT_STD::new_handler;
   101     using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
   102 #  endif
   103     
   104     _STLP_END_NAMESPACE
   105 
   106 #  endif /* _STLP_OWN_NAMESPACE */
   107 
   108 # endif /* _STLP_NO_BAD_ALLOC */
   109 
   110 # if defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW) || defined (__SYMBIAN32__) \
   111                     || defined (__WINS__) && ! defined (_STLP_CHECK_NULL_ALLOC)
   112 #  define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){_STLP_THROW(bad_alloc());}return __y
   113 # if defined (__SYMBIAN32__)
   114 //# define _STLP_NEW operator new
   115 #define _STLP_NEW  ::malloc
   116 #endif
   117 /*
   118 # elif defined (__SYMBIAN32__) || defined (__WINS__)
   119 #  ifndef _STLP_USE_TRAP_LEAVE
   120 #   define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){abort();}return __y
   121 #  else
   122 #   define _STLP_NEW(x) :: operator new (x, ELeave) 
   123 #   define _STLP_CHECK_NULL_ALLOC(__x) return __x
   124 #  endif
   125 */
   126 # else
   127 #  define _STLP_CHECK_NULL_ALLOC(__x) return __x
   128 # endif
   129 
   130 #ifndef _STLP_NEW
   131 # define _STLP_NEW ::operator new
   132 #endif
   133 # define _STLP_PLACEMENT_NEW ::new
   134 
   135 _STLP_BEGIN_NAMESPACE
   136 
   137 #ifdef __SYMBIAN32__
   138 
   139 typedef void(*new_handler)();
   140 
   141 _STLP_DECLSPEC new_handler set_new_handler(new_handler pnew)  __NO_THROW;
   142 
   143 #endif
   144 
   145 #if (( defined(__IBMCPP__)|| defined(__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined(__DEBUG_ALLOC__) )
   146 inline void*  _STLP_CALL __stl_new(size_t __n) {  _STLP_CHECK_NULL_ALLOC(_STLP_NEW(__n, __FILE__, __LINE__)); }
   147 inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
   148 #else
   149 inline void*  _STLP_CALL __stl_new(size_t __n)   { return ::operator new(__n); }
   150 inline void   _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
   151 #endif
   152 _STLP_END_NAMESPACE
   153 
   154 
   155 # endif /* _STLP_WINCE */
   156 
   157 #if defined(__SYMBIAN32__) && !defined(__GCCE__)
   158 _STLP_DECLSPEC void *operator new(unsigned int aSize);
   159 
   160 _STLP_DECLSPEC void *operator new[](unsigned int aSize);
   161 #endif
   162 
   163 _STLP_DECLSPEC void operator delete(void* aPtr) __NO_THROW;
   164 
   165 _STLP_DECLSPEC void operator delete[](void* aPtr) __NO_THROW;
   166 
   167 _STLP_DECLSPEC void* operator new(unsigned int aSize, const std::nothrow_t& /*aNoThrow*/)  __NO_THROW;
   168 
   169 _STLP_DECLSPEC void* operator new[](unsigned int aSize, const std::nothrow_t& aNoThrow)  __NO_THROW;
   170 
   171 _STLP_DECLSPEC void operator delete(void* aPtr, const std::nothrow_t& /*aNoThrow*/)  __NO_THROW;
   172 
   173 _STLP_DECLSPEC void operator delete[](void* aPtr, const std::nothrow_t& /*aNoThrow*/)  __NO_THROW;
   174 
   175 
   176 // placement delete
   177 #ifndef __PLACEMENT_VEC_NEW_INLINE
   178 #define __PLACEMENT_VEC_NEW_INLINE
   179 inline void* operator new[](unsigned int /*aSize*/, void* aBase)  __NO_THROW
   180 	{return aBase;}
   181 inline void operator delete[](void* /*aPtr*/, void* /*aBase*/)  __NO_THROW
   182     {
   183     
   184     }
   185 #endif
   186 
   187 #ifndef __PLACEMENT_NEW_INLINE
   188 #define __PLACEMENT_NEW_INLINE
   189 inline void* operator new(unsigned int /*aSize*/, void* aBase)  __NO_THROW
   190 	{return aBase;}
   191 
   192 // Global placement operator delete
   193 inline void operator delete(void* /*aPtr*/, void* /*aBase*/)  __NO_THROW
   194 	{}
   195 #endif //__PLACEMENT_NEW_INLINE
   196 
   197 
   198 #endif /* _STLP_NEW_H_HEADER */