summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2015-08-02 15:50:38 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2015-08-03 22:30:20 +0100
commit38375045bfc78f6338649ad70b99e7f8a64b3494 (patch)
tree631465c2dd11418c7cb63c3614cedcb012af1ed9 /include
parent8449bb0c102a0ff85e3dc8d4319fac531ea5374f (diff)
downloadlibnslayout-38375045bfc78f6338649ad70b99e7f8a64b3494.tar.gz
libnslayout-38375045bfc78f6338649ad70b99e7f8a64b3494.tar.bz2
Add error header.
Diffstat (limited to 'include')
-rw-r--r--include/libnslayout/error.h109
-rw-r--r--include/libnslayout/nslayout.h7
2 files changed, 111 insertions, 5 deletions
diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h
new file mode 100644
index 0000000..0e2321f
--- /dev/null
+++ b/include/libnslayout/error.h
@@ -0,0 +1,109 @@
+/*
+ * This file is part of LibNSLayout
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+/** \file include/libnslayout/error.h
+ * Layout object handling
+ */
+
+#ifndef nslayout_error_h_
+#define nslayout_error_h_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * Libnslayout return codes
+ *
+ * NSLAYOUT_OK indicates no error.
+ */
+typedef enum nslayout_error {
+ /** No error code */
+ NSLAYOUT_OK = 0,
+
+ /** Error provenance */
+ NSLAYOUT_NSLAYOUT = (1 << 0),
+ NSLAYOUT_LIBDOM = (1 << 1),
+ NSLAYOUT_LIBCSS = (1 << 2),
+
+ /** LibNSLayout errors */
+ NSLAYOUT_NO_MEM = (1 << 8) + NSLAYOUT_NSLAYOUT,
+} nslayout_error;
+
+
+/**
+ * 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
diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h
index 2610e42..b486cba 100644
--- a/include/libnslayout/nslayout.h
+++ b/include/libnslayout/nslayout.h
@@ -20,6 +20,8 @@ extern "C"
#include <libcss/libcss.h>
#include <dom/dom.h>
+#include <libnslayout/error.h>
+
/** An opaque client-owned replaced element */
typedef void nslayout_replaced;
@@ -86,11 +88,6 @@ typedef struct nslayout_request {
} response;
} nslayout_request;
-/** Libnslayout return codes */
-typedef enum nslayout_error {
- NSLAYOUT_OK,
- NSLAYOUT_NO_MEM
-} nslayout_error;
/**
* Initialise LibNSLayout