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