-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinters.cc
executable file
·253 lines (231 loc) · 9.06 KB
/
printers.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include "simlab.h"
#include <stdio.h>
#include <stdarg.h>
#include <vector>
#ifdef JAVA
#include <jni.h>
#else
#ifdef WIN
#define JNIEXPORT __declspec(dllexport)
#else
#define JNIEXPORT extern "C"
#endif
#endif
extern simlab data;
extern passa<4> passnext;
int (*prnt)( const char*, ... );
template <typename T, typename K> class c_printer {
public:
c_printer( const T nv, int size ) : v(nv), s(size) { /*v = (int*)*new int[1]; *v = (int)nv; */ };
virtual K operator[]( int i ) { return (K)v[i]; };
const T v;
int s;
};
template <> int c_printer<int*,int>::operator []( int i ) {
if( i % s == s-1 ) printf("%d\n", v[i] );
else printf("%d ", v[i] );
return v[i];
};
template <> float c_printer<float*,float>::operator []( int i ) {
if( i % s == s-1 ) printf("%f\n", v[i] );
else printf("%f ", v[i] );
return v[i];
};
template <> double c_printer<double*,double>::operator []( int i ) {
if( i % s == s-1 ) printf("%e \n", (float)v[i] );
else printf("%e ", (float)v[i] );
return v[i];
};
template <typename T, typename K> void t_printrecursive( const char* format, const char* end, T & buffer, std::vector<int> & shape, int index, int here ) {
if( index > 0 ) {
long len = 1;
for( int k = 0; k < index; k++ ) {
len *= shape[k];
}
for( int i = 0; i < shape[index]; i++ ) {
t_printrecursive<T,K>( format, end, buffer, shape, index-1, here+i*len );
}
} else {
int length = shape[0];
for( int i = here; i < here+length; i++ ) {
prnt( format, (K)buffer[i] );
}
}
prnt( end );
}
template <typename T,typename K> void t_print( const char* format, const char* end, T & buffer, int length, ... ) {
va_list args;
va_start(args, length);
std::vector<int> vi;
simlab val = va_arg( args, simlab );
int mul = 1;
while( val.buffer != 0 && vi.size() < 8 ) {
vi.push_back( val.buffer );
mul *= val.buffer;
val = va_arg( args, simlab );
}
va_end( args );
if( length == -1 ) mul = length;
else if( mul != length || vi.size() == 0 ) vi.push_back( length/mul );
t_printrecursive<T,K>( format, end, buffer, vi, vi.size()-1, 0 );
}
extern "C" JNIEXPORT int printer( simlab size ) {
if( data.type == 32 ) {
c_printer<int*,int> * printer = new c_printer<int*,int>( (int*)data.buffer, size.buffer );
data.buffer = (long)printer;
data.type = -data.type;
} else if( data.type == 34 ) {
//float* f = (float*)data.buffer;
c_printer<float*,float> * printer = new c_printer<float*,float>( (float*)data.buffer, size.buffer );
data.buffer = (long)printer;
data.type = -data.type;
/*c_printer<float*,float> & pf = *printer;
for( int i = 0; i < data.length; i++ ) {
printf( "%f co%f\n", f[i], pf[i] );
}*/
} else if( data.type == 66 ) {
c_printer<double*,double> * printer = new c_printer<double*,double>( (double*)data.buffer, size.buffer );
data.buffer = (long)printer;
data.type = -data.type;
}
return 0;
}
extern "C" JNIEXPORT int touch( simlab val ) {
if( val.type == 0 ) {
if( data.type == -32 ) {
c_simlab<int> & cslab = *(c_simlab<int>*)data.buffer;
for( int i = 0; i < data.length; i++ ) {
cslab[i];
}
} else if( data.type == -34 ) {
c_simlab<float> & cslab = *(c_simlab<float>*)data.buffer;
for( int i = 0; i < data.length; i++ ) {
cslab[i];
}
} else if( data.type == -66 ) {
c_simlab<double> & cslab = *(c_simlab<double>*)data.buffer;
for( int i = 0; i < data.length; i++ ) {
cslab[i];
}
}
} else {
if( data.type == -32 ) {
c_simlab<int> & cslab = *(c_simlab<int>*)data.buffer;
cslab[val.buffer];
} else if( data.type == -34 ) {
c_simlab<float> & cslab = *(c_simlab<float>*)data.buffer;
cslab[val.buffer];
} else if( data.type == -66 ) {
c_simlab<double> & cslab = *(c_simlab<double>*)data.buffer;
cslab[val.buffer];
}
}
return 1;
}
JNIEXPORT int print( const char* format, const char* end, ... ) {
if( format == NULL ) {
char* c = (char*)data.buffer;
for( int i = 0; i < data.length; i++ ) {
putchar( c[i] );
}
putchar( '\n' );
} else if( data.type > 0 ) {
if( end == NULL ) end = "\n";
if( data.length == -1 ) {
if( data.type == 66 ) {
//PseudoBuffer<double>* buffer = (PseudoBuffer<double>*)data.buffer;
//if( format[1] == 'e' ) t_print<PseudoBuffer<double>,double>( format, end, *buffer, buffer->length(), passnext );
//else if( format[1] == 'd' ) t_print<PseudoBuffer<double>,int>( format, end, *buffer, buffer->length(), passnext );
} else if( data.type == 32 ) {
c_simlab<int>* buffer = (c_simlab<int>*)data.buffer;
//if( format[1] == 'e' ) t_print<c_simlab<int>,double>( format, end, *buffer, buffer->length(), passnext );
//else if( format[1] == 'd' ) t_print<c_simlab<int>,int>( format, end, *buffer, buffer->length(), passnext );
} else if( data.type == 34 ) {
//PseudoBuffer<float>* buffer = (PseudoBuffer<float>*)data.buffer;
//if( format[1] == 'e' ) t_print<PseudoBuffer<float>,double>( format, end, *buffer, buffer->length(), passnext );
//else if( format[1] == 'd' ) t_print<PseudoBuffer<float>,int>( format, end, *buffer, buffer->length(), passnext );
}
} else if( data.length == 0 ) {
/*if( data.type == 32 ) {
if( format[1] == 'e' ) t_print<unsigned*,double>( format, end, (unsigned int*)&data.buffer, 1, passnext );
else if( format[1] == 'd' ) t_print<unsigned int*,int>( format, end, (unsigned int*)&data.buffer, 1, passnext );
} else if( data.type == 34 ) {
if( format[1] == 'e' ) t_print<float*,double>( format, end, (float*)&data.buffer, 1, passnext );
else if( format[1] == 'd' ) t_print<float*,int>( format, end, (float*)&data.buffer, 1, passnext );
}*/
} else {
if( data.type == 66 ) {
double* db = (double*)data.buffer;
if( format[1] == 'e' ) {
printf("ok\n");
t_print<double*,double>( format, end, db, data.length, passnext );
} else if( format[1] == 'd' ) {
t_print<double*,int>( format, end, db, data.length, passnext );
}
} else if( data.type == 32 ) {
int* ib = (int*)data.buffer;
if( format[1] == 'e' ) t_print<int*,double>( format, end, ib, data.length, passnext );
else if( format[1] == 'd' ) t_print<int*,int>( format, end, ib, data.length, passnext );
} else if( data.type == 16 ) {
short* sb = (short*)data.buffer;
if( format[1] == 'e' ) t_print<short*,double>( format, end, sb, data.length, passnext );
else if( format[1] == 'd' ) t_print<short*,int>( format, end, sb, data.length, passnext );
} else if( data.type == 34 ) {
float* fb = (float*)data.buffer;
if( format[1] == 'e' ) t_print<float*,double>( format, end, fb, data.length, passnext );
else if( format[1] == 'd' ) t_print<float*,int>( format, end, fb, data.length, passnext );
} else if( data.type == 8 ) {
char* cb = (char*)data.buffer;
if( format[1] == 'e' ) t_print<char*,double>( format, end, cb, data.length, passnext );
else if( format[1] == 'd' ) t_print<char*,int>( format, end, cb, data.length, passnext );
}
}
} else {
if( data.type == -66 ) {
c_simlab<double&> & sdb = *(c_simlab<double&>*)data.buffer;
if( format[1] == 'e' ) {
printf("okok %d\n", sdb[2] );
t_print<c_simlab<double&>,double>( format, end, sdb, data.length, passnext );
} else if( format[1] == 'd' ) {
t_print<c_simlab<double&>,int>( format, end, sdb, data.length, passnext );
}
} else if( data.type == -64 ) {
c_simlab<long long> & slb = *(c_simlab<long long>*)data.buffer;
if( format[1] == 'e' ) t_print<c_simlab<long long>,double>( format, end, slb, data.length, passnext );
else if( format[1] == 'd' ) t_print<c_simlab<long long>,int>( format, end, slb, data.length, passnext );
else if( format[1] == 'l' ) t_print<c_simlab<long long>,long long>( format, end, slb, data.length, passnext );
} else if( data.type == -32 ) {
c_simlab<int> & sib = *(c_simlab<int>*)data.buffer;
if( format[1] == 'e' ) t_print<c_simlab<int>,double>( format, end, sib, data.length, passnext );
else if( format[1] == 'd' ) t_print<c_simlab<int>,int>( format, end, sib, data.length, passnext );
} else if( data.type == -16 ) {
short* sb = (short*)data.buffer;
if( format[1] == 'e' ) t_print<short*,double>( format, end, sb, data.length, passnext );
else if( format[1] == 'd' ) t_print<short*,int>( format, end, sb, data.length, passnext );
} else if( data.type == -34 ) {
c_simlab<float> & sfb = *(c_simlab<float>*)data.buffer;
if( format[1] == 'e' ) t_print<c_simlab<float>,double>( format, end, sfb, data.length, passnext );
else if( format[1] == 'd' ) t_print<c_simlab<float>,int>( format, end, sfb, data.length, passnext );
} else if( data.type == -8 ) {
char* cb = (char*)data.buffer;
if( format[1] == 'e' ) t_print<char*,double>( format, end, cb, data.length, passnext );
else if( format[1] == 'd' ) t_print<char*,int>( format, end, cb, data.length, passnext );
}
}
return 2;
}
JNIEXPORT int printihtml( ... ) {
return print( "%d\t", "<br>\n", passnext );
}
JNIEXPORT int printdhtml( ... ) {
return print( "%e\t", "<br>\n", passnext );
}
JNIEXPORT int printi( ... ) {
return print( "%d\t", "\n", passnext );
}
JNIEXPORT int printd( ... ) {
return print( "%e\t", "\n", passnext );
}
JNIEXPORT int printl( ... ) {
return print( "%lld\t", "\n", passnext );
}