genericopenlibs/cppstdlib/inc/stdcpp_support.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2008-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 * Name        : stdcpp_support.h
       
    16 * Part of     : standard c++ library.
       
    17 * 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 #ifndef _STDCPP_SUPPORT_H_
       
    24 #define _STDCPP_SUPPORT_H_
       
    25 
       
    26 #include <exception>
       
    27 //This is required for the TRAP macro
       
    28 #include <e32cmn.h>
       
    29 // This is required for the Symbian error numbers
       
    30 #include <e32err.h>
       
    31 
       
    32 /* A utility funtion that takes a SymbianC++ error number and throws a corresponding 
       
    33 C++ exception. This mapping is done based on what is mentioned in Chapter 19.1 of 
       
    34 the C++ specification and Symbian's e32err.h.
       
    35 */
       
    36 IMPORT_C void TranslateSymErrorToCppException(TInt);
       
    37 
       
    38 
       
    39 /* A utility function that takes an instance of std::exception and returns a
       
    40 corresponding SymbianC++ error number. This mapping is done based on what is
       
    41 mentioned in Chapter 19.1 of the C++ specification and Symbian's e32err.h.
       
    42 */
       
    43 IMPORT_C TInt TranslateCppExceptionToSymError(const std::exception&);
       
    44 
       
    45 
       
    46 /* Executes the set of C++ statements _s under a trap harness and throws a suitable  
       
    47 C++ exception that matches the Symbian error code.
       
    48 
       
    49 Use this macro as a C++ statement to translate a User::Leave
       
    50 
       
    51 _s can consist of multiple C++ statements; in theory, _s can consist
       
    52 of any legal C++ code but in practice, such statements consist of Symbian C++
       
    53 function calls that may leave, e.g. FooL() or an assignment of some value to 
       
    54 the result of a function call, e.g. functionValue=GetFooL().
       
    55 */
       
    56 #define TRANSLATE_SYM_CPP_LEAVES(_s)			\
       
    57 	{											\
       
    58 		TInt err;								\
       
    59 		TRAP(err, _s);							\
       
    60 		if(err) TranslateSymErrorToCppException(err);	\
       
    61 	}
       
    62 
       
    63 class Symbian_error : public std::exception
       
    64 {
       
    65 public:
       
    66 	/* A Symbian specific error can be encapsulated within this object*/
       
    67 	Symbian_error(TInt e):error_code(e) {}
       
    68 
       
    69 	inline TInt error() { return error_code; }
       
    70 private:
       
    71 	TInt error_code;
       
    72 };
       
    73 
       
    74 
       
    75 #endif //STDCPP_SUPPORT_H
       
    76