From c4821c8e6bf1f81c6ea31e11ebc0fc1666e9337b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 25 Feb 2021 10:27:59 -0500 Subject: Add exess from git@gitlab.com:drobilla/exess.git 4638b1f --- .../exess/bindings/cpp/include/exess/exess.hpp | 707 +++++++++++++++++++++ subprojects/exess/bindings/cpp/meson.build | 54 ++ subprojects/exess/bindings/cpp/test/.clang-tidy | 17 + subprojects/exess/bindings/cpp/test/meson.build | 8 + .../exess/bindings/cpp/test/test_exess_hpp.cpp | 221 +++++++ 5 files changed, 1007 insertions(+) create mode 100644 subprojects/exess/bindings/cpp/include/exess/exess.hpp create mode 100644 subprojects/exess/bindings/cpp/meson.build create mode 100644 subprojects/exess/bindings/cpp/test/.clang-tidy create mode 100644 subprojects/exess/bindings/cpp/test/meson.build create mode 100644 subprojects/exess/bindings/cpp/test/test_exess_hpp.cpp (limited to 'subprojects/exess/bindings') diff --git a/subprojects/exess/bindings/cpp/include/exess/exess.hpp b/subprojects/exess/bindings/cpp/include/exess/exess.hpp new file mode 100644 index 00000000..7aa6fc5b --- /dev/null +++ b/subprojects/exess/bindings/cpp/include/exess/exess.hpp @@ -0,0 +1,707 @@ +/* + Copyright 2021 David Robillard + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef EXESS_EXESS_HPP +#define EXESS_EXESS_HPP + +#include "exess/exess.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace exess { + +/** + @defgroup exesspp Exess C++ API + This is the C++ wrapper for the exess API. + @{ +*/ + +constexpr const char* EXESS_NONNULL const xsd_uri = + "http://www.w3.org/2001/XMLSchema#"; + +// FIXME: Reorganize +using Datatype = ExessDatatype; +using Result = ExessResult; + +using Duration = ExessDuration; +using DateTime = ExessDateTime; +using Time = ExessTime; +using Date = ExessDate; + +/** + @defgroup exesspp_status Status + @copydoc exess_status + @{ +*/ + +/// @copydoc ExessStatus +enum class Status { + success, ///< @copydoc EXESS_SUCCESS + expected_end, ///< @copydoc EXESS_EXPECTED_END + expected_boolean, ///< @copydoc EXESS_EXPECTED_BOOLEAN + expected_integer, ///< @copydoc EXESS_EXPECTED_INTEGER + expected_duration, ///< @copydoc EXESS_EXPECTED_DURATION + expected_sign, ///< @copydoc EXESS_EXPECTED_SIGN + expected_digit, ///< @copydoc EXESS_EXPECTED_DIGIT + expected_colon, ///< @copydoc EXESS_EXPECTED_COLON + expected_dash, ///< @copydoc EXESS_EXPECTED_DASH + expected_time_sep, ///< @copydoc EXESS_EXPECTED_TIME_SEP + expected_time_tag, ///< @copydoc EXESS_EXPECTED_TIME_TAG + expected_date_tag, ///< @copydoc EXESS_EXPECTED_DATE_TAG + expected_hex, ///< @copydoc EXESS_EXPECTED_HEX + expected_base64, ///< @copydoc EXESS_EXPECTED_BASE64 + bad_order, ///< @copydoc EXESS_BAD_ORDER + bad_value, ///< @copydoc EXESS_BAD_VALUE + out_of_range, ///< @copydoc EXESS_OUT_OF_RANGE + no_space, ///< @copydoc EXESS_NO_SPACE + would_reduce_precision, ///< @copydoc EXESS_WOULD_REDUCE_PRECISION + would_round, ///< @copydoc EXESS_WOULD_ROUND + would_truncate, ///< @copydoc EXESS_WOULD_TRUNCATE + unsupported, ///< @copydoc EXESS_UNSUPPORTED +}; + +/// @copydoc exess_strerror +inline const char* EXESS_NONNULL +strerror(const Status status) +{ + return exess_strerror(static_cast(status)); +} + +inline std::ostream& +operator<<(std::ostream& stream, const Status status) +{ + return stream << strerror(status); +} + +/** + @} + + Datatype Traits +*/ + +namespace detail { + +template +struct DatatypeTraits {}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_BOOLEAN; + static constexpr auto read_function = exess_read_boolean; + static constexpr auto write_function = exess_write_boolean; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_DOUBLE; + static constexpr auto read_function = exess_read_double; + static constexpr auto write_function = exess_write_double; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_FLOAT; + static constexpr auto read_function = exess_read_float; + static constexpr auto write_function = exess_write_float; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_LONG; + static constexpr auto read_function = exess_read_long; + static constexpr auto write_function = exess_write_long; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_INT; + static constexpr auto read_function = exess_read_int; + static constexpr auto write_function = exess_write_int; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_SHORT; + static constexpr auto read_function = exess_read_short; + static constexpr auto write_function = exess_write_short; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_BYTE; + static constexpr auto read_function = exess_read_byte; + static constexpr auto write_function = exess_write_byte; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_ULONG; + static constexpr auto read_function = exess_read_ulong; + static constexpr auto write_function = exess_write_ulong; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_UINT; + static constexpr auto read_function = exess_read_uint; + static constexpr auto write_function = exess_write_uint; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_USHORT; + static constexpr auto read_function = exess_read_ushort; + static constexpr auto write_function = exess_write_ushort; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_UBYTE; + static constexpr auto read_function = exess_read_ubyte; + static constexpr auto write_function = exess_write_ubyte; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_DURATION; + static constexpr auto read_function = exess_read_duration; + static constexpr auto write_function = exess_write_duration; +}; + +template<> +struct DatatypeTraits { + static constexpr auto datatype = EXESS_DATETIME; + static constexpr auto read_function = exess_read_datetime; + static constexpr auto write_function = exess_write_datetime; +}; + +template<> +struct DatatypeTraits