API Documentation
Loading...
Searching...
No Matches
CheckSumGenerator.h
Go to the documentation of this file.
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{
37 /**----------------------------------------------------------------------------
38 \brief Logic for generating checksums based on initial value and a type.
39 ----------------------------------------------------------------------------*/
40 template<class t_hash_type>
42 {
43 public:
45 : type_buffer(0)
46 , m_checksum(5381)
47 {};
48 template <class t_type, class t_allocator, class t_memory_manager>
50 {
51 if (buffer.size() == 0)
52 {
53 m_checksum = ((m_checksum << 5) + m_checksum) + 5381;
54 }
55 for (uint04 ii = 0; ii < buffer.size(); ii++)
56 {
57 update<t_type>(buffer[ii]);
58 }
59 }
60 template <class t_type, class t_allocator, class t_memory_manager>
62 {
63 const uint04 size = getMin(max_size, buffer.size());
64 for (uint04 ii = 0; ii < size; ii++)
65 {
66 update<t_type>(buffer[ii]);
67 }
68 }
69 template<class t_type>
70 void update(const t_type& object)
71 {
72 if (sizeof(t_type) == sizeof(t_hash_type))
73 {
74 memcpy(&type_buffer, &object, sizeof(t_type));
75 }
76 else if ((sizeof(t_type) > sizeof(t_hash_type)))
77 {
78 static const uint04 remainder = sizeof(t_type) % sizeof(t_hash_type);
79 static const uint04 num_to_copy = sizeof(t_type) / sizeof(t_hash_type);
80 for (uint04 ii = 0; ii < num_to_copy; ii++)
81 {
82 memcpy(&type_buffer, ((uint01*)(&object)) + sizeof(t_hash_type) * ii, sizeof(t_hash_type));
84 }
85 if (remainder != 0)
86 {
87 memcpy(&type_buffer, ((uint01*)(&object)) + sizeof(t_hash_type) * num_to_copy, sizeof(remainder));
89 }
90 }
91 else
92 {
93 memcpy(&type_buffer, &object, sizeof(t_type));
95 }
96 }
97 template<>
98 void update(const t_hash_type& hash_value)
99 {
100 m_checksum = ((m_checksum << 5) + m_checksum) + hash_value;
101 }
102 t_hash_type getCheckSum() { return m_checksum; }
103 t_hash_type type_buffer;
104 t_hash_type m_checksum;
105 };
106}
107
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:59
constexpr t_index_type size() const
Definition Buffer.hpp:1374
Logic for generating checksums based on initial value and a type.
Definition CheckSumGenerator.h:42
void update(const Buffer< t_type, t_allocator, t_memory_manager > &buffer)
Definition CheckSumGenerator.h:49
t_hash_type m_checksum
Definition CheckSumGenerator.h:104
void update(const t_type &object)
Definition CheckSumGenerator.h:70
t_hash_type type_buffer
Definition CheckSumGenerator.h:103
void update(const Buffer< t_type, t_allocator, t_memory_manager > &buffer, uint04 max_size)
Definition CheckSumGenerator.h:61
CheckSumGenerator()
Definition CheckSumGenerator.h:44
void update(const t_hash_type &hash_value)
Definition CheckSumGenerator.h:98
t_hash_type getCheckSum()
Definition CheckSumGenerator.h:102
Definition ACIColor.h:37
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:78
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:94
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...
Definition BaseFunctions.hpp:56