-
Notifications
You must be signed in to change notification settings - Fork 1
/
rlcsa.i
89 lines (64 loc) · 2.11 KB
/
rlcsa.i
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
// Name the module something Java-y that isn't going to clash with the RLCSA
// class.
%module RLCSAUtil
// Set up STL compatibility
%include "std_string.i"
%include "std_pair.i"
// And pointer arrays
%include "carrays.i"
// And pointers
%include "cpointer.i"
// And integers of various sizes
%include <stdint.i>
// Set up exception not-killing-the-process-ness. See
// <http://www.swig.org/Doc1.3/Library.html#Library_nn17>
%include "exception.i"
%exception {
try {
$action
} catch (const std::exception& e) {
SWIG_exception(SWIG_RuntimeError, e.what());
}
}
%{
#include "rlcsa.h"
using namespace CSA;
%}
#ifdef MASSIVE_DATA_RLCSA
typedef unsigned long usint;
typedef signed long sint;
#else
typedef unsigned int usint;
typedef signed int sint;
#endif
// uchars are unsigned chars.
typedef unsigned char uchar;
// Java needs to work with pair_types that are count results.
typedef std::pair<usint, usint> pair_type;
%template(pair_type) std::pair<usint, usint>;
// We need to be able to work with arrays of usint
%array_functions(usint,USIntArray);
// And with pointers to usint
%pointer_functions(usint,USIntPointer);
// And with arrays of characters (instead of null-terminated strings) for the
// display output.
%array_functions(uchar,UCharArray)
// Whenever any of the JNI classes loads, load the native library.
%pragma(java) jniclasscode=%{
static {
RLCSANativeLoader.load();
}
%}
// Mark some of the display methods as making new objects we need to manage the
// memory of. TODO: get them all.
%newobject RLCSA::display(usint sequence, bool include_end_marker = false);
%newobject RLCSA::display(usint sequence, pair_type range) const;
uchar* RLCSA::display(usint sequence, pair_type range) const;
// Those display methods don't null-terminate their strings. Make sure they are
// arrays by not saying those uchar*s should be strings.
// The other uchar*s are actually char*s (null-terminated strings)
%apply char* { uchar* pattern, uchar* base_name };
%include "rlcsa.h"
// We also take the important inlines in misc/definitions.h for working with
// pair_type ranges.
%include "misc/definitions.h"