VISR  0.11.7
Versatile Interactive Scene Renderer
compile_time_hash_fnv1.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_DETAIL_COMPILE_TIME_HASH_FNV1_HPP_INCLUDED
4 #define VISR_DETAIL_COMPILE_TIME_HASH_FNV1_HPP_INCLUDED
5 
6 #include <string>
7 #include <cstddef>
8 #include <stdexcept>
9 
10 namespace visr
11 {
12 namespace detail
13 {
14  // Forward declaration of internal implementation function.
15  constexpr uint64_t fnv1( uint64_t h, const char* s );
16 
25  constexpr uint64_t compileTimeHashFNV1( const char* s )
26  {
27  return true ?
28  detail::fnv1( 14695981039346656037ull, s ) :
29  throw std::logic_error("FNV1 hash failed.");
30  }
31 
35  constexpr uint64_t fnv1( uint64_t h, const char* s )
36  {
37 // Disable "integral constant overflow" warning in Microsoft Visual C++ compiler.
38 #ifdef _MSC_VER
39 //#pragma warning( push )
40 #pragma warning( disable : 4307)
41 #endif
42  return (*s == 0) ? h :
43  fnv1( static_cast<uint64_t>(h * 1099511628211ull) ^
44  *s, s + 1 );
45 #ifdef _MSC_VER
46 //#pragma warning( pop )
47 #endif
48  }
49 
50 
51 } // namespace detail
52 } // namespace visr
53 
54 #endif // #ifndef VISR_DETAIL_COMPILE_TIME_HASH_FNV1_HPP_INCLUDED
constexpr uint64_t compileTimeHashFNV1(const char *s)
Definition: compile_time_hash_fnv1.hpp:25
constexpr uint64_t fnv1(uint64_t h, const char *s)
Definition: compile_time_hash_fnv1.hpp:35
Definition: options.cpp:10