cxacb02.a
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· A 代码 · 共 422 行 · 第 1/2 页
A
422 行
procedure Service_Output ( Stream : access Ada.Streams.Root_Stream_Type'Class; Item : Service_Type ) is begin TC_Output_Total := TC_Output_Total + 2; -- Write the discriminant value to the stream. -- The attribute 'Write (for the record type) will not write the -- discriminant of the record object to the stream. Therefore, it -- must be explicitly written using the 'Write attribute of the -- discriminant type. Customer_Type'Write (Stream, Item.Customer); -- Write the record component values (but not the discriminant) to -- the stream. Service_Type'Write (Stream, Item); end Service_Output; function History_Input ( Stream : access Ada.Streams.Root_Stream_Type'Class ) return Service_History_Type is Quarter_Bound_Low : Quarterly_Period_Type; Quarter_Bound_High : Quarterly_Period_Type; Month_Bound_Low : Month_In_Quarter_Type; Month_Bound_High : Month_In_Quarter_Type; begin TC_Input_Total := TC_Input_Total + 3; -- Read the value of the array bounds from the stream. -- Use these bounds in the creation of an array object that will -- be used to store data from the stream. -- The array bound values would not otherwise be read from the -- stream by use of the Service_History_Type'Read attribute. Quarterly_Period_Type'Read (Stream, Quarter_Bound_Low); Quarterly_Period_Type'Read (Stream, Quarter_Bound_High); Month_In_Quarter_Type'Read (Stream, Month_Bound_Low); Month_In_Quarter_Type'Read (Stream, Month_Bound_High); declare Service_History_Array : Service_History_Type (Quarterly_Period_Type range Quarter_Bound_Low..Quarter_Bound_High, Month_In_Quarter_Type range Month_Bound_Low .. Month_Bound_High); begin Service_History_Type'Read (Stream, Service_History_Array); return Service_History_Array; end; end History_Input; procedure History_Output ( Stream : access Ada.Streams.Root_Stream_Type'Class; Item : Service_History_Type ) is begin TC_Output_Total := TC_Output_Total + 7; -- Write the upper/lower bounds of the array object dimensions to -- the stream. Quarterly_Period_Type'Write (Stream, Item'First(1)); Quarterly_Period_Type'Write (Stream, Item'Last(1)); Month_In_Quarter_Type'Write (Stream, Item'First(2)); Month_In_Quarter_Type'Write (Stream, Item'Last(2)); -- Write the array values to the stream in canonical order (last -- dimension varying fastest). Service_History_Type'Write (Stream, Item); end History_Output; begin Util_Stream := Ada.Streams.Stream_IO.Stream (Util_File); -- Write data to the stream. A customer service record is followed -- by a service history array. Service_Type'Output (Util_Stream, Customer1); Service_History_Type'Output (Util_Stream, C1_Service_History); Service_Type'Output (Util_Stream, Customer2); Service_History_Type'Output (Util_Stream, C2_Service_History); Service_Type'Output (Util_Stream, Customer3); Service_History_Type'Output (Util_Stream, C3_Service_History); -- Read data from the stream, and verify the use of the user specified -- attributes. Verify_Data_Block: declare TC_Residence : Service_Type (Residence); TC_Apartment : Service_Type (Apartment); TC_Commercial : Service_Type (Commercial); TC_History1 : Service_History_Type (Quarterly_Period_Type, Month_In_Quarter_Type) := (others => (others => Electric_Usage_Type'First)); TC_History2 : Service_History_Type (Quarterly_Period_Type range Spring .. Summer, Month_In_Quarter_Type) := (others => (others => Electric_Usage_Type'First)); TC_History3 : Service_History_Type (Quarterly_Period_Type, Month_In_Quarter_Type) := (others => (others => Electric_Usage_Type'First)); begin -- Reset Stream file to mode In_File. Ada.Streams.Stream_IO.Reset (Util_File, Ada.Streams.Stream_IO.In_File); -- Read data from the stream. TC_Residence := Service_Type'Input (Util_Stream); TC_History1 := Service_History_Type'Input (Util_Stream); TC_Apartment := Service_Type'Input (Util_Stream); TC_History2 := Service_History_Type'Input (Util_Stream); TC_Commercial := Service_Type'Input (Util_Stream); TC_History3 := Service_History_Type'Input (Util_Stream); -- Verify product data was correctly written to/read from stream, -- including discriminants and array bounds. if (TC_Residence /= Customer1) or (TC_Residence.Customer /= Customer1.Customer) or (TC_History1'Last(1) /= C1_Service_History'Last(1)) or (TC_History1'First(1) /= C1_Service_History'First(1)) or (TC_History1'Last(2) /= C1_Service_History'Last(2)) or (TC_History1'First(2) /= C1_Service_History'First(2)) then Report.Failed ("Incorrect data from stream - 1"); end if; if (TC_Apartment /= Customer2) or (TC_Apartment.Customer /= Customer2.Customer) or (TC_History2 /= C2_Service_History) or (TC_History2'Last(1) /= C2_Service_History'Last(1)) or (TC_History2'First(1) /= C2_Service_History'First(1)) or (TC_History2'Last(2) /= C2_Service_History'Last(2)) or (TC_History2'First(2) /= C2_Service_History'First(2)) then Report.Failed ("Incorrect data from stream - 2"); end if; if (TC_Commercial /= Customer3) or (TC_Commercial.Customer /= Customer3.Customer) or (TC_History3 /= C3_Service_History) or (TC_History3'Last(1) /= C3_Service_History'Last(1)) or (TC_History3'First(1) /= C3_Service_History'First(1)) or (TC_History3'Last(2) /= C3_Service_History'Last(2)) or (TC_History3'First(2) /= C3_Service_History'First(2)) then Report.Failed ("Incorrect data from stream - 3"); end if; -- Verify that the user defined subprograms were used to override -- the default 'Input and 'Output attributes. -- There were three calls on each of the user defined attributes. if (TC_Input_Total /= 12 ) or (TC_Output_Total /= 27 ) then Report.Failed ("Incorrect use of user defined attributes"); end if; end Verify_Data_Block; exception when others => Report.Failed ("Exception raised in Operational Test Block"); end Operational_Test_Block; if Ada.Streams.Stream_IO.Is_Open (Util_File) then Ada.Streams.Stream_IO.Delete (Util_File); else Ada.Streams.Stream_IO.Open (Util_File, Ada.Streams.Stream_IO.Out_File, Utility_Filename); Ada.Streams.Stream_IO.Delete (Util_File); end if; exception -- Since Use_Error or Name_Error can be raised if, for the specified -- mode, the environment does not support Stream_IO operations, -- the following handlers are included: when Ada.Streams.Stream_IO.Name_Error => Report.Not_Applicable ("Name_Error raised on Stream IO Create"); when Ada.Streams.Stream_IO.Use_Error => Report.Not_Applicable ("Use_Error raised on Stream IO Create"); when others => Report.Failed ("Unexpected exception raised"); end Test_for_Stream_IO_Support; Report.Result;end CXACB02;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?