-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportpolynomial.pas
78 lines (63 loc) · 2.54 KB
/
importpolynomial.pas
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
unit ImportPolynomial;
{$mode objfpc}{$H+}
interface
type
TPolynomial = Pointer;
TCopyFunc = function (P: TPolynomial): TPolynomial;
TConstructor = function: TPolynomial; cdecl;
TDestructor = procedure (var P: TPolynomial); cdecl;
TGetIntegerFunc = function (P: TPolynomial): Integer; cdecl;
TSetIntegerProc = procedure (P: TPolynomial; AValue: Integer); cdecl;
TGetDoubleAtIndex = function (P: TPolynomial; AnIndex: Integer): Double; cdecl;
TSetDoubleAtIndex = procedure (P: TPolynomial; AnIndex: Integer; AValue: Double); cdecl;
TGetValueFromArg = function (P: TPolynomial; x: Double): Double; cdecl;
TGetDerivation = function(P: TPolynomial; n: Integer): TPolynomial; cdecl;
TGetSecant = function(P: TPolynomial; a, b: Double): TPolynomial; cdecl;
TGetTangent = function (P: TPolynomial; x0: Double): TPolynomial; cdecl;
var
CreatePolynomial: TConstructor;
CreateCopy: TCopyFunc;
DestroyPolynomial: TDestructor;
GetDegree: TGetIntegerFunc;
SetDegree: TSetIntegerProc;
GetCoefficient: TGetDoubleAtIndex;
SetCoefficient: TSetDoubleAtIndex;
GetPolynomialValue: TGetValueFromArg;
GetDerivation: TGetDerivation;
GetSecant: TGetSecant;
GetTangent: TGetTangent;
LibLoaded: Boolean;
implementation
uses DynLibs, SysUtils;
const
LibFileName = '/Users/andreas/.lib/libpolynomial.dylib';
procedure LinkProc(Lib: TLibHandle; AFuncName: string; var AFuncVar);
begin
Pointer(AFuncVar) := GetProcedureAddress(Lib, AFuncName);
if Pointer(AFuncVar) = nil then
raise Exception.CreateFmt('"%s" is not found in "%s"', [AFuncName, LibFileName]);
end;
var
LibHandle: TLibHandle;
initialization
LibHandle := LoadLibrary(LibFileName);
if LibHandle <> NilHandle then begin
LinkProc(LibHandle, 'CreatePolynomial', CreatePolynomial);
LinkProc(LibHandle, 'CreateCopy', CreateCopy);
LinkProc(LibHandle, 'DestroyPolynomial', DestroyPolynomial);
LinkProc(LibHandle, 'GetDegree', GetDegree);
LinkProc(LibHandle, 'SetDegree', SetDegree);
LinkProc(LibHandle, 'GetCoefficient', GetCoefficient);
LinkProc(LibHandle, 'SetCoefficient', SetCoefficient);
LinkProc(LibHandle, 'GetPolynomialValue', GetPolynomialValue);
LinkProc(LibHandle, 'GetDerivation', GetDerivation);
LinkProc(LibHandle, 'GetSecant', GetSecant);
LinkProc(LibHandle, 'GetTangent', GetTangent);
LibLoaded := True;
end
else raise Exception.Create(GetLoadErrorStr);
finalization
LibLoaded := False;
if not UnloadLibrary(LibHandle) then
raise Exception.CreateFmt('Unloading of "%s" is not possibly', [LibFileName]);
end.