/* * This source code is released into the public domain. */ module; #include #include #include #include #include export module nihil.ucl:type; import nihil.error; namespace nihil::ucl { // Our strongly-typed version of ::ucl_type. export enum struct object_type { object = UCL_OBJECT, array = UCL_ARRAY, integer = UCL_INT, real = UCL_FLOAT, string = UCL_STRING, boolean = UCL_BOOLEAN, time = UCL_TIME, userdata = UCL_USERDATA, null = UCL_NULL, }; // Get the name of a type. export auto str(object_type type) -> std::string_view; // Concept of a UCL data type. export template concept datatype = requires(T o) { { o.get_ucl_object() } -> std::convertible_to<::ucl_object_t const *>; { o.type() } -> std::same_as; { T::ucl_type } -> std::convertible_to; }; // Exception thrown when a type assertion fails. export struct type_mismatch : error { type_mismatch(object_type expected_type, object_type actual_type); // The type we expected. auto expected_type(this type_mismatch const &self) -> object_type; // The type we got. auto actual_type(this type_mismatch const &self) -> object_type; private: object_type m_expected_type; object_type m_actual_type; }; } // namespace nihil::ucl