1 #ifndef _TCUSEEDBUILDER_HPP
2 #define _TCUSEEDBUILDER_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Utility class to build seeds from different data types.
24 *
25 * Values are first XORed with type specifig mask, which makes sure that
26 * two values with different types, but same bit presentation produce
27 * different results. Then values are passed through 32 bit crc.
28 *//*--------------------------------------------------------------------*/
29
30 #include "tcuDefs.hpp"
31 #include "tcuVector.hpp"
32
33 #include <string>
34 #include <vector>
35
36 namespace tcu
37 {
38
39 class SeedBuilder
40 {
41 public:
42 SeedBuilder(void);
get(void) const43 uint32_t get(void) const
44 {
45 return m_hash;
46 }
47 void feed(size_t size, const void *ptr);
48
49 private:
50 uint32_t m_hash;
51 } DE_WARN_UNUSED_TYPE;
52
53 SeedBuilder &operator<<(SeedBuilder &builder, bool value);
54 SeedBuilder &operator<<(SeedBuilder &builder, int8_t value);
55 SeedBuilder &operator<<(SeedBuilder &builder, uint8_t value);
56
57 SeedBuilder &operator<<(SeedBuilder &builder, int16_t value);
58 SeedBuilder &operator<<(SeedBuilder &builder, uint16_t value);
59
60 SeedBuilder &operator<<(SeedBuilder &builder, int32_t value);
61 SeedBuilder &operator<<(SeedBuilder &builder, uint32_t value);
62
63 SeedBuilder &operator<<(SeedBuilder &builder, int64_t value);
64 SeedBuilder &operator<<(SeedBuilder &builder, uint64_t value);
65
66 SeedBuilder &operator<<(SeedBuilder &builder, float value);
67 SeedBuilder &operator<<(SeedBuilder &builder, double value);
68
69 SeedBuilder &operator<<(SeedBuilder &builder, const std::string &value);
70
71 template <class T, int Size>
operator <<(SeedBuilder & builder,const tcu::Vector<T,Size> & value)72 SeedBuilder &operator<<(SeedBuilder &builder, const tcu::Vector<T, Size> &value)
73 {
74 for (int i = 0; i < Size; i++)
75 builder << value[i];
76
77 return builder;
78 }
79
80 } // namespace tcu
81
82 #endif // _TCUSEEDBUILDER_HPP
83