+ Added some index checking. Centralized error handling (merged)

This commit is contained in:
peter 2000-10-15 09:27:48 +00:00
parent 788a2e5be2
commit 093bbd5017
2 changed files with 79 additions and 56 deletions

View File

@ -15,6 +15,30 @@
{* TBits *}
{****************************************************************************}
ResourceString
SErrInvalidBitIndex = 'Invalid bit index : %d';
SErrindexTooLarge = 'Bit index exceeds array limit: %d';
Procedure BitsError (Msg : string);
begin
Raise EBitsError.Create(Msg);
end;
Procedure BitsErrorFmt (Msg : string; Args : array of const);
begin
Raise EBitsError.CreateFmt(Msg,args);
end;
procedure CheckBitIndex (Bit : longint);
begin
if (bit<0) then
BitsErrorFmt(SErrInvalidBitIndex,[bit]);
if (bit>=MaxBitFlags) then
BitsErrorFmt(SErrIndexTooLarge,[bit])
end;
{ ************* functions to match TBits class ************* }
function TBits.getSize : longint;
@ -89,9 +113,7 @@ var
newSize : longint;
loop : longint;
begin
if nbit >= MaxBitFlags then
Raise EBitsError.Create('Bit index exceeds array limit');
CheckBitindex(nbit);
newSize := (nbit shr BITSHIFT) + 1;
@ -119,9 +141,7 @@ var
n : longint;
begin
n := bit shr BITSHIFT;
grow(bit);
FBits^[n] := FBits^[n] or (longint(1) shl (bit and MASK));
end;
@ -129,10 +149,9 @@ procedure TBits.clear(bit : longint);
var
n : longint;
begin
CheckBitIndex(bit);
n := bit shr BITSHIFT;
grow(bit);
FBits^[n] := FBits^[n] and not(longint(1) shl (bit and MASK));
end;
@ -148,13 +167,9 @@ function TBits.get(bit : longint) : Boolean;
var
n : longint;
begin
CheckBitIndex(bit);
result := False;
if bit >= MaxBitFlags then
Raise EBitsError.Create('Bit index exceeds array limit');
n := bit shr BITSHIFT;
if (n < FSize) then
result := (FBits^[n] and (longint(1) shl (bit and MASK))) <> 0;
end;
@ -353,7 +368,12 @@ end;
{
$Log$
Revision 1.2 2000-07-13 11:32:58 michael
Revision 1.3 2000-10-15 09:27:48 peter
+ Added some index checking. Centralized error handling (merged)
Revision 1.2 2000/07/13 11:32:58 michael
+ removed logs
Revision 1.1 2000/07/13 06:31:29 michael
+ Initial import
}

View File

@ -1181,7 +1181,10 @@ end;
{
$Log$
Revision 1.4 2000-10-13 12:33:23 sg
Revision 1.5 2000-10-15 09:27:48 peter
+ Added some index checking. Centralized error handling (merged)
Revision 1.4 2000/10/13 12:33:23 sg
* Some small cosmetic changes and minor fixes
Revision 1.3 2000/07/22 14:55:56 sg