1 //------------------------------------------------------------------------------
2 // GB_cast_factory: return a pointer to a typecasting function
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7
8 //------------------------------------------------------------------------------
9
10 // Returns a pointer to a function f(z,x,s) that copies its input x into its
11 // output z, casting as needed. That is, it computes z = (type of z) x.
12 // s is the size for user-defined types, which can only be copied.
13
14 // This function returns one of ((13*13) + 1) pointers to a typecasting/copy
15 // function. 13*13 is the set of functions named GB__cast_ZTYPE_XTYPE, for
16 // each pair of built-in types (ZTYPE, XTYPE). The last pointer is the
17 // function GB_copy_user_user.
18
19 #include "GB.h"
20
21 GB_PUBLIC // accessed by the MATLAB tests in GraphBLAS/Test only
GB_cast_factory(const GB_Type_code code1,const GB_Type_code code2)22 GB_cast_function GB_cast_factory // returns pointer to function to cast x to z
23 (
24 const GB_Type_code code1, // the type of z, the output value
25 const GB_Type_code code2 // the type of x, the input value
26 )
27 {
28
29 //--------------------------------------------------------------------------
30 // define the worker for the switch factory
31 //--------------------------------------------------------------------------
32
33 // the worker selects a typecast function and returns it to the caller
34 #define GB_WORKER(ignore1,ignore2,ztype,ignore3,xtype) \
35 return (&GB (_cast_ ## ztype ## _ ## xtype)) ;
36
37 //--------------------------------------------------------------------------
38 // launch the switch factory
39 //--------------------------------------------------------------------------
40
41 // switch factory for two built-in types; user types are skipped.
42 // no generic worker so the switch factory cannot be disabled.
43 #include "GB_2type_factory.c"
44
45 //--------------------------------------------------------------------------
46 // user-defined types fall through the switch factory to here
47 //--------------------------------------------------------------------------
48
49 return (&GB_copy_user_user) ;
50 }
51
52