diff options
Diffstat (limited to 'src/candidates.ads')
-rw-r--r-- | src/candidates.ads | 136 |
1 files changed, 107 insertions, 29 deletions
diff --git a/src/candidates.ads b/src/candidates.ads index 90b2425..fb04a4e 100644 --- a/src/candidates.ads +++ b/src/candidates.ads @@ -1,73 +1,151 @@ -with Ada.Containers.Vectors; +private with Ada.Strings.Unbounded; +private with Ada.Containers.Vectors; package Candidates is type Candidate is private; - type CandidateID is Natural; + type CandidateID is new Positive; + + + function To_String + (Input_Candidate : in Candidate; + Delimiter : in Character := ',') + return String; + + + + + type Candidate_Vector is private; + type CandidateID_Vector is private; + + + procedure Read_Candidates + (Filename, State : in String; + Candidate_List : out Candidate_Vector); + + + function First + (Candidate_List : in Candidate_Vector) + return CandidateID; + + + function Last + (Candidate_List : in Candidate_Vector) + return CandidateID; + + + function Lookup + (Candidate_List : in Candidate_Vector; + Index : in CandidateID) + return Candidate; + + + function First + (CandidateID_List : in CandidateID_Vector) + return Positive; + + + function Last + (CandidateID_List : in CandidateID_Vector) + return Positive; + + + function Lookup + (CandidateID_List : in CandidateID_Vector; + Index : in Positive) + return CandidateID; + + type Above_Line_Ballot is private; type Below_Line_Ballot is private; - package Candidate_Vectors is new Ada.Containers.Vectors - (Index_Type => CandidateID, - Element_Type => Candidate); + procedure Generate_Ballots + (Candidate_List : in Candidate_Vector; + Above_Ballot : out Above_Line_Ballot; + Below_Ballot : out Below_Line_Ballot); - package CandidateID_Vectors is new Ada.Containers.Vectors - (Index_Type => Natural, - Element_Type => CandidateID); + function First + (Above_Ballot : in Above_Line_Ballot) + return Positive; - procedure Read_Candidates - (Data_File, State : in String; - Above_Ballot : out Above_Line_Ballot; - Below_Ballot : out Below_Line_Ballot; - Candidate_List : out Candidate_Vectors.Vector); + function Last + (Above_Ballot : in Above_Line_Ballot) + return Positive; function Lookup (Above_Ballot : in Above_Line_Ballot; - Index : in Natural) - return CandidateID_Vectors.Vector; + Index : in Positive) + return CandidateID_Vector; + + + function First + (Below_Ballot : in Below_Line_Ballot) + return Positive; + + + function Last + (Below_Ballot : in Below_Line_Ballot) + return Positive; function Lookup (Below_Ballot : in Below_Line_Ballot; - Index : in Natural) + Index : in Positive) return CandidateID; private + package SU renames Ada.Strings.Unbounded; + + type Candidate is record - ID : CandidateID; - First_Name : String; - Last_Name : String; - Group : String; - Group_Rank : Natural; - Party : String; + First_Name : SU.Unbounded_String; + Last_Name : SU.Unbounded_String; + Group : SU.Unbounded_String; + Group_Rank : SU.Unbounded_String; + Party : SU.Unbounded_String; end record; - package Above_Line_Ballots is new Ada.Containers.Vectors - (Index_Type => Natural, - Element_Type => CandidateID_Vectors.Vector); + package Candidate_Vectors is new Ada.Containers.Vectors + (Index_Type => CandidateID, + Element_Type => Candidate); + type Candidate_Vector is record + Vec : Candidate_Vectors.Vector; + end record; - package Below_Line_Ballots is new Ada.Containers.Vectors - (Index_Type => Natural, + package CandidateID_Vectors is new Ada.Containers.Vectors + (Index_Type => Positive, Element_Type => CandidateID); + type CandidateID_Vector is record + Vec : CandidateID_Vectors.Vector; + end record; + + + package Above_Line_Ballots is new Ada.Containers.Vectors + (Index_Type => Positive, + Element_Type => CandidateID_Vector); + type Above_Line_Ballot is record + Vec : Above_Line_Ballots.Vector; + end record; - type Above_Line_Ballot is Above_Line_Ballots.Vector; - type Below_Line_Ballot is Below_Line_Ballots.Vector; + type Below_Line_Ballot is record + Vec : CandidateID_Vectors.Vector; + end record; end Candidates; |