/src/s2geometry/src/s2/util/gtl/unaligned.h
Line | Count | Source |
1 | | // Copyright Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS-IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | // |
15 | | |
16 | | #ifndef S2_UTIL_GTL_UNALIGNED_H_ |
17 | | #define S2_UTIL_GTL_UNALIGNED_H_ |
18 | | |
19 | | #include <type_traits> |
20 | | |
21 | | namespace gtl { |
22 | | |
23 | | template <typename T> |
24 | 0 | T UnalignedLoad(const char *p) { |
25 | 0 | static_assert(std::is_trivially_copyable_v<T>); |
26 | 0 | T v; |
27 | 0 | memcpy(&v, p, sizeof(v)); |
28 | 0 | return v; |
29 | 0 | } Unexecuted instantiation: unsigned short gtl::UnalignedLoad<unsigned short>(char const*) Unexecuted instantiation: unsigned int gtl::UnalignedLoad<unsigned int>(char const*) Unexecuted instantiation: unsigned long gtl::UnalignedLoad<unsigned long>(char const*) |
30 | | |
31 | | template <typename T> |
32 | 0 | void UnalignedStore(T v, char *p) { |
33 | 0 | static_assert(std::is_trivially_copyable_v<T>); |
34 | 0 | memcpy(p, &v, sizeof(v)); |
35 | 0 | } Unexecuted instantiation: void gtl::UnalignedStore<unsigned short>(unsigned short, char*) Unexecuted instantiation: void gtl::UnalignedStore<unsigned int>(unsigned int, char*) Unexecuted instantiation: void gtl::UnalignedStore<unsigned long>(unsigned long, char*) |
36 | | |
37 | | } // namespace gtl |
38 | | |
39 | | #endif // S2_UTIL_GTL_UNALIGNED_H_ |