I am creating the following task in Ada and I want it to contain a procedure that tells me the count of my buffer. How can I do that?
package body Buffer is
task body Buffer is
size: constant := 10000; -- buffer capacity
buf: array(1.. size) of Types.Item;
count: integer range 0..size := 0;
in_index,out_index:integer range 1..size := 1;
begin
procedure getCount(currentCount: out Integer) is
begin
currentCount := count;
end getCount;
loop
select
when count<size =>
accept put(item: in Types.Item) do
buf(in_index) := item;
end put;
in_index := in_index mod size+1;
count := count + 1;
or
when count>0 =>
accept get(item:out Types.Item) do
item := buf(out_index);
end get;
out_index := out_index mod size+1;
count := count - 1;
or
terminate;
end select;
end loop;
end Buffer;
end Buffer;
When I compile this code I get an error that
declarations must come before "begin"
referring to the definition of the getCount procedure.