package body My_Lib.Bascules is
-------------------------------------------------
-- Obtenir le l'ajustement maximum et minimum. --
-------------------------------------------------
function Max(Bascule : in Bascule_Type'Class) return Adjustement_Type is
begin
if Bascule.Ponderations(Right) > Bascule.Ponderations(Left) then
return Right;
elsif Bascule.Ponderations(Left) > Bascule.Ponderations(Right) then
return Left;
else
return Adjust;
end if;
end Max;
function Min(Bascule : in Bascule_Type'Class) return Adjustement_Type is
begin
if Bascule.Ponderations(Right) < Bascule.Ponderations(Left) then
return Right;
elsif Bascule.Ponderations(Left) < Bascule.Ponderations(Right) then
return Left;
else
return Adjust;
end if;
end Min;
----------------------------------------------------------
-- Adjuster les plateaux d'une bascule par pondération. --
----------------------------------------------------------
procedure Ponderation(Bascule : in out Bascule_Type'Class;
Board : in Adjustement_Type;
Ponderation : in Float) is
begin
Bascule.Ponderations(Board) := Bascule.Ponderations(Board) + Ponderation;
case Board is
when Left =>
Bascule.Ponderations(Right) := Bascule.Ponderations(Right) - Ponderation;
Bascule.Ponderations(Left) := Bascule.Ponderations(Left) + Ponderation;
when Right =>
Bascule.Ponderations(Left) := Bascule.Ponderations(Left) - Ponderation;
Bascule.Ponderations(Right) := Bascule.Ponderations(Right) + Ponderation;
when Adjust =>
if Bascule.Ponderations(Adjust) > Ponderation then
Bascule.Ponderations(Left) := Bascule.Ponderations(Left) - Ponderation;
elsif Ponderation > Bascule.Ponderations(Adjust) then
Bascule.Ponderations(Right) := Bascule.Ponderations(Right) + Ponderation;
else
return;
end if;
end case;
if Max(Bascule) /= Adjust then
Bascule.Ponderations(Adjust) := abs(Bascule.Ponderations(Bascule.Max) -
Bascule.Ponderations(Bascule.Min));
end if;
exception
when Constraint_Error =>
raise Board_Overflow;
end Ponderation;
----------------------------------------
-- Obtenir l'ajustement d'une bascule --
----------------------------------------
function Adjustement(Bascule : in Bascule_Type'Class;Adjustement : in Adjustement_type) return Float is
begin
return Bascule.Ponderations(Adjustement);
end Adjustement;
---------------------------------
-- Mettre les plateaux à zero. --
---------------------------------
procedure Reset(Bascule : in out Bascule_Type'Class) is
begin
Bascule.Ponderations := (others => 0.0);
end Reset;
end My_Lib.bascules;