Debian Codegraph @

src/C++/Quiver/QuiverConfig.cpp

raw
1 // Author: David Alexander
2
3 #include <ConsensusCore/Quiver/QuiverConfig.hpp>
4
5 #include <stdexcept>
6 #include <string>
7 #include <vector>
8
9 #include <boost/algorithm/string.hpp>
10
11 namespace ConsensusCore {
12 QuiverConfig::QuiverConfig(const QvModelParams& qvParams, int movesAvailable,
13 const BandingOptions& bandingOptions, float fastScoreThreshold,
14 float addThreshold)
15 : QvParams(qvParams)
16 , MovesAvailable(movesAvailable)
17 , Banding(bandingOptions)
18 , FastScoreThreshold(fastScoreThreshold)
19 , AddThreshold(addThreshold)
20 {
21 }
22
23 QuiverConfig::QuiverConfig(const QuiverConfig& qvConfig)
24 : QvParams(qvConfig.QvParams)
25 , MovesAvailable(qvConfig.MovesAvailable)
26 , Banding(qvConfig.Banding)
27 , FastScoreThreshold(qvConfig.FastScoreThreshold)
28 , AddThreshold(qvConfig.AddThreshold)
29 {
30 }
31
32 QuiverConfigTable::QuiverConfigTable() {}
33
34 bool QuiverConfigTable::InsertAs_(const std::string& name, const QuiverConfig& config)
35 {
36 const_iterator it;
37
38 for (it = table.begin(); it != table.end(); it++)
39 if (name.compare(it->first) == 0) return false;
40
41 table.push_front(std::make_pair(name, config));
42
43 return true;
44 }
45
46 #define FALLBACK "*"
47
48 bool QuiverConfigTable::InsertAs(const std::string& name, const QuiverConfig& config)
49 {
50 if (name.compare(FALLBACK) == 0)
51 throw InvalidInputError("Cannot Insert(...) a QuiverConfig with chemistry '" FALLBACK "'");
52 return InsertAs_(name, config);
53 }
54
55 bool QuiverConfigTable::Insert(const QuiverConfig& config)
56 {
57 const std::string& name = config.QvParams.ChemistryName;
58 return InsertAs(name, config);
59 }
60
61 bool QuiverConfigTable::InsertDefault(const QuiverConfig& config)
62 {
63 return InsertAs_(FALLBACK, config);
64 }
65
66 int QuiverConfigTable::Size() const { return table.size(); }
67
68 const QuiverConfig& QuiverConfigTable::At(const std::string& name) const
69 {
70 const_iterator it;
71
72 // If we find a direct match for the chemistry, use it
73 for (it = table.begin(); it != table.end(); it++)
74 if (it->first.compare(name) == 0) return it->second;
75
76 // Fallback
77 for (it = table.begin(); it != table.end(); it++)
78 if (it->first.compare(FALLBACK) == 0) return it->second;
79
80 throw InvalidInputError("Chemistry not found in QuiverConfigTable");
81 }
82
83 std::vector<std::string> QuiverConfigTable::Keys() const
84 {
85 std::vector<std::string> keys;
86 for (const_iterator it = table.begin(); it != table.end(); it++) {
87 keys.push_back(it->first);
88 }
89 return keys;
90 }
91
92 QuiverConfigTable::const_iterator QuiverConfigTable::begin() const { return table.begin(); }
93
94 QuiverConfigTable::const_iterator QuiverConfigTable::end() const { return table.end(); }
95 }