1 #ifndef DALI_SCENE3D_LOADER_HASH_H_
2 #define DALI_SCENE3D_LOADER_HASH_H_
4 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
31 * @brief Rudimentary hash generator that follows a builder pattern.
36 static constexpr uint64_t DEFAULT_SEED = 61081;
38 explicit Hash(uint64_t initial = DEFAULT_SEED);
41 * @brief Applies a boolean to the hash.
42 * @return Its updated self.
47 * @brief Applies a signed 32-bit integer to the hash.
48 * @return Its updated self.
53 * @brief Applies an unsigned 32-bit integer to the hash.
54 * @return Its updated self.
56 Hash& Add(uint32_t i);
59 * @brief Applies an unsigned 64-bit integer to the hash.
60 * @return Its updated self.
62 Hash& Add(uint64_t i);
65 * @brief Applies a float to the hash.
66 * @return Its updated self.
71 * @brief Applies a c-string to the hash.
72 * @return Its updated self.
74 Hash& Add(const char* cStr);
77 * @brief Applies a c-string @a cStr of @a len characters, to the hash.
78 * @return Its updated self.
80 Hash& Add(const char* cStr, size_t len);
83 * @brief Applies a string to the hash.
84 * @return Its updated self.
86 Hash& Add(const std::string& str);
89 * @brief Applies a series of bytes between @a i0 and @a i1 to the hash.
90 * @return Its updated self.
92 Hash& AddBytes(const uint8_t* i0, const uint8_t* i1);
95 * @brief Applies the bytes of an object @a value, to the hash.
96 * @return Its updated self.
99 Hash& AddObjectBytes(const T& value);
101 operator uint64_t() const;
106 uint64_t Concatenate(uint64_t value);
110 Hash& Hash::AddObjectBytes(const T& value)
112 auto i0 = reinterpret_cast<const uint8_t*>(&value);
113 auto i1 = i0 + sizeof(T);
116 mValue = Concatenate(*i0);
122 } // namespace Loader
123 } // namespace Scene3D
126 #endif // DALI_SCENE3D_LOADER_HASH_H_