common.h 2.3 KB
Newer Older
1 2
/**
 * \file lite-c/src/common.h
3
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
4
 *
5
 * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
6
 *
7 8 9
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
 */

#ifndef LITE_C_COMMON_H_
#define LITE_C_COMMON_H_

#include "../src/misc.h"
#include "lite-c/network_c.h"
#include "lite-c/tensor_c.h"
#include "lite/network.h"

#include <exception>
#include <stdexcept>

//! convert c Layout to lite::Layout
lite::Layout convert_to_layout(const LiteLayout& layout);

//! convert lite::Layout to C Layout
LiteLayout convert_to_clayout(const lite::Layout& layout);

//! convert c config to lite::config
lite::Config convert_to_lite_config(const LiteConfig c_config);

//! convert C NetworkIO io to lite::NetworkIO
lite::NetworkIO convert_to_lite_io(const LiteNetworkIO c_network_io);

/*!
 * \brief handle exception
 * \param e the exception
 * \return the return value of the error
 */
int LiteHandleException(const std::exception& e);
#if LITE_ENABLE_EXCEPTION
/*! \brief  macro to guard a function */
#define LITE_CAPI_BEGIN() try {
/*! \brief every function starts with LITE_CAPI_BEGIN();
 * ends with LITE_CAPI_END or LITE_CAPI_END_WITH_STMS
 */
#define LITE_CAPI_END()                       \
    }                                         \
    catch (std::exception & _except_) {       \
        return LiteHandleException(_except_); \
    }                                         \
    return 0;
#else
/*! \brief  macro to guard a function */
#define LITE_CAPI_BEGIN()  {
/*! \brief every function starts with LITE_CAPI_BEGIN();
 * ends with LITE_CAPI_END or LITE_CAPI_END_WITH_STMS
 */
#define LITE_CAPI_END()                       \
    }                                         \
    return 0;
#endif
/*!
 * \brief catch the exception with stms
 */
#define LITE_CAPI_END_WITH_STMS(_stms)        \
    }                                         \
    catch (std::exception & _except_) {       \
        _stms;                                \
        return LiteHandleException(_except_); \
    }                                         \
    return 0;

#endif
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}