epoc32/include/stdapis/stlport/stl/_new.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3 
     4 * Redistribution and use in source and binary forms, with or without 
     5 * modification, are permitted provided that the following conditions are met:
     6 
     7 * Redistributions of source code must retain the above copyright notice, this 
     8 * list of conditions and the following disclaimer.
     9 * Redistributions in binary form must reproduce the above copyright notice, 
    10 * this list of conditions and the following disclaimer in the documentation 
    11 * and/or other materials provided with the distribution.
    12 * Neither the name of Nokia Corporation nor the names of its contributors 
    13 * may be used to endorse or promote products derived from this software 
    14 * without specific prior written permission.
    15 
    16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    19 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
    20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
    23 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    26 *
    27 * Description:
    28 *
    29 */
    30 
    31 #ifndef _STLP_NEW_H_HEADER
    32 # define _STLP_NEW_H_HEADER
    33 
    34 # ifdef _STLP_NO_BAD_ALLOC
    35 # ifndef _STLP_NEW_DONT_THROW
    36 #   define _STLP_NEW_DONT_THROW 1
    37 # endif /* _STLP_NEW_DONT_THROW */
    38 
    39 #  include <exception>
    40 
    41 
    42 _STLP_BEGIN_NAMESPACE
    43 
    44 #if defined(__SYMBIAN32__) && defined( __WINSCW__)
    45 // already defined symcpp.h included from rvct2_2.h
    46 struct nothrow_t {};
    47 #endif
    48 
    49 
    50 # ifdef _STLP_OWN_IOSTREAMS
    51 #ifdef __ARMCC__
    52 extern _STLP_DECLSPEC const nothrow_t nothrow;
    53 #else
    54 extern IMPORT_C const nothrow_t& GetNoThrowObj();
    55 #define nothrow GetNoThrowObj()
    56 #endif
    57 # else
    58 #  define nothrow nothrow_t()
    59 # endif
    60 #ifndef _STLP_EXCEPTION_BASE
    61 #  define _STLP_EXCEPTION_BASE exception
    62 #endif
    63 
    64 class bad_alloc : public _STLP_EXCEPTION_BASE { 
    65 public:
    66   bad_alloc () _STLP_NOTHROW_INHERENTLY { }
    67   bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
    68   bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
    69   ~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
    70   const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
    71 };
    72 
    73 _STLP_END_NAMESPACE
    74 
    75 #endif /* _STLP_NO_BAD_ALLOC */
    76 
    77 #if defined (_STLP_WINCE)
    78 _STLP_BEGIN_NAMESPACE
    79 
    80 inline void* _STLP_CALL __stl_new(size_t __n) {
    81   return ::malloc(__n);
    82 }
    83 
    84 inline void _STLP_CALL __stl_delete(void* __p) {
    85   free(__p);
    86 }
    87 
    88 #ifndef __cdecl
    89 # define __cdecl
    90 #endif
    91 
    92 _STLP_END_NAMESPACE
    93 
    94 #else /* _STLP_WINCE */
    95 
    96 #include <new>
    97 
    98 # ifndef _STLP_NO_BAD_ALLOC
    99 #  ifdef _STLP_USE_OWN_NAMESPACE
   100 
   101     _STLP_BEGIN_NAMESPACE
   102     using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
   103     using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
   104     using _STLP_VENDOR_EXCEPT_STD::nothrow;
   105 
   106 #  if defined (_STLP_GLOBAL_NEW_HANDLER)
   107     using ::new_handler;
   108     using ::set_new_handler;
   109 #  else
   110     using _STLP_VENDOR_EXCEPT_STD::new_handler;
   111     using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
   112 #  endif
   113     
   114     _STLP_END_NAMESPACE
   115 
   116 #  endif /* _STLP_OWN_NAMESPACE */
   117 
   118 # endif /* _STLP_NO_BAD_ALLOC */
   119 
   120 # if defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW) || defined (__SYMBIAN32__) \
   121                     || defined (__WINS__) && ! defined (_STLP_CHECK_NULL_ALLOC)
   122 #  define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){_STLP_THROW(bad_alloc());}return __y
   123 # if defined (__SYMBIAN32__)
   124 //# define _STLP_NEW operator new
   125 #define _STLP_NEW  ::malloc
   126 #endif
   127 /*
   128 # elif defined (__SYMBIAN32__) || defined (__WINS__)
   129 #  ifndef _STLP_USE_TRAP_LEAVE
   130 #   define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){abort();}return __y
   131 #  else
   132 #   define _STLP_NEW(x) :: operator new (x, ELeave) 
   133 #   define _STLP_CHECK_NULL_ALLOC(__x) return __x
   134 #  endif
   135 */
   136 # else
   137 #  define _STLP_CHECK_NULL_ALLOC(__x) return __x
   138 # endif
   139 
   140 #ifndef _STLP_NEW
   141 # define _STLP_NEW ::operator new
   142 #endif
   143 # define _STLP_PLACEMENT_NEW ::new
   144 
   145 _STLP_BEGIN_NAMESPACE
   146 
   147 #ifdef __SYMBIAN32__
   148 
   149 typedef void(*new_handler)();
   150 
   151 _STLP_DECLSPEC new_handler set_new_handler(new_handler pnew) throw();
   152 
   153 #endif
   154 
   155 #if (( defined(__IBMCPP__)|| defined(__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined(__DEBUG_ALLOC__) )
   156 inline void*  _STLP_CALL __stl_new(size_t __n) {  _STLP_CHECK_NULL_ALLOC(_STLP_NEW(__n, __FILE__, __LINE__)); }
   157 inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
   158 #else
   159 inline void*  _STLP_CALL __stl_new(size_t __n)   { return ::operator new(__n); }
   160 inline void   _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
   161 #endif
   162 _STLP_END_NAMESPACE
   163 
   164 
   165 # endif /* _STLP_WINCE */
   166 
   167 #if defined(__SYMBIAN32__) && !defined(__GCCE__)
   168 _STLP_DECLSPEC void *operator new(unsigned int aSize);
   169 
   170 _STLP_DECLSPEC void *operator new[](unsigned int aSize);
   171 #endif
   172 
   173 _STLP_DECLSPEC void operator delete(void* aPtr) throw();
   174 
   175 _STLP_DECLSPEC void operator delete[](void* aPtr) throw();
   176 
   177 _STLP_DECLSPEC void* operator new(unsigned int aSize, const std::nothrow_t& /*aNoThrow*/) throw();
   178 
   179 _STLP_DECLSPEC void* operator new[](unsigned int aSize, const std::nothrow_t& aNoThrow) throw();
   180 
   181 _STLP_DECLSPEC void operator delete(void* aPtr, const std::nothrow_t& /*aNoThrow*/) throw();
   182 
   183 _STLP_DECLSPEC void operator delete[](void* aPtr, const std::nothrow_t& /*aNoThrow*/) throw();
   184 
   185 
   186 // placement delete
   187 #ifndef __PLACEMENT_VEC_NEW_INLINE
   188 #define __PLACEMENT_VEC_NEW_INLINE
   189 inline void* operator new[](unsigned int /*aSize*/, void* aBase) throw()
   190 	{return aBase;}
   191 inline void operator delete[](void* /*aPtr*/, void* /*aBase*/) throw()
   192     {
   193     
   194     }
   195 #endif
   196 
   197 #ifndef __PLACEMENT_NEW_INLINE
   198 #define __PLACEMENT_NEW_INLINE
   199 inline void* operator new(unsigned int /*aSize*/, void* aBase) throw()
   200 	{return aBase;}
   201 
   202 // Global placement operator delete
   203 inline void operator delete(void* /*aPtr*/, void* /*aBase*/) throw()
   204 	{}
   205 #endif //__PLACEMENT_NEW_INLINE
   206 
   207 
   208 #endif /* _STLP_NEW_H_HEADER */