STAR++ v0.2.2
C++ implementation of STAR voting
Loading...
Searching...
No Matches
election.h
1#ifndef ELECTION_H
2#define ELECTION_H
3
4// Shared Library Support
5#include "star/star_base_export.h"
6
7// Qt Includes
8#include "qdatetime.h"
9#include <QString>
10#include <QList>
11
12// Project Includes
13#include "star/rank.h"
14
15namespace Star
16{
17
18class STAR_BASE_EXPORT Election
19{
20//-Inner Classes----------------------------------------------------------------------------------------------------
21public:
22 struct Vote;
23 struct Voter;
24 class Ballot;
25 class Builder;
26
27//-Instance Variables--------------------------------------------------------------------------------------------------
28private:
29 QString mName;
30 QList<Ballot> mBallots;
31 int mSeats;
32 QMap<QString, int> mTotals;
33 QList<Rank> mScoreRankings;
34
35//-Constructor---------------------------------------------------------------------------------------------------------
36public:
37 Election();
38
39//-Instance Functions-------------------------------------------------------------------------------------------------
40public:
41 bool isValid() const;
42
43 QString name() const;
44 QStringList candidates() const;
45 const QList<Ballot>& ballots() const;
46 int seatCount() const;
47
48 int totalScore(const QString& candidate) const;
49 const QList<Rank>& scoreRankings() const;
50};
51
53{
54 QString name;
56};
57
59{
60 QString candidate;
61 int score = 0;
62};
63
64class STAR_BASE_EXPORT Election::Ballot
65{
66 friend class Election::Builder;
67//-Instance Variables--------------------------------------------------------------------------------------------------
68private:
69 Voter mVoter;
70 QHash<QString, int> mVotes;
71
72//-Constructor--------------------------------------------------------------------------------------------------------
73private:
74 Ballot();
75
76//-Instance Functions-------------------------------------------------------------------------------------------------
77public:
78 const Voter& voter() const;
79
80 int score(const QString& candidate) const;
81 QString preference(const QString& candidateA, const QString& candidateB) const;
82};
83
84class STAR_BASE_EXPORT Election::Builder
85{
86//-Instance Variables--------------------------------------------------------------------------------------------------
87private:
88 Election mConstruct;
89
90//-Constructor---------------------------------------------------------------------------------------------------------
91public:
92 Builder(const QString& name = QString());
93
94//-Instance Functions-------------------------------------------------------------------------------------------------
95public:
96 Builder& wName(const QString& name);
97 Builder& wBallot(const Voter& voter, const QList<Vote>& votes);
98 Builder& wSeatCount(int count);
99 void reset();
100 Election build();
101};
102
103}
104
105#endif // ELECTION_H
The Election::Ballot class represents a single ballot for a given election.
Definition election.h:65
The Election::Builder class is a utility through which elections can be prepared.
Definition election.h:85
The Election class represents a collection of candidates and ballots.
Definition election.h:19
The Star namespace is the main namespace through which all functionality of the STAR++ library is acc...
Definition calculator.cpp:21
The Election::Voter struct represents a single vote for a candidate in an election.
Definition election.h:59
QString candidate
Definition election.h:60
int score
Definition election.h:61
The Election::Voter struct contains the details of a voter participating in an election.
Definition election.h:53
QString name
Definition election.h:54
QString anonymousName
Definition election.h:55