OSVR-Core
AlignmentPadding.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_AlignmentPadding_h_GUID_B916398A_5714_44B8_455A_B38EA1092172
26 #define INCLUDED_AlignmentPadding_h_GUID_B916398A_5714_44B8_455A_B38EA1092172
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <stddef.h>
36 
37 namespace osvr {
38 namespace common {
49  inline size_t computeAlignmentPadding(size_t alignment,
50  size_t currentSize) {
51  size_t ret = 0;
52  if (2 > alignment) {
54  return ret;
55  }
56  auto leftover = currentSize % alignment;
57  if (leftover == 0) {
59  return ret;
60  }
62  ret = alignment - leftover;
63  return ret;
64  }
65 } // namespace common
66 } // namespace osvr
67 
68 #endif // INCLUDED_AlignmentPadding_h_GUID_B916398A_5714_44B8_455A_B38EA1092172
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
size_t computeAlignmentPadding(size_t alignment, size_t currentSize)
Given an alignment in bytes, and a current size of a buffer, return the number of bytes of padding re...
Definition: AlignmentPadding.h:49