williamr@4
|
1 |
/*
|
williamr@4
|
2 |
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@4
|
3 |
* All rights reserved.
|
williamr@4
|
4 |
* This component and the accompanying materials are made available
|
williamr@4
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
williamr@4
|
6 |
* which accompanies this distribution, and is available
|
williamr@4
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Initial Contributors:
|
williamr@4
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* Contributors:
|
williamr@4
|
13 |
*
|
williamr@4
|
14 |
* Description:
|
williamr@4
|
15 |
* Name : stdcpp_support.h
|
williamr@4
|
16 |
* Part of : standard c++ library.
|
williamr@4
|
17 |
*
|
williamr@4
|
18 |
*
|
williamr@4
|
19 |
*/
|
williamr@4
|
20 |
|
williamr@4
|
21 |
|
williamr@4
|
22 |
|
williamr@4
|
23 |
#ifndef _STDCPP_SUPPORT_H_
|
williamr@4
|
24 |
#define _STDCPP_SUPPORT_H_
|
williamr@4
|
25 |
|
williamr@4
|
26 |
#include <exception>
|
williamr@4
|
27 |
//This is required for the TRAP macro
|
williamr@4
|
28 |
#include <e32cmn.h>
|
williamr@4
|
29 |
// This is required for the Symbian error numbers
|
williamr@4
|
30 |
#include <e32err.h>
|
williamr@4
|
31 |
|
williamr@4
|
32 |
/* A utility funtion that takes a SymbianC++ error number and throws a corresponding
|
williamr@4
|
33 |
C++ exception. This mapping is done based on what is mentioned in Chapter 19.1 of
|
williamr@4
|
34 |
the C++ specification and Symbian's e32err.h.
|
williamr@4
|
35 |
*/
|
williamr@4
|
36 |
IMPORT_C void TranslateSymErrorToCppException(TInt);
|
williamr@4
|
37 |
|
williamr@4
|
38 |
|
williamr@4
|
39 |
/* A utility function that takes an instance of std::exception and returns a
|
williamr@4
|
40 |
corresponding SymbianC++ error number. This mapping is done based on what is
|
williamr@4
|
41 |
mentioned in Chapter 19.1 of the C++ specification and Symbian's e32err.h.
|
williamr@4
|
42 |
*/
|
williamr@4
|
43 |
IMPORT_C TInt TranslateCppExceptionToSymError(const std::exception&);
|
williamr@4
|
44 |
|
williamr@4
|
45 |
|
williamr@4
|
46 |
/* Executes the set of C++ statements _s under a trap harness and throws a suitable
|
williamr@4
|
47 |
C++ exception that matches the Symbian error code.
|
williamr@4
|
48 |
|
williamr@4
|
49 |
Use this macro as a C++ statement to translate a User::Leave
|
williamr@4
|
50 |
|
williamr@4
|
51 |
_s can consist of multiple C++ statements; in theory, _s can consist
|
williamr@4
|
52 |
of any legal C++ code but in practice, such statements consist of Symbian C++
|
williamr@4
|
53 |
function calls that may leave, e.g. FooL() or an assignment of some value to
|
williamr@4
|
54 |
the result of a function call, e.g. functionValue=GetFooL().
|
williamr@4
|
55 |
*/
|
williamr@4
|
56 |
#define TRANSLATE_SYM_CPP_LEAVES(_s) \
|
williamr@4
|
57 |
{ \
|
williamr@4
|
58 |
TInt err; \
|
williamr@4
|
59 |
TRAP(err, _s); \
|
williamr@4
|
60 |
if(err) TranslateSymErrorToCppException(err); \
|
williamr@4
|
61 |
}
|
williamr@4
|
62 |
|
williamr@4
|
63 |
class Symbian_error : public std::exception
|
williamr@4
|
64 |
{
|
williamr@4
|
65 |
public:
|
williamr@4
|
66 |
/* A Symbian specific error can be encapsulated within this object*/
|
williamr@4
|
67 |
Symbian_error(TInt e):error_code(e) {}
|
williamr@4
|
68 |
|
williamr@4
|
69 |
inline TInt error() { return error_code; }
|
williamr@4
|
70 |
private:
|
williamr@4
|
71 |
TInt error_code;
|
williamr@4
|
72 |
};
|
williamr@4
|
73 |
|
williamr@4
|
74 |
|
williamr@4
|
75 |
#endif //STDCPP_SUPPORT_H
|
williamr@4
|
76 |
|