Skip to content

Commit

Permalink
A agpl-generic_indefinite_file_store.adb
Browse files Browse the repository at this point in the history
A    agpl-generic_indefinite_file_store.ads
M    agpl-generic_file_store.adb
M    agpl-generic_file_store.ads
  • Loading branch information
mosteo committed Sep 5, 2006
1 parent c00fa0b commit f8c2485
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
21 changes: 15 additions & 6 deletions agpl-generic_file_store.adb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ package body Agpl.Generic_File_Store is
----------

function Load (File : in String) return Item is
Result : Item;
begin
Load (Result, File);

return Result;
end Load;

----------
-- Load --
----------

procedure Load (This : out Item; File : in String) is
use Ada.Streams.Stream_Io;
F : File_Type;
begin
Open (F, Name => File, Mode => In_File);

declare
Result : constant Item := Item'Input (Stream (F));
begin
Close (F);
return Result;
end;
This := Item'Input (Stream (F));

Close (F);
end Load;

end Agpl.Generic_File_Store;
8 changes: 7 additions & 1 deletion agpl-generic_file_store.ads
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@
------------------------------------------------------------------------------

generic
type Item (<>) is private;
type Item is private;
package Agpl.Generic_File_Store is

pragma Elaborate_Body;

type Item_Access is access all Item;

procedure To_File (This : in Item; File : in String);
-- This uses Item'Write
-- Write a file with the dumped item. Overwrites if existing.

function Load (File : in String) return Item;
-- This uses Item'Read

procedure Load (This : out Item; File : in String);
-- This uses Item'Read
-- In place to avoid extra copy at return.

end Agpl.Generic_File_Store;
37 changes: 37 additions & 0 deletions agpl-generic_indefinite_file_store.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
with Ada.Streams.Stream_Io;

package body Agpl.Generic_Indefinite_File_Store is

-------------
-- To_File --
-------------

procedure To_File (This : in Item; File : in String) is
use Ada.Streams.Stream_Io;
F : File_Type;
begin
Create (F, Name => File, Mode => Out_File);

Item'Output (Stream (F), This);
Close (F);
end To_File;

----------
-- Load --
----------

function Load (File : in String) return Item is
use Ada.Streams.Stream_Io;
F : File_Type;
begin
Open (F, Name => File, Mode => In_File);

declare
Result : constant Item := Item'Input (Stream (F));
begin
Close (F);
return Result;
end;
end Load;

end Agpl.Generic_Indefinite_File_Store;
43 changes: 43 additions & 0 deletions agpl-generic_indefinite_file_store.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
------------------------------------------------------------------------------
-- ADAGIO - ADALID - AENEA. --
-- --
-- Copyright (C) 2003 --
-- A. Mosteo. --
-- --
-- Authors: A. Mosteo. (adagio@mosteo.com) --
-- --
-- If you have any questions in regard to this software, please address --
-- them to the above email. --
-- --
-- This program is free software; you can redistribute it and/or modify --
-- it under the terms of the GNU General Public License as published by --
-- the Free Software Foundation; either version 2 of the License, or (at --
-- your option) any later version. --
-- --
-- This program is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public License --
-- along with this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --

------------------------------------------------------------------------------

generic
type Item (<>) is private;
package Agpl.Generic_Indefinite_File_Store is

pragma Elaborate_Body;

type Item_Access is access all Item;

procedure To_File (This : in Item; File : in String);
-- This uses Item'Output
-- Write a file with the dumped item. Overwrites if existing.

function Load (File : in String) return Item;
-- This uses Item'Input

end Agpl.Generic_Indefinite_File_Store;

0 comments on commit f8c2485

Please sign in to comment.