18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

286 Persistence<br />

Canada, Belgium, USA, Germany, Norway.<br />

When added to a b<strong>in</strong>ary tree, this would recreate the tree structure present <strong>in</strong> the orig<strong>in</strong>al object.<br />

procedure F<strong>in</strong>alize( The:<strong>in</strong> out Pic ) is<br />

Per : Io.File_Type; --File descriptor<br />

procedure Rec_F<strong>in</strong>alize( The:<strong>in</strong> Subtree ) is --Save state<br />

beg<strong>in</strong><br />

if The /= null then --Subtree save as<br />

Io.Write( Per, The.Rec ); -- Item<br />

Rec_F<strong>in</strong>alize( The.Left ); -- LHS<br />

Rec_F<strong>in</strong>alize( The.Right ); -- RHS<br />

end if;<br />

end Rec_F<strong>in</strong>alize;<br />

beg<strong>in</strong><br />

if To_Str<strong>in</strong>g(The.Obj_Id) /= "" then --If save state<br />

Io.Create( Per, Io.Out_File,<br />

To_Str<strong>in</strong>g( The.Obj_Id ) );<br />

Rec_F<strong>in</strong>alize( The.Tree );<br />

Io.Close( Per );<br />

end if;<br />

Release_Storage( The.Tree );<br />

exception<br />

--Return real exception<br />

when others => raise Per_Error; -- as sub code<br />

end F<strong>in</strong>alize;<br />

The procedure Discard disassociates the object identity from the object and resets the state of the tree to<br />

empty. This procedure should be used when the object’s state is not required to be saved to disk.<br />

procedure Discard eg<strong>in</strong><br />

Set_Name( The, "" );<br />

Release_Storage( The.Tree );<br />

end Discard;<br />

--No name<br />

--Release storage<br />

procedure Set_Name( The:<strong>in</strong> out Pic; Id:<strong>in</strong> Str<strong>in</strong>g ) is<br />

beg<strong>in</strong><br />

The.Obj_Id := To_Unbounded_Str<strong>in</strong>g(Id); --Set object name<br />

end Set_Name;<br />

function Get_Name( The:<strong>in</strong> Pic ) return Str<strong>in</strong>g is<br />

beg<strong>in</strong><br />

return To_Str<strong>in</strong>g( The.Obj_Id ); --Name of object<br />

end Get_Name;<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!