NDEVR
API Documentation
CheckSumGenerator.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: CheckSumGenerator
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Buffer.h>
34
35namespace NDEVR
36{
42 template<class t_hash_type>
44 {
45 public:
50 : type_buffer(0)
51 , m_checksum(5381)
52 {};
53
57 template <class t_type, class t_allocator, class t_memory_manager>
59 {
60 if (buffer.size() == 0)
61 {
62 m_checksum = ((m_checksum << 5) + m_checksum) + 5381;
63 }
64 for (uint04 ii = 0; ii < buffer.size(); ii++)
65 {
66 update<t_type>(buffer[ii]);
67 }
68 }
69
74 template <class t_type, class t_allocator, class t_memory_manager>
76 {
77 const uint04 size = getMin(max_size, buffer.size());
78 for (uint04 ii = 0; ii < size; ii++)
79 {
80 update<t_type>(buffer[ii]);
81 }
82 }
83
87 template<class t_type>
88 void update(const t_type& object)
89 {
90 if (sizeof(t_type) == sizeof(t_hash_type))
91 {
92 memcpy(&type_buffer, &object, sizeof(t_type));
93 }
94 else if ((sizeof(t_type) > sizeof(t_hash_type)))
95 {
96 static const uint04 remainder = sizeof(t_type) % sizeof(t_hash_type);
97 static const uint04 num_to_copy = sizeof(t_type) / sizeof(t_hash_type);
98 for (uint04 ii = 0; ii < num_to_copy; ii++)
99 {
100 memcpy(&type_buffer, ((uint01*)(&object)) + sizeof(t_hash_type) * ii, sizeof(t_hash_type));
102 }
103 if (remainder != 0)
104 {
105 memcpy(&type_buffer, ((uint01*)(&object)) + sizeof(t_hash_type) * num_to_copy, sizeof(remainder));
107 }
108 }
109 else
110 {
111 memcpy(&type_buffer, &object, sizeof(t_type));
113 }
114 }
115
119 template<>
120 void update(const t_hash_type& hash_value)
121 {
122 m_checksum = ((m_checksum << 5) + m_checksum) + hash_value;
123 }
124
128 t_hash_type getCheckSum() { return m_checksum; }
129 t_hash_type type_buffer;
130 t_hash_type m_checksum;
131 };
132}
133
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void update(const Buffer< t_type, t_allocator, t_memory_manager > &buffer)
Updates the checksum by processing all elements in the given buffer.
void update(const t_hash_type &hash_value)
Specialization that directly incorporates a hash-type value into the checksum.
t_hash_type getCheckSum()
Returns the current computed checksum value.
void update(const Buffer< t_type, t_allocator, t_memory_manager > &buffer, uint04 max_size)
Updates the checksum by processing elements in the buffer up to a maximum count.
void update(const t_type &object)
Updates the checksum with a single object by splitting it into hash-type-sized chunks.
t_hash_type type_buffer
Temporary buffer used for copying object data during checksum computation.
CheckSumGenerator()
Constructs a CheckSumGenerator with default initial values.
t_hash_type m_checksum
The running checksum value accumulated from all processed data.
The primary namespace for the NDEVR SDK.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...