Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Alignment.hpp
00001 // ArduinoJson - arduinojson.org 00002 // Copyright Benoit Blanchon 2014-2021 00003 // MIT License 00004 00005 #pragma once 00006 00007 #include <ArduinoJson/Namespace.hpp> 00008 00009 #include <stddef.h> // size_t 00010 00011 namespace ARDUINOJSON_NAMESPACE { 00012 00013 #if ARDUINOJSON_ENABLE_ALIGNMENT 00014 00015 inline bool isAligned(size_t value) { 00016 const size_t mask = sizeof(void *) - 1; 00017 size_t addr = value; 00018 return (addr & mask) == 0; 00019 } 00020 00021 inline size_t addPadding(size_t bytes) { 00022 const size_t mask = sizeof(void *) - 1; 00023 return (bytes + mask) & ~mask; 00024 } 00025 00026 template <size_t bytes> 00027 struct AddPadding { 00028 static const size_t mask = sizeof(void *) - 1; 00029 static const size_t value = (bytes + mask) & ~mask; 00030 }; 00031 00032 #else 00033 00034 inline bool isAligned(size_t) { 00035 return true; 00036 } 00037 00038 inline size_t addPadding(size_t bytes) { 00039 return bytes; 00040 } 00041 00042 template <size_t bytes> 00043 struct AddPadding { 00044 static const size_t value = bytes; 00045 }; 00046 00047 #endif 00048 00049 template <typename T> 00050 inline bool isAligned(T *ptr) { 00051 return isAligned(reinterpret_cast<size_t>(ptr)); 00052 } 00053 00054 template <typename T> 00055 inline T *addPadding(T *p) { 00056 size_t address = addPadding(reinterpret_cast<size_t>(p)); 00057 return reinterpret_cast<T *>(address); 00058 } 00059 00060 } // namespace ARDUINOJSON_NAMESPACE
Generated on Wed Jul 13 2022 01:10:36 by
1.7.2