Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use NativeCall;
- constant XQC_VERSION_NUMBER = 1;
- ## Enumerations
- enum XQC_Error is export (
- XQC_NO_ERROR => 0,
- XQC_END_OF_SEQUENCE => 1,
- XQC_NO_CURRENT_ITEM => 2,
- XQC_PARSE_ERROR => 3,
- XQC_INVALID_ARGUMENT => 4,
- XQC_NOT_NODE => 5,
- XQC_INTERNAL_ERROR => 6,
- XQC_NOT_IMPLEMENTED => 7,
- XQC_UNRECOGNIZED_ENCODING => 8,
- XQC_STATIC_ERROR => 9,
- XQC_TYPE_ERROR => 10,
- XQC_DYNAMIC_ERROR => 11,
- XQC_SERIALIZATION_ERROR => 12
- );
- enum XQC_ItemType is export (
- XQC_EMPTY_TYPE => 0,
- XQC_DOCUMENT_TYPE => 1,
- XQC_ELEMENT_TYPE => 2,
- XQC_ATTRIBUTE_TYPE => 3,
- XQC_TEXT_TYPE => 4,
- XQC_PROCESSING_INSTRUCTION_TYPE => 5,
- XQC_COMMENT_TYPE => 6,
- XQC_NAMESPACE_TYPE => 7,
- XQC_ANY_SIMPLE_TYPE => 8,
- XQC_ANY_URI_TYPE => 9,
- XQC_BASE_64_BINARY_TYPE => 10,
- XQC_BOOLEAN_TYPE => 11,
- XQC_DATE_TYPE => 12,
- XQC_DATE_TIME_TYPE => 13,
- XQC_DAY_TIME_DURATION_TYPE => 14,
- XQC_DECIMAL_TYPE => 15,
- XQC_DOUBLE_TYPE => 16,
- XQC_DURATION_TYPE => 17,
- XQC_FLOAT_TYPE => 18,
- XQC_G_DAY_TYPE => 19,
- XQC_G_MONTH_TYPE => 20,
- XQC_G_MONTH_DAY_TYPE => 21,
- XQC_G_YEAR_TYPE => 22,
- XQC_G_YEAR_MONTH_TYPE => 23,
- XQC_HEX_BINARY_TYPE => 24,
- XQC_NOTATION_TYPE => 25,
- XQC_QNAME_TYPE => 26,
- XQC_STRING_TYPE => 27,
- XQC_TIME_TYPE => 28,
- XQC_UNTYPED_ATOMIC_TYPE => 29,
- XQC_YEAR_MONTH_DURATION_TYPE => 30
- );
- enum XQC_XPath1Mode is export (
- XQC_XPATH2_0 => 0,
- XQC_XPATH1_0 => 1
- );
- enum XQC_OrderingMode is export (
- XQC_ORDERED => 0,
- XQC_UNORDERED => 1
- );
- enum XQC_OrderEmptyMode is export (
- XQC_EMPTY_GREATEST => 0,
- XQC_EMPTY_LEAST => 1
- );
- enum XQC_InheritMode is export (
- XQC_INHERIT_NS => 0,
- XQC_NO_INHERIT_NS => 1
- );
- enum XQC_PreserveMode is export (
- XQC_PRESERVE_NS => 0,
- XQC_NO_PRESERVE_NS => 1
- );
- enum XQC_BoundarySpaceMode is export (
- XQC_PRESERVE_SPACE => 0,
- XQC_STRIP_SPACE => 1
- );
- enum XQC_ConstructionMode is export (
- XQC_PRESERVE_CONS => 0,
- XQC_STRIP_CONS => 1
- );
- ## Structures
- # == /usr/include/xqc.h ==
- class XQC_InputStream_s is repr<CStruct> {
- has Str $.encoding; # const char* encoding
- has Pointer $.user_data; # void* user_data
- has Pointer $!read; # F:unsigned int ( Typedef<XQC_InputStream>->|XQC_InputStream_s|*, void*, unsigned int)* read
- has Pointer $!free; # F:void ( Typedef<XQC_InputStream>->|XQC_InputStream_s|*)* free
- method read(str $b, Int $v where * > 0) {
- my &func_sig = nativecast(:(XQC_InputStream_s, Pointer, uint32), $!read);
- return func_sig(self, $b, $v);
- }
- submethod DESTROY {
- $!free();
- }
- }
- class XQC_ErrorHandler_s is repr<CStruct> is export {
- has Pointer $.user_data; # void* user_data
- has Pointer $.error; # F:void ( Typedef<XQC_ErrorHandler>->|XQC_ErrorHandler_s|*, XQC_Error, const char*, const char*, const char*, Typedef<XQC_Sequence>->|XQC_Sequence_s|*)* error
- }
- class XQC_StaticContext_s is repr<CStruct> is export {
- has Pointer $.create_child_context; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, Typedef<XQC_StaticContext>->|XQC_StaticContext_s|**)* create_child_context
- has Pointer $.declare_ns; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char*, const char*)* declare_ns
- has Pointer $.get_ns_by_prefix; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char*, const char**)* get_ns_by_prefix
- has Pointer $.set_default_element_and_type_ns; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char*)* set_default_element_and_type_ns
- has Pointer $.get_default_element_and_type_ns; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char**)* get_default_element_and_type_ns
- has Pointer $.set_default_function_ns; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char*)* set_default_function_ns
- has Pointer $.get_default_function_ns; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char**)* get_default_function_ns
- has Pointer $.set_xpath_compatib_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_XPath1Mode)* set_xpath_compatib_mode
- has Pointer $.get_xpath_compatib_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_XPath1Mode*)* get_xpath_compatib_mode
- has Pointer $.set_construction_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_ConstructionMode)* set_construction_mode
- has Pointer $.get_construction_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_ConstructionMode*)* get_construction_mode
- has Pointer $.set_ordering_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_OrderingMode)* set_ordering_mode
- has Pointer $.get_ordering_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_OrderingMode*)* get_ordering_mode
- has Pointer $.set_default_order_empty_sequences; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_OrderEmptyMode)* set_default_order_empty_sequences
- has Pointer $.get_default_order_empty_sequences; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_OrderEmptyMode*)* get_default_order_empty_sequences
- has Pointer $.set_boundary_space_policy; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_BoundarySpaceMode)* set_boundary_space_policy
- has Pointer $.get_boundary_space_policy; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_BoundarySpaceMode*)* get_boundary_space_policy
- has Pointer $.set_copy_ns_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_PreserveMode, XQC_InheritMode)* set_copy_ns_mode
- has Pointer $.get_copy_ns_mode; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, XQC_PreserveMode*, XQC_InheritMode*)* get_copy_ns_mode
- has Pointer $.set_base_uri; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char*)* set_base_uri
- has Pointer $.get_base_uri; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char**)* get_base_uri
- has Pointer $.set_error_handler; # F:XQC_Error ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, Typedef<XQC_ErrorHandler>->|XQC_ErrorHandler_s|*)* set_error_handler
- has Pointer $.get_error_handler; # F:XQC_Error ( const Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, Typedef<XQC_ErrorHandler>->|XQC_ErrorHandler_s|**)* get_error_handler
- has Pointer $.get_interface; # F:void* ( const Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, const char*)* get_interface
- has Pointer $.free; # F:void ( Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*)* free
- }
- class XQC_Expression_s is repr<CStruct> is export {
- has Pointer $.create_context; # F:XQC_Error ( const Typedef<XQC_Expression>->|XQC_Expression_s|*, Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|**)* create_context
- has Pointer $.execute; # F:XQC_Error ( const Typedef<XQC_Expression>->|XQC_Expression_s|*, const Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* execute
- has Pointer $.get_interface; # F:void* ( const Typedef<XQC_Expression>->|XQC_Expression_s|*, const char*)* get_interface
- has Pointer $!free; # F:void ( Typedef<XQC_Expression>->|XQC_Expression_s|*)* free
- submethod DESTROY {
- $!free();
- }
- }
- class XQC_Sequence_s is repr<CStruct> is export {
- has Pointer $!next; # F:XQC_Error ( Typedef<XQC_Sequence>->|XQC_Sequence_s|*)* next
- has Pointer $!item_type; # F:XQC_Error ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, XQC_ItemType*)* item_type
- has Pointer $!type_name; # F:XQC_Error ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, const char**, const char**)* type_name
- has Pointer $!string_value; # F:XQC_Error ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, const char**)* string_value
- has Pointer $!integer_value; # F:XQC_Error ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, int*)* integer_value
- has Pointer $!double_value; # F:XQC_Error ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, double*)* double_value
- has Pointer $!node_name; # F:XQC_Error ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, const char**, const char**)* node_name
- has Pointer $!get_interface; # F:void* ( const Typedef<XQC_Sequence>->|XQC_Sequence_s|*, const char*)* get_interface
- has Pointer $!free; # F:void ( Typedef<XQC_Sequence>->|XQC_Sequence_s|*)* free
- method next {
- my &func_sig = nativecast(:(XQC_Sequence_s --> XQC_Error), $!next);
- my $err = &func_sig(self);
- testErr($err);
- }
- method item_type {
- my &func_sig = nativecast(:(XQC_Sequence_s, XQC_ItemType --> XQC_Error), $!item_type);
- my XQC_ItemType $it;
- my $err = &func_sig(self, $it);
- testErr($err);
- return $it;
- }
- method string_value {
- my &func_sig = nativecast(:(XQC_Sequence_s, Pointer --> XQC_Error), $!string_value);
- my str $sval = str.new();
- my $err = &func_sig(self, $sval);
- testErr($err);
- return $sval;
- }
- method integer_value {
- my &func_sig = nativecast(:(XQC_Sequence_s, Pointer --> XQC_Error), $!integer_value);
- my Int $ival = Int.new();
- my $err = &func_sig(self, $ival);
- testErr($err);
- return $ival;
- }
- method double_value {
- my &func_sig = nativecast(:(XQC_Sequence_s, Pointer --> XQC_Error), $!double_value);
- my Num $nval = Num.new();
- my $err = &func_sig(self, $nval);
- testErr($err);
- return $nval;
- }
- method node_name {
- my &func_sig = nativecast(:(XQC_Sequence_s, Pointer, Pointer --> XQC_Error), $!node_name);
- my str $uri = str.new();
- my str $name = str.new();
- my $err = &func_sig(self, $uri, $name);
- testErr($err);
- return ($uri, $name);
- }
- submethod DESTROY {
- $!free();
- }
- }
- class XQC_Implementation_s is repr<CStruct> is export {
- has Pointer $!create_context; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, Typedef<XQC_StaticContext>->|XQC_StaticContext_s|**)* create_context
- has Pointer $!prepare; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, const char*, const Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, Typedef<XQC_Expression>->|XQC_Expression_s|**)* prepare
- has Pointer $!prepare_file; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, Typedef<FILE>->|_IO_FILE|*, const Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, Typedef<XQC_Expression>->|XQC_Expression_s|**)* prepare_file
- has Pointer $!prepare_stream; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, Typedef<XQC_InputStream>->|XQC_InputStream_s|*, const Typedef<XQC_StaticContext>->|XQC_StaticContext_s|*, Typedef<XQC_Expression>->|XQC_Expression_s|**)* prepare_stream
- has Pointer $!parse_document; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, const char*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* parse_document
- has Pointer $!parse_document_file; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, Typedef<FILE>->|_IO_FILE|*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* parse_document_file
- has Pointer $!parse_document_stream; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, Typedef<XQC_InputStream>->|XQC_InputStream_s|*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* parse_document_stream
- has Pointer $!create_empty_sequence; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* create_empty_sequence
- has Pointer $!create_singleton_sequence; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, XQC_ItemType, const char*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* create_singleton_sequence
- has Pointer $!create_string_sequence; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, const char**, unsigned int, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* create_string_sequence
- has Pointer $!create_integer_sequence; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, int*, unsigned int, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* create_integer_sequence
- has Pointer $!create_double_sequence; # F:XQC_Error ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*, double*, unsigned int, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* create_double_sequence
- # cw: -YYY- Not implementing yet...
- has Pointer $!get_interface; # F:void* ( const Typedef<XQC_Implementation>->|XQC_Implementation_s|*, const char*)* get_interface
- has Pointer $!free; # F:void ( Typedef<XQC_Implementation>->|XQC_Implementation_s|*)* free
- #has XQC_StaticContext_s $!context;
- sub new {
- createXQillaXQCImplementation(XQC_VERSION_NUMBER);
- }
- # cw: Implemented for completeness, but I do not yet see a need for its
- # use in the Perl6 methods, since passing 0 will give the default
- # static context.
- #method !createContext() {
- # my &func_sig = nativecast(:(XQC_Implementation_s, XQC_StaticContext_s --> XQC_Error), $!create_context);
- #
- # $!context = XQC_StaticContext_s.new();
- #
- # my $err = &func_sig(self, $!context);
- # testErr($err);
- #}
- method prepare(str $expr) {
- my &func_sig = nativecast(:(XQC_Implementation_s, str, Pointer, Pointer --> int32), $!prepare);
- my $xpr = XQC_Expression_s.new();
- my $err = &func_sig(self, $expr, 0, $xpr);
- testErr($err);
- return $xpr;
- }
- multi method prepare_file(IO::Handle $fh) {
- my &func_sig = nativecast(:(XQC_Implementation_s, Pointer, XQC_StaticContext_s, Pointer --> XQC_Error), $!prepare_file);
- #createContext() unless $!context.defined;
- my $NF = fdopen($fh.native-descriptor(), "r");
- my $xpr = XQC_Expression_s.new();
- my $err = &func_sig(self, $NF, XQC_StaticContext_s, $xpr);
- testErr($err);
- fdclose($NF);
- close($fh);
- free($NF);
- return $xpr;
- }
- multi method prepare_file(str $file_name) {
- die "File not found." unless $file_name.IO.e;
- my $fh = open $file_name, :r;
- return .prepare_file($fh);
- }
- method prepare_stream(XQC_InputStream_s $stream) {
- my &func_sig = nativecast(:(XQC_Implementation_s, XQC_InputStream_s, XQC_StaticContext_s, Pointer --> XQC_Error), $!prepare_stream);
- my $xpr = XQC_Expression_s.new();
- my $err = &func_sig(self, $stream, XQC_StaticContext_s, $xpr);
- testErr($err);
- return $xpr;
- }
- method parse_document(str $doc) {
- my &func_sig = nativecast(:(XQC_Implementation_s, str, Pointer --> XQC_Error), $!parse_document);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $doc, $seq);
- testErr($err);
- return $seq;
- }
- multi method parse_document_file(str $file_name) {
- die "File not found." unless $file_name.IO.e;
- my $fh = open $file_name, :r;
- return .parse_document_file($fh);
- }
- multi method parse_document_file(IO::Handle $fh) {
- my &func_sig = nativecast(:(XQC_Implementation_s, Pointer, Pointer --> XQC_Error), $!parse_document_file);
- my $seq = XQC_Sequence_s.new();
- my $NF = fdopen($fh.native-descriptor(), "r");
- my $err = &func_sig(self, $NF, $seq);
- testErr($err);
- fdclose($NF);
- close($fh);
- free($NF);
- return $seq;
- }
- method parse_document_stream(XQC_InputStream_s $stream) {
- my &func_sig = nativecast(:(XQC_Implementation_s, XQC_InputStream_s, Pointer --> XQC_Error), $!parse_document_stream);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $stream, $seq);
- testErr($err);
- return $seq;
- }
- method create_empty_sequence {
- my &func_sig = nativecast(:(XQC_Implementation_s, Pointer --> XQC_Error), $!create_empty_sequence);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $seq);
- testErr($err);
- return $seq;
- }
- method create_singleton_sequence(str $val, XQC_ItemType $type = XQC_ANY_SIMPLE_TYPE) {
- my &func_sig = nativecast(:(XQC_Implementation_s, XQC_ItemType, str, Pointer --> XQC_Error), $!create_singleton_sequence);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $type, $val, $seq);
- testErr($err);
- return $seq;
- }
- method create_string_sequence(Array $arr, Int $count?) {
- my $idx = 0;
- my $carr = CArray[Str].new();
- for ($arr) -> $v {
- die "Non string value encountered in create_string_sequence."
- unless $v ~~ Str;
- $carr[$idx++] = $v;
- }
- $count ||= $idx;
- if ($count != $idx) {
- warn "Count of objects does not match parameter in create_string_sequence.";
- }
- my &func_sig = nativecast(:(XQC_Implementation_s, CArray[Str], uint, Pointer --> XQC_Error), $!create_string_sequence);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $carr, $count, $seq);
- testErr($err);
- return $seq;
- }
- method create_integer_sequence(Array $arr, Int $count?) {
- my $idx = 0;
- my $carr = CArray[int32].new();
- for ($arr) -> $v {
- die "Non integer value or overflow encountered in create_integer_sequence."
- unless [&&] (
- $v ~~ Int,
- $v <= 2 ** 32 - 1,
- $v >= -(2 ** 32)
- );
- $carr[$idx++] = $v;
- }
- $count ||= $idx;
- if ($count != $idx) {
- warn "Count of objects does not match parameter in create_integer_sequence.";
- }
- my &func_sig = nativecast(:(XQC_Implementation_s, CArray[int32], uint, Pointer --> XQC_Error), $!create_string_sequence);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $carr, $count, $seq);
- testErr($err);
- return $seq;
- }
- method create_double_sequence(Array $arr, Int $count?) {
- my $idx = 0;
- my $carr = CArray[num64].new();
- for ($arr) -> $v {
- die "Non double value encountered in create_double_sequence."
- unless $v ~~ Real;
- $carr[$idx++] = $v;
- }
- $count ||= $idx;
- if ($count != $idx) {
- warn "Count of objects does not match parameter in create_double_sequence.";
- }
- my &func_sig = nativecast(:(XQC_Implementation_s, CArray[num64], uint, Pointer --> XQC_Error), $!create_string_sequence);
- my $seq = XQC_Sequence_s.new();
- my $err = &func_sig(self, $carr, $count, $seq);
- testErr($err);
- return $seq;
- }
- submethod DESTROY {
- $!free();
- }
- }
- class XQC_DynamicContext_s is repr<CStruct> is export {
- has Pointer $!set_variable; # F:XQC_Error ( Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, const char*, const char*, Typedef<XQC_Sequence>->|XQC_Sequence_s|*)* set_variable
- has Pointer $!get_variable; # F:XQC_Error ( const Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, const char*, const char*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* get_variable
- has Pointer $!set_context_item; # F:XQC_Error ( Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, Typedef<XQC_Sequence>->|XQC_Sequence_s|*)* set_context_item
- has Pointer $!get_context_item; # F:XQC_Error ( const Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, Typedef<XQC_Sequence>->|XQC_Sequence_s|**)* get_context_item
- has Pointer $!set_implicit_timezone; # F:XQC_Error ( Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, int)* set_implicit_timezone
- has Pointer $!get_implicit_timezone; # F:XQC_Error ( const Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, int*)* get_implicit_timezone
- has Pointer $!set_error_handler; # F:XQC_Error ( Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, Typedef<XQC_ErrorHandler>->|XQC_ErrorHandler_s|*)* set_error_handler
- has Pointer $!get_error_handler; # F:XQC_Error ( const Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, Typedef<XQC_ErrorHandler>->|XQC_ErrorHandler_s|**)* get_error_handler
- has Pointer $!get_interface; # F:void* ( const Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*, const char*)* get_interface
- has Pointer $!free; # F:void ( Typedef<XQC_DynamicContext>->|XQC_DynamicContext_s|*)* free
- submethod DESTROY {
- $!free();
- }
- }
- constant XQC_Expression is export := XQC_Expression_s;
- constant XQC_Sequence is export := XQC_Sequence_s;
- constant XQC_InputStream is export := XQC_InputStream_s;
- constant XQC_Implementation is export := XQC_Implementation_s;
- constant XQC_ErrorHandler is export := XQC_ErrorHandler_s;
- constant XQC_DynamicContext is export := XQC_DynamicContext_s;
- constant XQC_StaticContext is export := XQC_StaticContext_s;
- #
- # Creates an XQC_Implementation object that uses XQilla.
- #
- # ```C
- # XQC_Implementation *createXQillaXQCImplementation(int version);
- # ```
- sub createXQillaXQCImplementation(int32 $version)
- is native('libxqilla') returns XQC_Implementation_s
- is export { * }
- sub testErr($err) {
- # Throw exception based on value of my $err.
- return unless $err != 0;
- my $msg = do given $err {
- when XQC_END_OF_SEQUENCE {
- "End of Sequence";
- }
- when XQC_NO_CURRENT_ITEM {
- "No current item";
- }
- when XQC_PARSE_ERROR {
- "Parse error";
- }
- when XQC_INVALID_ARGUMENT {
- "Invalid argument";
- }
- when XQC_NOT_NODE {
- "Not node";
- }
- when XQC_INTERNAL_ERROR {
- "Internal error";
- }
- when XQC_NOT_IMPLEMENTED {
- "Not implemented";
- }
- when XQC_UNRECOGNIZED_ENCODING {
- "Unrecognized encoding";
- }
- when XQC_STATIC_ERROR {
- "Static error";
- }
- when XQC_TYPE_ERROR {
- "Type error";
- }
- when XQC_DYNAMIC_ERROR {
- "Dynamic error";
- }
- when XQC_SERIALIZATION_ERROR {
- "Serialization error";
- }
- }
- die "An XQilla error has occurred: $msg";
- }
- # cw: ---YYY--- It would be nice to make the following subs private to this module, but
- # it is enough that they are not exported by default.
- # cw: ---YYY--- Insure that the use of int32 is correct on 64-bit systems.
- # To get FILE* from IO::Handle
- sub fdopen(int32, str)
- is native('libc')
- returns Pointer { * };
- sub fdclose(int32)
- is native('libc')
- { * };
- sub free(Pointer)
- is native('libc')
- { * };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement