1+ #ifndef _NBL_SYSTEM_TO_STRING_INCLUDED_
2+ #define _NBL_SYSTEM_TO_STRING_INCLUDED_
3+
4+ #include < nbl/builtin/hlsl/cpp_compat.hlsl>
5+ #include < nbl/builtin/hlsl/emulated/int64_t.hlsl>
6+ #include < nbl/builtin/hlsl/morton.hlsl>
7+
8+ namespace nbl
9+ {
10+ namespace system
11+ {
12+ namespace impl
13+ {
14+
15+ template <typename T>
16+ struct to_string_helper
17+ {
18+ static std::string __call (const T& value)
19+ {
20+ return std::to_string (value);
21+ }
22+ };
23+
24+ template <>
25+ struct to_string_helper <hlsl::emulated_uint64_t >
26+ {
27+ static std::string __call (const hlsl::emulated_uint64_t & value)
28+ {
29+ return std::to_string (static_cast <uint64_t >(value));
30+ }
31+ };
32+
33+ template <>
34+ struct to_string_helper <hlsl::emulated_int64_t >
35+ {
36+ static std::string __call (const hlsl::emulated_int64_t & value)
37+ {
38+ return std::to_string (static_cast <int64_t >(value));
39+ }
40+ };
41+
42+ template <typename T, int16_t N>
43+ struct to_string_helper <hlsl::vector<T, N>>
44+ {
45+ static std::string __call (const hlsl::vector<T, N>& value)
46+ {
47+ std::stringstream output;
48+ output << " { " ;
49+ for (int i = 0 ; i < N; ++i)
50+ {
51+ output << to_string_helper<T>::__call (value[i]);
52+
53+ if (i < N - 1 )
54+ output << " , " ;
55+ }
56+ output << " }" ;
57+
58+ return output.str ();
59+ }
60+ };
61+
62+ template <bool Signed, uint16_t Bits, uint16_t D, typename _uint64_t >
63+ struct to_string_helper <hlsl::morton::code<Signed, Bits, D, _uint64_t >>
64+ {
65+ using value_t = hlsl::morton::code<Signed, Bits, D, _uint64_t >;
66+ static std::string __call (value_t value)
67+ {
68+ return to_string_helper<value_t ::storage_t >::__call (value.value );
69+ }
70+ };
71+
72+
73+ }
74+
75+ template <typename T>
76+ std::string to_string (T value)
77+ {
78+ return impl::to_string_helper<T>::__call (value);
79+ }
80+ }
81+ }
82+
83+ #endif
0 commit comments