1 #ifndef DALI_SCENE_LOADER_HASH_H_
2 #define DALI_SCENE_LOADER_HASH_H_
4 * Copyright (c) 2021 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.
29 * @brief Rudimentary hash generator that follows a builder pattern.
34 static constexpr uint64_t DEFAULT_SEED = 61081;
36 explicit Hash(uint64_t initial = DEFAULT_SEED);
39 * @brief Applies a boolean to the hash.
40 * @return Its updated self.
45 * @brief Applies a signed 32-bit integer to the hash.
46 * @return Its updated self.
51 * @brief Applies an unsigned 32-bit integer to the hash.
52 * @return Its updated self.
54 Hash& Add(uint32_t i);
57 * @brief Applies an unsigned 64-bit integer to the hash.
58 * @return Its updated self.
60 Hash& Add(uint64_t i);
63 * @brief Applies a float to the hash.
64 * @return Its updated self.
69 * @brief Applies a c-string to the hash.
70 * @return Its updated self.
72 Hash& Add(const char* cStr);
75 * @brief Applies a c-string @a cStr of @a len characters, to the hash.
76 * @return Its updated self.
78 Hash& Add(const char* cStr, size_t len);
81 * @brief Applies a string to the hash.
82 * @return Its updated self.
84 Hash& Add(const std::string& str);
87 * @brief Applies a series of bytes between @a i0 and @a i1 to the hash.
88 * @return Its updated self.
90 Hash& AddBytes(const uint8_t* i0, const uint8_t* i1);
93 * @brief Applies the bytes of an object @a value, to the hash.
94 * @return Its updated self.
97 Hash& AddObjectBytes(const T& value);
99 operator uint64_t() const;
104 uint64_t Concatenate(uint64_t value);
108 Hash& Hash::AddObjectBytes(const T& value)
110 auto i0 = reinterpret_cast<const uint8_t*>(&value);
111 auto i1 = i0 + sizeof(T);
114 mValue = Concatenate(*i0);
120 } // namespace SceneLoader
123 #endif // DALI_SCENE_LOADER_HASH_H_