Open 3D Engine AzCore API Reference 25.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
/home/runner/work/api.o3de.org/api.o3de.org/o3de/Code/Framework/AzCore/AzCore/Math/Crc.h

Generates a Crc32 value from a string representation. This macro is not guaranteed to be evaluated at compile time if the version with one parameter is used, so it should only be used if the parameter is not a constexpr value. If the parameter is a constexpr value, the AZ_CRC_CE macro should be used instead. The version with two parameters is deprecated, also use AZ_CRC_CE instead.

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/base.h>
#include <AzCore/std/hash.h>
#include <AzCore/std/string/string_view.h>
#include <AzCore/RTTI/TypeInfoSimple.h>
// Implementation with only 1 param (by default it should be string)
#define AZ_CRC_1(_1) AZ::Crc32(_1)
// Deprecated (use AZ_CRC_CE instead): Implementation with 2 params (only the second parameter is used)
#define AZ_CRC_2(_1, _2) AZ::Crc32(AZ::u32(_2))
#define AZ_CRC(...) AZ_MACRO_SPECIALIZE(AZ_CRC_, AZ_VA_NUM_ARGS(__VA_ARGS__), (__VA_ARGS__))
#define AZ_CRC_CE(literal_) AZ::Internal::CompileTimeCrc32<static_cast<AZ::u32>(AZ::Crc32{ literal_ })>
namespace AZ
{
class SerializeContext;
class AZCORE_API Crc32
{
public:
AZ_TYPE_INFO_WITH_NAME_DECL_API(AZCORE_API, Crc32);
constexpr Crc32()
: m_value(0) { }
explicit constexpr Crc32(AZ::u32 value) : m_value{ value } {}
explicit constexpr Crc32(AZStd::string_view view);
Crc32(const void* data, size_t size, bool forceLowerCase = false);
template<class ByteType, class = AZStd::enable_if_t<sizeof(ByteType) == 1>>
constexpr Crc32(const ByteType* data, size_t size, bool forceLowerCase = false);
explicit constexpr Crc32(AZStd::span<const AZStd::byte> inputSpan);
constexpr void Add(AZStd::string_view view);
void Add(const void* data, size_t size, bool forceLowerCase = false);
template<class ByteType>
constexpr auto Add(const ByteType* data, size_t size, bool forceLowerCase = false)
-> AZStd::enable_if_t<sizeof(ByteType) == 1>;
constexpr void Add(AZStd::span<const AZStd::byte> inputSpan);
constexpr operator u32() const { return m_value; }
constexpr u32 GetValue() const { return m_value; }
constexpr bool operator==(Crc32 rhs) const { return (m_value == rhs.m_value); }
constexpr bool operator!=(Crc32 rhs) const { return (m_value != rhs.m_value); }
constexpr bool operator!() const { return (m_value == 0); }
static void Reflect(AZ::SerializeContext& context);
protected:
// A constant expression cannot contain a conversion from const-volatile void to any pointer to object type
// nor can it contain a reinterpret_cast, therefore overloads for const char* and uint8_t are added
void Set(const void* data, size_t size, bool forceLowerCase = false);
template<class ByteType>
constexpr auto Set(const ByteType* data, size_t size, bool forceLowerCase = false)
-> AZStd::enable_if_t<sizeof(ByteType) == 1>;
constexpr void Combine(u32 crc, size_t len);
u32 m_value;
};
AZ_TYPE_INFO_WITH_NAME_DECL_EXT_API(AZCORE_API, Crc32);
}
namespace AZStd
{
template<>
struct hash<AZ::Crc32>
{
size_t operator()(const AZ::Crc32& id) const
{
return hasher(static_cast<AZ::u32>(id));
}
};
}
#include <AzCore/Math/Crc.inl>
Definition Crc.h:56
Definition SerializeContext.h:127
Definition string_view.h:622
Definition span.h:59
Reopen namespace to define DataPatch class.
Definition AssetCommon.h:26
AZ namespace needs to be closed in order to specialize the AZStd::hash struct for AddressTypeElement ...
Definition AssetCommon.h:1248
Default template (just try to cast the value to size_t)
Definition hash.h:34