sl@0: /* sl@0: * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Name : stdcpp_support.h sl@0: * Part of : standard c++ library. sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #ifndef _STDCPP_SUPPORT_H_ sl@0: #define _STDCPP_SUPPORT_H_ sl@0: sl@0: #include sl@0: //This is required for the TRAP macro sl@0: #include sl@0: // This is required for the Symbian error numbers sl@0: #include sl@0: sl@0: /* A utility funtion that takes a SymbianC++ error number and throws a corresponding sl@0: C++ exception. This mapping is done based on what is mentioned in Chapter 19.1 of sl@0: the C++ specification and Symbian's e32err.h. sl@0: */ sl@0: IMPORT_C void TranslateSymErrorToCppException(TInt); sl@0: sl@0: sl@0: /* A utility function that takes an instance of std::exception and returns a sl@0: corresponding SymbianC++ error number. This mapping is done based on what is sl@0: mentioned in Chapter 19.1 of the C++ specification and Symbian's e32err.h. sl@0: */ sl@0: IMPORT_C TInt TranslateCppExceptionToSymError(const std::exception&); sl@0: sl@0: sl@0: /* Executes the set of C++ statements _s under a trap harness and throws a suitable sl@0: C++ exception that matches the Symbian error code. sl@0: sl@0: Use this macro as a C++ statement to translate a User::Leave sl@0: sl@0: _s can consist of multiple C++ statements; in theory, _s can consist sl@0: of any legal C++ code but in practice, such statements consist of Symbian C++ sl@0: function calls that may leave, e.g. FooL() or an assignment of some value to sl@0: the result of a function call, e.g. functionValue=GetFooL(). sl@0: */ sl@0: #define TRANSLATE_SYM_CPP_LEAVES(_s) \ sl@0: { \ sl@0: TInt err; \ sl@0: TRAP(err, _s); \ sl@0: if(err) TranslateSymErrorToCppException(err); \ sl@0: } sl@0: sl@0: class Symbian_error : public std::exception sl@0: { sl@0: public: sl@0: /* A Symbian specific error can be encapsulated within this object*/ sl@0: Symbian_error(TInt e):error_code(e) {} sl@0: sl@0: inline TInt error() { return error_code; } sl@0: private: sl@0: TInt error_code; sl@0: }; sl@0: sl@0: sl@0: #endif //STDCPP_SUPPORT_H sl@0: