| AAX SDK 2.8.0 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

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
44 template<class T> void AAX_EndianSwapInPlace(T* theDataP);
45
47 template<class T> T AAX_EndianSwap(T theData);
48
49
51 template<class T> void AAX_BigEndianNativeSwapInPlace(T* theDataP);
52
54 template<class T> T AAX_BigEndianNativeSwap(T theData);
55
57 template<class T> void AAX_LittleEndianNativeSwapInPlace(T* theDataP);
58
60 template<class T> T AAX_LittleEndianNativeSwap(T theData);
61
62
63
65 template<class Iter> void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI);
66
67
69 template<class Iter> void AAX_BigEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI);
70
72 template<class Iter> void AAX_LittleEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI);
73
74
75//
76// Implementations
77//
78
79 template<class T>
80 inline
81 void
82 AAX_EndianSwapInPlace(T* theDataP)
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
92 template<class T>
93 inline
94T AAX_EndianSwap(T theData)
95{
96 AAX_EndianSwapInPlace(&theData);
97 return theData;
98}
99
100
101 template<class T>
102 inline
103 void AAX_BigEndianNativeSwapInPlace(T* theDataP)
104{
105#if (!defined __BIG_ENDIAN__) || (0 == __BIG_ENDIAN__)
106 AAX_EndianSwapInPlace(theDataP);
107#endif
108}
109
110
111 template<class T>
112 inline
113T AAX_BigEndianNativeSwap(T theData)
114{
115 AAX_BigEndianNativeSwapInPlace(&theData);
116 return theData;
117}
118
119
120 template<class T>
121 inline
122 void AAX_LittleEndianNativeSwapInPlace(T* theDataP)
123{
124#if (defined __BIG_ENDIAN__) && (0 != __BIG_ENDIAN__)
125 AAX_EndianSwapInPlace(theDataP);
126#endif
127}
128
129
130 template<class T>
131 inline
132T AAX_LittleEndianNativeSwap(T theData)
133{
134 AAX_LittleEndianNativeSwapInPlace(&theData);
135 return theData;
136}
137
138
139 template<class Iter>
140 inline
141 void 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?
146 AAX_EndianSwapInPlace(&(*i));
147 };
148}
149
150
151 template<class Iter>
152 inline
153 void 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
161 template<class Iter>
162 inline
163 void AAX_LittleEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI)
164{
165#if (defined __BIG_ENDIAN__) && (0 != __BIG_ENDIAN__)
166 AAX_EndianSwapSequenceInPlace(beginI, endI);
167#endif
168}
169
170#endif
AAX_EndianSwapInPlace
void AAX_EndianSwapInPlace(T *theDataP)
Byte swap data in-place.
Definition: AAX_EndianSwap.h:82
AAX_BigEndianNativeSwapInPlace
void AAX_BigEndianNativeSwapInPlace(T *theDataP)
Convert data in-place between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:103
AAX_LittleEndianNativeSwap
T AAX_LittleEndianNativeSwap(T theData)
Copy and convert data from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:132
AAX_LittleEndianNativeSwapSequenceInPlace
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
AAX_EndianSwap
T AAX_EndianSwap(T theData)
Make a byte-swapped copy of data.
Definition: AAX_EndianSwap.h:94
AAX_BigEndianNativeSwap
T AAX_BigEndianNativeSwap(T theData)
Copy and convert data between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:113
AAX_EndianSwapSequenceInPlace
void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI)
Byte swap a sequence of data in-place.
Definition: AAX_EndianSwap.h:141
AAX_BigEndianNativeSwapSequenceInPlace
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
AAX_LittleEndianNativeSwapInPlace
void AAX_LittleEndianNativeSwapInPlace(T *theDataP)
Convert data in-place from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:122