AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_EndianSwap.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2013-2015 by Avid Technology, Inc.
5  * All rights reserved.
6  *
7  * CONFIDENTIAL: This document contains confidential information. Do not
8  * read or examine this document unless you are an Avid Technology employee
9  * or have signed a non-disclosure agreement with Avid Technology which protects
10  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
11  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
12  * OF Avid Technology, INC.
13  *
14  */
15 
22 /*================================================================================================*/
23 
24 
25 #pragma once
26 
27 #ifndef ENDIANSWAP_H
28 #define ENDIANSWAP_H
29 
30 // Standard headers
31 #include <algorithm>
32 
34 template<class T> void AAX_EndianSwapInPlace(T* theDataP);
35 
37 template<class T> T AAX_EndianSwap(T theData);
38 
39 
41 template<class T> void AAX_BigEndianNativeSwapInPlace(T* theDataP);
42 
44 template<class T> T AAX_BigEndianNativeSwap(T theData);
45 
47 template<class T> void AAX_LittleEndianNativeSwapInPlace(T* theDataP);
48 
50 template<class T> T AAX_LittleEndianNativeSwap(T theData);
51 
52 
53 
55 template<class Iter> void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI);
56 
57 
59 template<class Iter> void AAX_BigEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI);
60 
62 template<class Iter> void AAX_LittleEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI);
63 
64 
65 //
66 // Implementations
67 //
68 
69 template<class T>
70 inline
71 void
73 {
74  char *begin, *end;
75 
76  begin = reinterpret_cast<char*>(theDataP);
77  end = begin + sizeof( T );
78  std::reverse( begin, end );
79 }
80 
81 
82 template<class T>
83 inline
84 T AAX_EndianSwap(T theData)
85 {
86  AAX_EndianSwapInPlace(&theData);
87  return theData;
88 }
89 
90 
91 template<class T>
92 inline
94 {
95 #if (!defined __BIG_ENDIAN__) || (0 == __BIG_ENDIAN__)
96  AAX_EndianSwapInPlace(theDataP);
97 #endif
98 }
99 
100 
101 template<class T>
102 inline
104 {
106  return theData;
107 }
108 
109 
110 template<class T>
111 inline
113 {
114 #if (defined __BIG_ENDIAN__) && (0 != __BIG_ENDIAN__)
115  AAX_EndianSwapInPlace(theDataP);
116 #endif
117 }
118 
119 
120 template<class T>
121 inline
123 {
125  return theData;
126 }
127 
128 
129 template<class Iter>
130 inline
131 void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI)
132 {
133  for(Iter i = beginI; i != endI; ++i)
134  {
135  // WARNING : Will this give a compile error if a use mistakenly uses it on a const sequence?
136  AAX_EndianSwapInPlace(&(*i));
137  };
138 }
139 
140 
141 template<class Iter>
142 inline
143 void AAX_BigEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI)
144 {
145 #if (!defined __BIG_ENDIAN__) || (0 == __BIG_ENDIAN__)
146  AAX_EndianSwapSequenceInPlace(beginI, endI);
147 #endif
148 }
149 
150 
151 template<class Iter>
152 inline
153 void AAX_LittleEndianNativeSwapSequenceInPlace(Iter beginI, Iter endI)
154 {
155 #if (defined __BIG_ENDIAN__) && (0 != __BIG_ENDIAN__)
156  AAX_EndianSwapSequenceInPlace(beginI, endI);
157 #endif
158 }
159 
160 #endif
void AAX_EndianSwapInPlace(T *theDataP)
Byte swap data in-place.
Definition: AAX_EndianSwap.h:72
void AAX_BigEndianNativeSwapInPlace(T *theDataP)
Convert data in-place between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:93
T AAX_LittleEndianNativeSwap(T theData)
Copy and convert data from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:122
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:153
T AAX_EndianSwap(T theData)
Make a byte-swapped copy of data.
Definition: AAX_EndianSwap.h:84
T AAX_BigEndianNativeSwap(T theData)
Copy and convert data between Big Endian and native byte ordering.
Definition: AAX_EndianSwap.h:103
void AAX_EndianSwapSequenceInPlace(Iter beginI, Iter endI)
Byte swap a sequence of data in-place.
Definition: AAX_EndianSwap.h:131
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:143
void AAX_LittleEndianNativeSwapInPlace(T *theDataP)
Convert data in-place from the native byte ordering to Little Endian byte ordering.
Definition: AAX_EndianSwap.h:112