1 // SPDX-License-Identifier: Apache-2.0
2
3 // Implementations of string callbacks
4 #include <limits>
5 #include <iostream>
6 #include "GB_callback.hpp"
7
8 // Define function pointer we will use later
9 std::istream* (*file_callback)(std::string, std::iostream&);
10
11
12 //Semi-ring callbacks
13
14 std::istream* semiring_plus_times_callback( std::string filename, std::iostream& tmp_stream);
15
16 std::istream* semiring_min_plus_callback( std::string filename, std::iostream& tmp_stream);
17
18 std::istream* semiring_max_plus_callback( std::string filename, std::iostream& tmp_stream);
19
20
21 //Monoid callbacks
22
23 std::istream* file_callback_plus(std::string filename, std::iostream& tmp_stream);
24
25 std::istream* file_callback_max(std::string filename, std::iostream& tmp_stream);
26
27 std::istream* file_callback_min(std::string filename, std::iostream& tmp_stream);
28
29
semiring_plus_times_callback(std::string filename,std::iostream & tmp_stream)30 std::istream* semiring_plus_times_callback( std::string filename,
31 std::iostream& tmp_stream)
32 {
33 if (filename == "mySemiRing.h") {
34 tmp_stream << "#define MONOID_IDENTITY (T_Z)0\n"
35 "#define MULADD( c, a, b ) (c) += (T_Z)( (a) * (b) )\n"
36 "#define MUL( a, b) (a) * (b)\n"
37 "#define ADD( a, b) (a) + (b)\n";
38 return &tmp_stream;
39 }
40 else {
41 // Find this file through other mechanisms
42 return 0;
43 }
44
45 }
46
semiring_min_plus_callback(std::string filename,std::iostream & tmp_stream)47 std::istream* semiring_min_plus_callback( std::string filename,
48 std::iostream& tmp_stream)
49 { // Define the identity and operations for the (MIN,PLUS) semi-ring. mul->+, add -> min
50 if (filename == "mySemiRing.h") {
51 tmp_stream << "#define MONOID_IDENTITY std::numeric_limits<T_Z>::max()\n"
52 "#define MUL( a, b) (a) + (b)\n"
53 "#define ADD( a, b) (a) < (b) ? (a) : (b)\n";
54 return &tmp_stream;
55 }
56 else {
57 // Find this file through other mechanisms
58 return 0;
59 }
60
61 }
62
semiring_max_plus_callback(std::string filename,std::iostream & tmp_stream)63 std::istream* semiring_max_plus_callback( std::string filename,
64 std::iostream& tmp_stream)
65 { // Define the identity and operations for the (MAX,PLUS) semi-ring. mul->+, add -> max
66 if (filename == "mySemiRing.h") {
67 tmp_stream << "#define MONOID_IDENTITY std::numeric_limits<T_Z>::min()\n"
68 "#define MUL( a, b) (a) + (b)\n"
69 "#define ADD( a, b) (a) > (b) ? (a) : (b)\n";
70 return &tmp_stream;
71 }
72 else {
73 // Find this file through other mechanisms
74 return 0;
75 }
76
77 }
78
file_callback_plus(std::string filename,std::iostream & tmp_stream)79 std::istream* file_callback_plus(std::string filename, std::iostream& tmp_stream) {
80 // User returns NULL or pointer to stream containing file source
81 // Note: tmp_stream is provided for convenience
82 if (filename == "myOp.h") {
83 tmp_stream << "#pragma once\n"
84 "#define MONOID_IDENTITY (T)0\n"
85 "#define OP( a, b) (a) + (b)\n";
86 return &tmp_stream;
87 }
88 else {
89 // Find this file through other mechanisms
90 return 0;
91 }
92 }
93
file_callback_max(std::string filename,std::iostream & tmp_stream)94 std::istream* file_callback_max(std::string filename, std::iostream& tmp_stream) {
95 // User returns NULL or pointer to stream containing file source
96 // Note: tmp_stream is provided for convenience
97 if (filename == "myOp.h") {
98 tmp_stream << "#pragma once\n"
99 "#include <limits>\n"
100 "#define MONOID_IDENTITY std::numeric_limits<T>::min()\n"
101 "#define OP( a, b) (a) > (b) ? (a) : (b)\n";
102
103 return &tmp_stream;
104 }
105 else {
106 // Find this file through other mechanisms
107 return 0;
108 }
109 }
110
file_callback_min(std::string filename,std::iostream & tmp_stream)111 std::istream* file_callback_min(std::string filename, std::iostream& tmp_stream) {
112 // User returns NULL or pointer to stream containing file source
113 // Note: tmp_stream is provided for convenience
114 if (filename == "myOp.h") {
115 tmp_stream << "#pragma once\n"
116 "#include <limits>\n"
117 "#define MONOID_IDENTITY std::numeric_limits<T>::max()\n"
118 "#define OP( a, b) (a) < (b) ? (a) : (b)\n";
119
120 return &tmp_stream;
121 }
122 else {
123 // Find this file through other mechanisms
124 return 0;
125 }
126 }
127
128
129