buildlib/Lucy/Build/Binding/Object.pm

filter: Statementstmt 100% 25 / 25 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 90.9% 30 / 33 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
bind_all
1.0
CRAP 1.0
« buildlib/Lucy/Build/Binding/Plan.pm ↑ Summary buildlib/Lucy/Build/Binding/Highlight.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 package Lucy::Build::Binding::Object;
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '0.008000';
20 1 $VERSION = eval $VERSION;
21  
22 1 ▶sub bind_all {
Subroutine bind_all: called CC=1 SCAR=0.0
Pod undocumented
23 1 my $class = shift;
24 1 $class->bind_bitvector;
25 1 $class->bind_i32array;
26 }
27  
28 1 ▶sub bind_bitvector {
Subroutine bind_bitvector: called CC=1 SCAR=0.0
Pod undocumented
29 1 my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
30 1 my $synopsis = <<'END_SYNOPSIS';
31 my $bit_vec = Lucy::Object::BitVector->new( capacity => 8 );
32 my $other = Lucy::Object::BitVector->new( capacity => 8 );
33 $bit_vec->set($_) for ( 0, 2, 4, 6 );
34 $other->set($_) for ( 1, 3, 5, 7 );
35 $bit_vec->or($other);
36 print "$_\n" for @{ $bit_vec->to_array }; # prints 0 through 7.
37 END_SYNOPSIS
38 1 my $constructor = <<'END_CONSTRUCTOR';
39 my $bit_vec = Lucy::Object::BitVector->new(
40 capacity => $doc_max + 1, # default 0,
41 );
42 END_CONSTRUCTOR
43 1 $pod_spec->set_synopsis($synopsis);
44 1 $pod_spec->add_constructor( alias => 'new', sample => $constructor );
45  
46 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
47 parcel => "Lucy",
48 class_name => "Lucy::Object::BitVector",
49 );
50 1 $binding->set_pod_spec($pod_spec);
51  
52 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
53 }
54  
55 1 ▶sub bind_i32array {
Subroutine bind_i32array: called CC=1 SCAR=0.0
Pod undocumented
56 1 my $xs_code = <<'END_XS_CODE';
57 MODULE = Lucy PACKAGE = Lucy::Object::I32Array
58  
59 #include "Clownfish/Util/Memory.h"
60  
61 SV*
62 new(either_sv, ...)
63 SV *either_sv;
64 CODE:
65 {
66 static const XSBind_ParamSpec param_specs[1] = {
67 XSBIND_PARAM("ints", true)
68 };
69 int32_t locations[1];
70 SV *ints_sv = NULL;
71 AV *ints_av = NULL;
72 lucy_I32Array *self = NULL;
73  
74 XSBind_locate_args(aTHX_ &ST(0), 1, items, param_specs, locations, 1);
75  
76 ints_sv = ST(locations[0]);
77 if (SvROK(ints_sv)) {
78 ints_av = (AV*)SvRV(ints_sv);
79 }
80 if (ints_av && SvTYPE(ints_av) == SVt_PVAV) {
81 int64_t size = av_len(ints_av) + 1;
82 int32_t *ints;
83 int64_t i;
84 if (size < 0 || size > INT32_MAX) {
85 THROW(CFISH_ERR, "Size out of range: %i64", size);
86 }
87 ints = (int32_t*)CFISH_MALLOCATE(size * sizeof(int32_t));
88  
89 for (i = 0; i < size; i++) {
90 SV **const sv_ptr = av_fetch(ints_av, (I32)i, 0);
91 ints[i] = (sv_ptr && XSBind_sv_defined(aTHX_ *sv_ptr))
92 ? SvIV(*sv_ptr)
93 : 0;
94 }
95 self = (lucy_I32Array*)XSBind_new_blank_obj(aTHX_ either_sv);
96 lucy_I32Arr_init(self, ints, (size_t)size);
97 }
98 else {
99 THROW(CFISH_ERR, "Required param 'ints' isn't an arrayref");
100 }
101  
102 RETVAL = CFISH_OBJ_TO_SV_NOINC(self);
103 }
104 OUTPUT: RETVAL
105  
106 SV*
107 to_arrayref(self)
108 lucy_I32Array *self;
109 CODE:
110 {
111 AV *out_av = newAV();
112 size_t i;
113 size_t size = LUCY_I32Arr_Get_Size(self);
114  
115 av_extend(out_av, size);
116 for (i = 0; i < size; i++) {
117 int32_t result = LUCY_I32Arr_Get(self, i);
118 SV* result_sv = result == -1 ? newSV(0) : newSViv(result);
119 av_push(out_av, result_sv);
120 }
121 RETVAL = newRV_noinc((SV*)out_av);
122 }
123 OUTPUT: RETVAL
124 END_XS_CODE
125  
126 1 my $binding = Clownfish::CFC::Binding::Perl::Class->new(
127 parcel => "Lucy",
128 class_name => "Lucy::Object::I32Array",
129 );
130 1 $binding->append_xs($xs_code);
131 1 $binding->exclude_constructor;
132  
133 1 Clownfish::CFC::Binding::Perl::Class->register($binding);
134 }
135  
136 1 1;
« buildlib/Lucy/Build/Binding/Plan.pm ↑ Summary buildlib/Lucy/Build/Binding/Highlight.pm »