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