Files
bsnes/nall/hash/hash.hpp
Tim Allen 559a6585ef Update to v106r81 release.
byuu says:

First 32 instructions implemented in the TLCS900H disassembler. Only 992
to go!

I removed the use of anonymous namespaces in nall. It was something I
rarely used, because it rarely did what I wanted.

I updated all nested namespaces to use C++17-style namespace Foo::Bar {}
syntax instead of classic C++-style namespace Foo { namespace Bar {}}.

I updated ruby::Video::acquire() to return a struct, so we can use C++17
structured bindings. Long term, I want to get away from all functions
that take references for output only. Even though C++ botched structured
bindings by not allowing you to bind to existing variables, it's even
worse to have function calls that take arguments by reference and then
write to them. From the caller side, you can't tell the value is being
written, nor that the value passed in doesn't matter, which is terrible.
2019-01-16 13:02:24 +11:00

48 lines
1.2 KiB
C++

#pragma once
#include <nall/arithmetic.hpp>
#include <nall/range.hpp>
#include <nall/string.hpp>
//cannot use constructor inheritance due to needing to call virtual reset();
//instead, define a macro to reduce boilerplate code in every Hash subclass
#define nallHash(Name) \
Name() { reset(); } \
Name(const void* data, uint64_t size) : Name() { input(data, size); } \
Name(const vector<uint8_t>& data) : Name() { input(data); } \
Name(const string& data) : Name() { input(data); } \
using Hash::input; \
namespace nall::Hash {
struct Hash {
virtual auto reset() -> void = 0;
virtual auto input(uint8_t data) -> void = 0;
virtual auto output() const -> vector<uint8_t> = 0;
auto input(array_view<uint8_t> data) -> void {
for(auto byte : data) input(byte);
}
auto input(const void* data, uint64_t size) -> void {
auto p = (const uint8_t*)data;
while(size--) input(*p++);
}
auto input(const vector<uint8_t>& data) -> void {
for(auto byte : data) input(byte);
}
auto input(const string& data) -> void {
for(auto byte : data) input(byte);
}
auto digest() const -> string {
string result;
for(auto n : output()) result.append(hex(n, 2L));
return result;
}
};
}