cxa9002.a
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· A 代码 · 共 483 行 · 第 1/2 页
A
483 行
Sav_File : Sav_DIO.File_Type; begin Acct_DIO.Create (Acct_File, Acct_DIO.Out_File, Acct_Filename); Cash_DIO.Create (Cash_File, Cash_DIO.Out_File, Cash_Filename); Inv_DIO.Create (Inv_File, Inv_DIO.Out_File, Inv_Filename); Chk_DIO.Create (Chk_File, Chk_DIO.Out_File, Chk_Filename); Sav_DIO.Create (Sav_File, Sav_DIO.Out_File, Sav_Filename); -- Store the tag values of the objects declared above for -- comparison with tag values of objects following processing. TC_Account_Type_Tag := new String'(Ada.Tags.External_Tag(Account_Type'Tag)); TC_Cash_Account_Type_Tag := new String'(Ada.Tags.External_Tag(Cash_Account_Type'Tag)); TC_Investment_Account_Type_Tag := new String'(Ada.Tags.External_Tag(Investment_Account_Type'Tag)); TC_Checking_Account_Type_Tag := new String'(Ada.Tags.External_Tag(Checking_Account_Type'Tag)); TC_Savings_Account_Type_Tag := new String'(Ada.Tags.External_Tag(Savings_Account_Type'Tag)); -- Prepare tagged data for writing to the Direct_IO files using -- Storage_IO procedure to place data in buffers. Acct_SIO.Write (Buffer => Acct_Buffer, Item => Account); Cash_SIO.Write (Cash_Buffer, Cash_Account); Inv_SIO.Write (Inv_Buffer, Item => Investment_Account); Chk_SIO.Write (Buffer => Chk_Buffer, Item => Checking_Account); Sav_SIO.Write (Sav_Buffer, Savings_Account); -- At this point, the data and associated tag values have been -- buffered by the Storage_IO procedure, and the buffered data -- can be written to the appropriate Direct_IO file. Acct_DIO.Write (File => Acct_File, Item => Acct_Buffer); Cash_DIO.Write (Cash_File, Cash_Buffer); Inv_DIO.Write (Inv_File, Item => Inv_Buffer); Chk_DIO.Write (File => Chk_File, Item =>Chk_Buffer); Sav_DIO.Write (Sav_File, Sav_Buffer); -- Close all Direct_IO files. Acct_DIO.Close (Acct_File); Cash_DIO.Close (Cash_File); Inv_DIO.Close (Inv_File); Chk_DIO.Close (Chk_File); Sav_DIO.Close (Sav_File); exception when others => Report.Failed("Exception raised in Buffer_Data"); end Buffer_Data; procedure Read_Data is Account : Account_Type; Cash_Account : Cash_Account_Type; Investment_Account : Investment_Account_Type; Checking_Account : Checking_Account_Type; Savings_Account : Savings_Account_Type; -- Storage_IO is instantiated for each of the specific tagged -- type. package Acct_SIO is new Ada.Storage_IO (Account_Type); package Cash_SIO is new Ada.Storage_IO (Cash_Account_Type); package Inv_SIO is new Ada.Storage_IO (Investment_Account_Type); package Chk_SIO is new Ada.Storage_IO (Checking_Account_Type); package Sav_SIO is new Ada.Storage_IO (Savings_Account_Type); -- Direct_IO is instantiated for the buffer types defined in the -- instantiated Storage_IO packages. package Acct_DIO is new Ada.Direct_IO (Acct_SIO.Buffer_Type); package Cash_DIO is new Ada.Direct_IO (Cash_SIO.Buffer_Type); package Inv_DIO is new Ada.Direct_IO (Inv_SIO.Buffer_Type); package Chk_DIO is new Ada.Direct_IO (Chk_SIO.Buffer_Type); package Sav_DIO is new Ada.Direct_IO (Sav_SIO.Buffer_Type); Acct_Buffer : Acct_SIO.Buffer_Type; Cash_Buffer : Cash_SIO.Buffer_Type; Inv_Buffer : Inv_SIO.Buffer_Type; Chk_Buffer : Chk_SIO.Buffer_Type; Sav_Buffer : Sav_SIO.Buffer_Type; Acct_File : Acct_DIO.File_Type; Cash_File : Cash_DIO.File_Type; Inv_File : Inv_DIO.File_Type; Chk_File : Chk_DIO.File_Type; Sav_File : Sav_DIO.File_Type; begin -- Open the Direct_IO files. Acct_DIO.Open (Acct_File, Acct_DIO.In_File, Acct_Filename); Cash_DIO.Open (Cash_File, Cash_DIO.In_File, Cash_Filename); Inv_DIO.Open (Inv_File, Inv_DIO.In_File, Inv_Filename); Chk_DIO.Open (Chk_File, Chk_DIO.In_File, Chk_Filename); Sav_DIO.Open (Sav_File, Sav_DIO.In_File, Sav_Filename); -- Read the buffer data from the files using Direct_IO. Acct_DIO.Read (File => Acct_File, Item => Acct_Buffer); Cash_DIO.Read (Cash_File, Cash_Buffer); Inv_DIO.Read (Inv_File, Item => Inv_Buffer); Chk_DIO.Read (File => Chk_File, Item =>Chk_Buffer); Sav_DIO.Read (Sav_File, Sav_Buffer); -- At this point, the data and associated tag values are stored -- in buffers. Use the Storage_IO procedure Read to recreate the -- tagged objects from the buffers. Acct_SIO.Read (Buffer => Acct_Buffer, Item => Account); Cash_SIO.Read (Cash_Buffer, Cash_Account); Inv_SIO.Read (Inv_Buffer, Item => Investment_Account); Chk_SIO.Read (Buffer => Chk_Buffer, Item => Checking_Account); Sav_SIO.Read (Sav_Buffer, Savings_Account); -- Delete all Direct_IO files. Acct_DIO.Delete (Acct_File); Cash_DIO.Delete (Cash_File); Inv_DIO.Delete (Inv_File); Chk_DIO.Delete (Chk_File); Sav_DIO.Delete (Sav_File); Data_Verification_Block: begin if Account /= TC_Account then Report.Failed("Incorrect Account object reconstructed"); end if; if Cash_Account /= TC_Cash_Account then Report.Failed ("Incorrect Cash_Account object reconstructed"); end if; if Investment_Account /= TC_Investment_Account then Report.Failed ("Incorrect Investment_Account object reconstructed"); end if; if Checking_Account /= TC_Checking_Account then Report.Failed ("Incorrect Checking_Account object reconstructed"); end if; if Savings_Account /= TC_Savings_Account then Report.Failed ("Incorrect Savings_Account object reconstructed"); end if; exception when others => Report.Failed ("Exception raised during Data_Verification Block"); end Data_Verification_Block; -- To ensure that the tags of the values reconstructed by -- Storage_IO were properly preserved, object tag values following -- object reconstruction are compared with tag values of objects -- stored prior to processing. Tag_Verification_Block: begin if TC_Account_Type_Tag.all /= Ada.Tags.External_Tag(Account_Type'Class(Account)'Tag) then Report.Failed("Incorrect Account tag"); end if; if TC_Cash_Account_Type_Tag.all /= Ada.Tags.External_Tag( Cash_Account_Type'Class(Cash_Account)'Tag) then Report.Failed("Incorrect Cash_Account tag"); end if; if TC_Investment_Account_Type_Tag.all /= Ada.Tags.External_Tag( Investment_Account_Type'Class(Investment_Account)'Tag) then Report.Failed("Incorrect Investment_Account tag"); end if; if TC_Checking_Account_Type_Tag.all /= Ada.Tags.External_Tag( Checking_Account_Type'Class(Checking_Account)'Tag) then Report.Failed("Incorrect Checking_Account tag"); end if; if TC_Savings_Account_Type_Tag.all /= Ada.Tags.External_Tag( Savings_Account_Type'Class(Savings_Account)'Tag) then Report.Failed("Incorrect Savings_Account tag"); end if; exception when others => Report.Failed ("Exception raised during tag evaluation"); end Tag_Verification_Block; exception when others => Report.Failed ("Exception in Read_Data"); end Read_Data; begin -- Test_Block -- Enter the data into the appropriate files. Buffer_Data; -- Reconstruct the data from files, and verify the results. Read_Data; exception when others => Report.Failed ("Exception raised in Test_Block"); end Test_Block; Report.Result;exception when Incomplete => Report.Result; when others => Report.Failed ( "Unexpected exception" ); Report.Result;end CXA9002;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?