Skip to content

Commit

Permalink
M agpl-cr-cost_matrix.adb
Browse files Browse the repository at this point in the history
M    agpl-cr-cost_matrix.ads
M    agpl-generic_file_store.adb
  • Loading branch information
mosteo committed Sep 5, 2006
1 parent f8c2485 commit 948d677
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
48 changes: 48 additions & 0 deletions agpl-cr-cost_matrix.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ with Agpl.Conversions; use Agpl.Conversions;
with Agpl.Cr.Tasks.Starting_Pose;
with Agpl.Trace; use Agpl.Trace;

with Ada.Containers;

package body Agpl.Cr.Cost_Matrix is

use type Cr.Costs;
Expand Down Expand Up @@ -254,4 +256,50 @@ package body Agpl.Cr.Cost_Matrix is
Include (This.Matrix, Key (Agent, Ini, Fin), Cost);
end Set_Cost;

----------
-- Read --
----------

procedure Read (Stream : access Ada.Streams.Root_Stream_Type'Class;
This : out Object)
is
use Ada.Containers;
Size : constant Count_Type := Count_Type'Input (Stream);
begin
This.Matrix.Clear;
This.Matrix.Reserve_Capacity (Size);

for I in 1 .. Size loop
declare
Key : constant String := String'Input (Stream);
C : constant Costs := Costs'Input (Stream);
begin
This.Matrix.Include (Key, C);
end;
-- if I rem 100 = 0 then
-- Log ("Read" & I'Img & " of" & Size'Img, Always);
-- end if;
end loop;
end Read;

-----------
-- Write --
-----------

procedure Write (Stream : access Ada.Streams.Root_Stream_Type'Class;
This : in Object)
is
use Ada.Containers;

procedure Write (I : in Cursor) is
begin
String'Output (Stream, Key (I));
Costs'Output (Stream, Element (I));
end Write;

begin
Count_Type'Output (Stream, This.Matrix.Length);
This.Matrix.Iterate (Write'Access);
end Write;

end Agpl.Cr.Cost_Matrix;
10 changes: 10 additions & 0 deletions agpl-cr-cost_matrix.ads
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ with Agpl.Cr.Agent.Containers;
with Agpl.Htn.Tasks;
with Agpl.Htn.Tasks.Containers;

with Ada.Streams;

package Agpl.Cr.Cost_Matrix is

pragma Preelaborate;
Expand Down Expand Up @@ -111,6 +113,14 @@ package Agpl.Cr.Cost_Matrix is
procedure Print (This : in Object);
-- Debug dump

procedure Read (Stream : access Ada.Streams.Root_Stream_Type'Class;
This : out Object);
for Object'Read use Read;

procedure Write (Stream : access Ada.Streams.Root_Stream_Type'Class;
This : in Object);
for Object'Write use Write;

private

package ATT_Maps is new Ada.Containers.Indefinite_Hashed_Maps
Expand Down
2 changes: 1 addition & 1 deletion agpl-generic_file_store.adb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ package body Agpl.Generic_File_Store is
begin
Open (F, Name => File, Mode => In_File);

This := Item'Input (Stream (F));
Item'Read (Stream (F), This);

Close (F);
end Load;
Expand Down

0 comments on commit 948d677

Please sign in to comment.