xrpld
Loading...
Searching...
No Matches
SHAMapAddNode.h
1#pragma once
2
3#include <string>
4
5namespace xrpl {
6
7// results of adding nodes
9{
10private:
11 int good_;
12 int bad_;
14
15public:
17
21 void
22 incInvalid();
23
27 void
28 incUseful();
29
35 void
37
41 [[nodiscard]] int
42 getGood() const;
43
49 [[nodiscard]] int
50 getBad() const;
51
57 [[nodiscard]] int
58 getDuplicate() const;
59
66 [[nodiscard]] bool
67 isGood() const;
68
72 [[nodiscard]] bool
73 isInvalid() const;
74
78 [[nodiscard]] bool
79 isUseful() const;
80
84 static SHAMapAddNode
85 duplicate();
86
90 static SHAMapAddNode
91 useful();
92
96 static SHAMapAddNode
97 invalid();
98
102 void
103 reset();
104
111 [[nodiscard]] std::string
112 get() const;
113
121 operator+=(SHAMapAddNode const& n);
122
123private:
124 SHAMapAddNode(int good, int bad, int duplicate);
125};
126
128{
129}
130
131inline SHAMapAddNode::SHAMapAddNode(int good, int bad, int duplicate)
132 : good_(good), bad_(bad), duplicate_(duplicate)
133{
134}
135
136inline void
141
142inline void
147
148inline void
153
154inline int
156{
157 return good_;
158}
159
160inline int
162{
163 return bad_;
164}
165
166inline int
168{
169 return duplicate_;
170}
171
172inline bool
174{
175 return (good_ + duplicate_) > bad_;
176}
177
178inline bool
180{
181 return bad_ > 0;
182}
183
184inline bool
186{
187 return good_ > 0;
188}
189
190inline SHAMapAddNode
192{
193 return SHAMapAddNode(0, 0, 1);
194}
195
196inline SHAMapAddNode
198{
199 return SHAMapAddNode(1, 0, 0);
200}
201
202inline SHAMapAddNode
204{
205 return SHAMapAddNode(0, 1, 0);
206}
207
208inline void
210{
211 good_ = bad_ = duplicate_ = 0;
212}
213
214inline std::string
216{
217 std::string ret;
218 if (good_ > 0)
219 {
220 ret.append("good:");
222 }
223 if (bad_ > 0)
224 {
225 if (!ret.empty())
226 ret.append(" ");
227 ret.append("bad:");
229 }
230 if (duplicate_ > 0)
231 {
232 if (!ret.empty())
233 ret.append(" ");
234 ret.append("dupe:");
236 }
237 if (ret.empty())
238 ret = "no nodes processed";
239 return ret;
240}
241
242inline SHAMapAddNode&
244{
245 good_ += n.good_;
246 bad_ += n.bad_;
248
249 return *this;
250}
251
252} // namespace xrpl
T append(T... args)
void incDuplicate()
Record one node that was not needed: the map already held it, or the map or its acquisition was no lo...
SHAMapAddNode & operator+=(SHAMapAddNode const &n)
Add another verdict's counts into this one.
void reset()
Clear every count back to zero.
int getDuplicate() const
void incUseful()
Record one node that produced a good result.
static SHAMapAddNode duplicate()
static SHAMapAddNode useful()
bool isInvalid() const
bool isGood() const
Whether nodes that produced a good result or were not needed outnumber the ones rejected.
std::string get() const
Render the tally as a log line.
void incInvalid()
Record one node that was rejected.
static SHAMapAddNode invalid()
bool isUseful() const
T empty(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
T to_string(T... args)