summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-12-14 12:50:43 +0100
committerErich Eckner <git@eckner.net>2017-12-14 12:50:43 +0100
commit03b2d87e3609bcff1bf1056cacecad8847bcad1c (patch)
treeda9a19f20a95e734919eae0b5675ca73fa96911a
parentab00e58c9cdedfa4c564b168251974a9a2ebff91 (diff)
downloadunits-03b2d87e3609bcff1bf1056cacecad8847bcad1c.tar.xz
matheunit.pas: tKnownValues haben jetzt einen Vorgesetzten
-rw-r--r--matheunit.pas72
1 files changed, 66 insertions, 6 deletions
diff --git a/matheunit.pas b/matheunit.pas
index d5f9de7..71005c5 100644
--- a/matheunit.pas
+++ b/matheunit.pas
@@ -16,17 +16,21 @@ type
end;
tKnownValues = class
private
- kvs: array of tKnownValue;
+ chef: tKnownValues;
+ knechte: array of tKnownValues;
+ kvs: array of tKnownValue;
function finde(nam: string): longint; inline;
public
- constructor create; overload;
- constructor create(original: tKnownValues); overload;
+ constructor create(chf: tKnownValues);
+ constructor createFromOriginal(original: tKnownValues);
destructor destroy; override;
procedure add(val: tKnownValue); inline; overload;
procedure add(nam: string; val: extended); overload;
function rem(nam: string): boolean;
function extract(nam: string; out val: extended): boolean; inline;
procedure dump(prot: tProtokollant; prefix: string);
+ procedure neuerKnecht(knecht: tKnownValues);
+ procedure entferneKnecht(knecht: tKnownValues);
end;
function plus(a,b: tExtPoint): tExtPoint;
@@ -59,26 +63,47 @@ implementation
// tKnownValueArray ************************************************************
-constructor tKnownValues.create;
+constructor tKnownValues.create(chf: tKnownValues);
begin
inherited create;
fillchar(kvs,sizeOf(kvs),#0);
+ fillchar(knechte,sizeOf(knechte),#0);
add('π',pi);
+ chef:=chf;
+ if assigned(chef) then
+ chef.neuerKnecht(self);
+ setLength(knechte,0);
end;
-constructor tKnownValues.create(original: tKnownValues);
+constructor tKnownValues.createFromOriginal(original: tKnownValues);
var
i: longint;
begin
inherited create;
fillchar(kvs,sizeOf(kvs),#0);
+ fillchar(knechte,sizeOf(knechte),#0);
for i:=0 to length(original.kvs)-1 do
add(original.kvs[i]);
+ chef:=original.chef;
+ if assigned(chef) then
+ chef.neuerKnecht(self);
end;
destructor tKnownValues.destroy;
+var
+ i: longint;
begin
setLength(kvs,0);
+ for i:=0 to length(knechte)-1 do begin
+ knechte[i].chef:=chef;
+ if assigned(chef) then
+ chef.neuerKnecht(knechte[i]);
+ end;
+ setLength(knechte,0);
+ if assigned(chef) then begin
+ chef.entferneKnecht(self);
+ chef:=nil;
+ end;
inherited destroy;
end;
@@ -135,7 +160,10 @@ begin
i:=finde(nam);
result:=i>=0;
if result then
- val:=kvs[i].value;
+ val:=kvs[i].value
+ else
+ if assigned(chef) then
+ result:=chef.extract(nam,val);
end;
procedure tKnownValues.dump(prot: tProtokollant; prefix: string);
@@ -144,6 +172,38 @@ var
begin
for i:=0 to length(kvs)-1 do
prot.schreibe(prefix+kvs[i].name+' = '+floattostr(kvs[i].value));
+ if assigned(chef) then
+ chef.dump(prot,prefix+' chef: ');
+end;
+
+procedure tKnownValues.neuerKnecht(knecht: tKnownValues);
+var
+ i: longint;
+begin
+ for i:=0 to length(knechte)-1 do
+ if knechte[i]=knecht then
+ fehler('tKnownValues soll einen Knecht hinzufügen, den es schon hat!');
+ setLength(knechte,length(knechte)+1);
+ knechte[length(knechte)-1]:=knecht;
+end;
+
+procedure tKnownValues.entferneKnecht(knecht: tKnownValues);
+var
+ i: longint;
+begin
+ i:=0;
+ while i<length(knechte) do begin
+ if knechte[i]=knecht then begin
+ while i<length(knechte)-1 do begin
+ knechte[i]:=knechte[i+1];
+ inc(i);
+ end;
+ setLength(knechte,length(knechte)-1);
+ exit;
+ end;
+ inc(i);
+ end;
+ fehler('tKnownValues soll einen Knecht entfernen, den es nicht hat!');
end;
// allgemeine Funktionen *******************************************************