27#define BITMASK 0x01U << 7
29#ifdef BYTE_ORDER_IS_BIG_ENDIAN
30#define MRTRIX_IS_BIG_ENDIAN true
31#define TO_LE(v) swap(v)
34#define MRTRIX_IS_BIG_ENDIAN false
36#define TO_BE(v) swap(v)
48 template <
typename ValueType>
53 template <
typename ValueType>
63 template <
typename ValueType>
74 template <
typename ValueType>
87 template <
typename ValueType>
90 template <
typename ValueType>
91 inline ValueType
LE (ValueType v) {
return TO_LE (v); }
93 template <
typename ValueType>
94 inline ValueType
BE (ValueType v) {
return TO_BE (v); }
96 template <
typename ValueType>
104 template <
typename ValueType> ValueType* as (
void* p) {
return reinterpret_cast<ValueType*
> (p); }
105 template <
typename ValueType>
const ValueType* as (
const void* p) {
return reinterpret_cast<const ValueType*
> (p); }
110 template <
typename ValueType>
113 template <
typename ValueType>
116 template <
typename ValueType>
119 template <
typename ValueType>
120 inline ValueType
fetch__native (
const void* address) {
return *as<ValueType>(address); }
123 template <
typename ValueType>
126 template <
typename ValueType>
129 template <
typename ValueType>
132 template <
typename ValueType>
138 template <
typename ValueType>
142 template <
typename ValueType>
146 template <
typename ValueType>
150 template <
typename ValueType>
151 inline ValueType
fetch_native (
const void* data,
size_t i) {
return as<ValueType>(data)[i]; }
156 template <
typename ValueType>
160 template <
typename ValueType>
164 template <
typename ValueType>
168 template <
typename ValueType>
176 inline bool fetch_native<bool> (
const void* data,
size_t i) {
return ( as<uint8_t>(data)[i/8]) & (
BITMASK >> i%8 ); }
179 inline void store_native<bool> (
const bool value,
void* data,
size_t i) {
183 std::atomic<uint8_t>* at =
reinterpret_cast<std::atomic<uint8_t>*
> (as<uint8_t>(data) + (i/8));
184 uint8_t prev = *at, new_value;
187 else new_value = prev & ~(
BITMASK >> i%8);
188 }
while (!at->compare_exchange_weak (prev, new_value));
193 inline bool fetch<bool> (
const void* data,
size_t i,
bool) {
return fetch_native<bool> (data, i); }
196 inline void store<bool> (
const bool value,
void* data,
size_t i,
bool) { store_native<bool> (
value, data, i); }
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
ValueType BE(ValueType v)
ValueType swap(const ValueType value, bool is_big_endian)
ValueType LE(ValueType v)
std::enable_if< std::is_fundamental< ValueType >::value &&sizeof(ValueType)==1, ValueType >::type swap(ValueType v)
ValueType fetch(const void *data, size_t i, bool is_big_endian=false)
fetch value in format is_big_endian from offset i from data
void store(const ValueType value, void *address, bool is_big_endian=false)
ValueType fetch_BE(const void *address)
ValueType fetch_LE(const void *address)
ValueType fetch_native(const void *data, size_t i)
fetch value in native format from offset i from data
void store_native(const ValueType value, void *address)
void store_LE(const ValueType value, void *address)
ValueType fetch_(const void *address, bool is_big_endian=false)
void store_BE(const ValueType value, void *address)
ValueType fetch__native(const void *address)
#define MRTRIX_IS_BIG_ENDIAN