AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_EndianSwap.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2013-2015, 2023-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
32/*================================================================================================*/
33
34
35#pragma once
36
37#ifndef ENDIANSWAP_H
38#define ENDIANSWAP_H
39
40// Standard headers
41#include <algorithm>
42
44template<class T> void AAX_EndianSwapInPlace(T* theDataP);
45
47template<class T> T AAX_EndianSwap(T theData);
48
49
51template<class T> void AAX_BigEndianNativeSwapInPlace(T* theDataP);
52
54template<class T> T AAX_BigEndianNativeSwap(T theData);
55
57template<class T> void AAX_LittleEndianNativeSwapInPlace(T* theDataP);
58
60template<class T> T AAX_LittleEndianNativeSwap(T theData);
61
62
63
65template<class Iter> void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI);
66
67
69template<class Iter> void AAX_BigEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI);
70
72template<class Iter> void AAX_LittleEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI);
73
74
75//
76// Implementations
77//
78
79template<class T>
80inline
81void
83{
84 char *begin, *end;
85
86 begin = reinterpret_cast<char*>(theDataP);
87 end = begin + sizeof( T );
88 std::reverse( begin, end );
89}
90
91
92template<class T>
93inline
94T AAX_EndianSwap(T theData)
95{
96 AAX_EndianSwapInPlace(&theData);
97 return theData;
98}
99
100
101template<class T>
102inline
104{
105#if (!defined __BIG_ENDIAN__) || (0 == __BIG_ENDIAN__)
106 AAX_EndianSwapInPlace(theDataP);
107#endif
108}
109
110
111template<class T>
112inline
114{
116 return theData;
117}
118
119
120template<class T>
121inline
123{
124#if (defined __BIG_ENDIAN__) && (0 != __BIG_ENDIAN__)
125 AAX_EndianSwapInPlace(theDataP);
126#endif
127}
128
129
130template<class T>
131inline
133{
135 return theData;
136}
137
138
139template<class Iter>
140inline
141void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI)
142{
143 for(Iter i = beginI; i != endI; ++i)
144 {
145 // WARNING : Will this give a compile error if a use mistakenly uses it on a const sequence?
147 };
148}
149
150
151template<class Iter>
152inline
153void AAX_BigEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI)
154{
155#if (!defined __BIG_ENDIAN__) || (0 == __BIG_ENDIAN__)
156 AAX_EndianSwapSequenceInPlace(beginI, endI);
157#endif
158}
159
160
161template<class Iter>
162inline
164{
165#if (defined __BIG_ENDIAN__) && (0 != __BIG_ENDIAN__)
166 AAX_EndianSwapSequenceInPlace(beginI, endI);
167#endif
168}
169
170#endif
void AAX_EndianSwapInPlace(T *theDataP)
Byte swap data in-place.
Definition: AAX_EndianSwap.h:82
void AAX_BigEndianNativeSwapInPlace(T *theDataP)
Convert data in-place between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:103
T AAX_LittleEndianNativeSwap(T theData)
Copy and convert data from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:132
void AAX_LittleEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI)
Convert an sequence of data in-place from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:163
T AAX_EndianSwap(T theData)
Make a byte-swapped copy of data.
Definition: AAX_EndianSwap.h:94
T AAX_BigEndianNativeSwap(T theData)
Copy and convert data between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:113
void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI)
Byte swap a sequence of data in-place.
Definition: AAX_EndianSwap.h:141
void AAX_BigEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI)
Convert an sequence of data in-place between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:153
void AAX_LittleEndianNativeSwapInPlace(T *theDataP)
Convert data in-place from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:122