Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
CRC.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32/*Code references:
33 http://www.cplusplus.com/forum/lounge/27570/
34*/
35
36
37#pragma once
38#ifndef UTIL_CRC_H_
39#define UTIL_CRC_H_
40
41namespace Divide {
42namespace Util {
43 class CRC32 final
44 {
45 public:
46 CRC32() = default;
47 explicit CRC32(const void* buf, const size_t size)
48 {
49 Hash(buf, size);
50 }
51
52 //=========================================
54 operator U32() const noexcept { return Get(); }
55
56 //=========================================
58 [[nodiscard]] U32 Get() const noexcept { return ~mCrc; }
59
60 //=========================================
61 // HashBase stuff
62 void Reset() noexcept { mCrc = to_U32(~0); }
63 void Hash(const void* buf, size_t siz) noexcept;
64
65 private:
66 U32 mCrc = to_U32(~0u);
67 static U32 mTable[0x100];
68
69 //=========================================
70 // internal support
71 static U32 Reflect(U32 v, I32 bits) noexcept;
72};
73} // namespace Util
74} // namespace Divide
75
76#endif
void Reset() noexcept
Definition: CRC.h:62
static U32 mTable[0x100]
Definition: CRC.h:67
static U32 Reflect(U32 v, I32 bits) noexcept
Definition: CRC.cpp:54
U32 Get() const noexcept
getting the crc
Definition: CRC.h:58
void Hash(const void *buf, size_t siz) noexcept
Definition: CRC.cpp:66
CRC32(const void *buf, const size_t size)
Definition: CRC.h:47
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
constexpr U32 to_U32(const T value)
int32_t I32
uint32_t U32