/* * This file is part of LibNSLayout * Licensed under the ISC License, http://opensource.org/licenses/ISC * Copyright 2015 Michael Drake */ /** \file include/libnslayout/error.h * Layout object handling */ #ifndef nslayout_error_h_ #define nslayout_error_h_ #ifdef __cplusplus extern "C" { #endif /** * Number of bits in an `nslayout_error` that indicate the source of the error. */ #define NSLAYOUT_ERROR_PROV 8 /** * Libnslayout return codes * * NSLAYOUT_OK indicates no error. */ typedef enum nslayout_error { /** No error code */ NSLAYOUT_OK = 0, /** Error provenance (bits 0..7) */ NSLAYOUT_NSLAYOUT = (1 << 0), NSLAYOUT_LIBDOM = (1 << 1), NSLAYOUT_LIBCSS = (1 << 2), /** LibNSLayout errors (bits 8..31) */ NSLAYOUT_NO_MEM = (1 << NSLAYOUT_ERROR_PROV) | NSLAYOUT_NSLAYOUT, } nslayout_error; /** * Get error provenance. * * \param[in] err Error code to test * \return error provenance */ static inline nslayout_error nslayout_error_provenance(nslayout_error err) { return err & ((1 << NSLAYOUT_ERROR_PROV) - 1); } /** * Check if error is from libnslayout * * \param[in] err Error code to test * \return true iff error is from libnslayout */ static inline bool nslayout_error_is_layout(nslayout_error err) { return err & NSLAYOUT_NSLAYOUT; } /** * Check if error is from libdom * * \param[in] err Error code to test * \return true iff error is from libdom */ static inline bool nslayout_error_is_libdom(nslayout_error err) { return err & NSLAYOUT_LIBDOM; } /** * Check if error is from libcss * * \param[in] err Error code to test * \return true iff error is from libcss */ static inline bool nslayout_error_is_libcss(nslayout_error err) { return err & NSLAYOUT_LIBCSS; } /** * Turn libnslayout return code into libnslayout error * * \param[in] err Error code to convert * \return libnslayout error */ static inline nslayout_error nslayout_error_to_layout(nslayout_error err) { return err; } /** * Turn libnslayout return code into libdom error * * \param[in] err Error code to convert * \return dom exception */ static inline dom_exception nslayout_error_to_libdom(nslayout_error err) { return err >> 8; } /** * Turn libnslayout return code into libcss error * * \param[in] err Error code to convert * \return libcss error */ static inline css_error nslayout_error_to_libcss(nslayout_error err) { return err >> 8; } #ifdef __cplusplus } #endif #endif