Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/PluginChecksum.cpp

Issue 11013110: Cleanup (Closed)
Left Patch Set: Refactoring CallAdblockPlusEngine Created July 24, 2013, 9:09 a.m.
Right Patch Set: More beautification and addressing comments Created July 29, 2013, 12:13 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginChecksum.h ('k') | src/plugin/PluginClass.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 #include "PluginStdAfx.h"
2
3 #include "PluginChecksum.h"
4 #include "PluginClient.h"
5
6
7 CPluginChecksum::CPluginChecksum()
8 {
9 Clear();
10 }
11
12
13 CPluginChecksum::~CPluginChecksum()
14 {
15 }
16
17
18 void CPluginChecksum::Clear()
19 {
20 m_sum = 0;
21 m_r = 55665;
22 m_c1 = 52845;
23 m_c2 = 22719;
24 }
25
26
27 DWORD CPluginChecksum::Get() const
28 {
29 return m_sum;
30 }
31
32
33 CString CPluginChecksum::GetAsString() const
34 {
35 CString checksum;
36
37 checksum.Format(L"%lu", Get());
38
39 return checksum;
40 }
41
42
43 void CPluginChecksum::Add(BYTE value)
44 {
45 if (value)
46 {
47 BYTE cipher = (value ^ (m_r >> 8));
48 m_r = (cipher + m_r) * m_c1 + m_c2;
49 m_sum += cipher;
50 }
51 }
52
53
54 void CPluginChecksum::Add(const CStringA& s)
55 {
56 for (int i = 0; i < s.GetLength(); i++)
57 {
58 Add((BYTE)s.GetAt(i));
59 }
60
61 #ifdef ENABLE_DEBUG_CHECKSUM
62 CStringA sum;
63 sum.Format("%d", m_sum);
64
65 DEBUG_CHECKSUM("Checksum::AddString " + s + " sum:" + sum)
66 #endif
67 }
68
69 void CPluginChecksum::Add(const CStringW& s)
70 {
71 for (int i = 0; i < s.GetLength(); i++)
72 {
73 WORD value = (WORD)s.GetAt(i);
74
75 Add(LOBYTE(value));
76 Add(HIBYTE(value));
77 }
78
79 #ifdef ENABLE_DEBUG_CHECKSUM
80 CStringA sum;
81 sum.Format("%d", m_sum);
82
83 DEBUG_CHECKSUM("Checksum::AddString " + s + " sum:" + sum)
84 #endif
85 }
86
87 void CPluginChecksum::Add(const CStringA& s1, const CStringA& s2)
88 {
89 if (!s1.IsEmpty() && !s2.IsEmpty())
90 {
91 Add(s1);
92 Add(s2);
93 }
94 }
95
96 void CPluginChecksum::Add(const CStringW& s1, const CStringW& s2)
97 {
98 if (!s1.IsEmpty() && !s2.IsEmpty())
99 {
100 Add(s1);
101 Add(s2);
102 }
103 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld