src/utility.h

changeset 196
6bcb284679d4
parent 141
185eb297dc1e
child 200
ca23936b455b
equal deleted inserted replaced
195:6e79c1cb83e6 196:6bcb284679d4
19 #pragma once 19 #pragma once
20 #include "basics.h" 20 #include "basics.h"
21 21
22 namespace utility 22 namespace utility
23 { 23 {
24 template<typename T, std::size_t N>
25 constexpr std::size_t countof(T(&)[N])
26 {
27 return N;
28 }
29
30 // http://stackoverflow.com/a/18204188/3629665 24 // http://stackoverflow.com/a/18204188/3629665
31 template<typename T> 25 template<typename T>
32 inline T rotl10(T x) 26 inline T rotl10(T x)
33 { 27 {
34 return (x << 10) | ((x >> 22) & 0x000000ff); 28 return (x << 10) | ((x >> 22) & 0x000000ff);
63 string = "'" + string + "'"; 57 string = "'" + string + "'";
64 } 58 }
65 return string; 59 return string;
66 } 60 }
67 61
68 template<typename T, typename R>
69 bool contains(T&& container, R&& value)
70 {
71 return std::find(std::begin(container), std::end(container), value) != std::end(container);
72 }
73
74 /** 62 /**
75 * @brief Converts the specified vertex to a simple string 63 * @brief Converts the specified vertex to a simple string
76 * @param vertex vertex to convert 64 * @param vertex vertex to convert
77 * @return "x y z"-formatted string 65 * @return "x y z"-formatted string
78 */ 66 */
84 inline QString vertexToStringParens(const glm::vec3& vertex) 72 inline QString vertexToStringParens(const glm::vec3& vertex)
85 { 73 {
86 return utility::format("(%1, %2, %3)", vertex.x, vertex.y, vertex.z); 74 return utility::format("(%1, %2, %3)", vertex.x, vertex.y, vertex.z);
87 } 75 }
88 } 76 }
77
78 template<typename T, glm::qualifier Q>
79 inline unsigned int qHash(const glm::vec<3, T, Q>& key)
80 {
81 return qHash(key.x) ^ utility::rotl10(qHash(key.y)) ^ utility::rotl20(qHash(key.z));
82 }

mercurial