Checksum.h Source File

Back to the index.

Checksum.h
Go to the documentation of this file.
1 #ifndef CHECKSUM_H
2 #define CHECKSUM_H
3 
4 /*
5  * Copyright (C) 2007-2010 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include "misc.h"
32 
33 #include "UnitTest.h"
34 
35 
36 /**
37  * \brief A checksum accumulator.
38  *
39  * The main purpose of this class is as a helper in unit tests, where
40  * objects such as trees are hard to compare to each other. A checksum
41  * of the first tree can then be compared with a checksum of the second
42  * tree.
43  *
44  * Note: This is not scientifically correct in any way. It is just something
45  * I made up, for unit testing purposes. (2007-12-27)
46  */
47 class Checksum
48  : public UnitTestable
49 {
50 public:
51  /**
52  * \brief Constructs a zeroed checksum.
53  */
54  Checksum();
55 
56  /**
57  * \brief Retrieves the value of the checksum, as a uint64_t.
58  *
59  * @return the checksum value
60  */
61  uint64_t Value() const;
62 
63  /**
64  * \brief Add a uint64_t to the checksum.
65  *
66  * @param x Value to add.
67  */
68  void Add(uint64_t x);
69 
70  /**
71  * \brief Add a string to the checksum.
72  *
73  * @param str The string to add.
74  */
75  void Add(const string& str);
76 
77  /**
78  * \brief Compares one %Checksum to another for equality.
79  *
80  * @param other The %Checksum to compare to.
81  * @return true if the checksums match, false otherwise.
82  */
83  bool operator == (const Checksum& other) const;
84 
85  /**
86  * \brief Compares one %Checksum to another for inequality.
87  *
88  * @param other The %Checksum to compare to.
89  * @return false if the checksums match, true otherwise.
90  */
91  bool operator != (const Checksum& other) const;
92 
93 
94  /********************************************************************/
95 
96  static void RunUnitTests(int& nSucceeded, int& nFailures);
97 
98 private:
99  uint64_t m_value;
100 };
101 
102 
103 #endif // CHECKSUM_H
uint64_t Value() const
Retrieves the value of the checksum, as a uint64_t.
Definition: Checksum.cc:37
A checksum accumulator.
Definition: Checksum.h:47
void Add(uint64_t x)
Add a uint64_t to the checksum.
Definition: Checksum.cc:43
bool operator!=(const Checksum &other) const
Compares one Checksum to another for inequality.
Definition: Checksum.cc:66
bool operator==(const Checksum &other) const
Compares one Checksum to another for equality.
Definition: Checksum.cc:60
Checksum()
Constructs a zeroed checksum.
Definition: Checksum.cc:31
static void RunUnitTests(int &nSucceeded, int &nFailures)
Base class for unit testable classes.
Definition: UnitTest.h:74

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13