InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Swap.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Robin_Briggs
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __SWAP__
25 #define __SWAP__
26 
27 
29 {
30 public:
31  static char SwapChar(char c)
32  { return c; }
33  static uint16 SwapInt16(uint16 i)
34  { return (((i&0xFF)<<8) | (i>>8)); }
35  static uint32 SwapInt32(uint32 i)
36  { return (((i&0xff000000)>>24)
37  | ((i&0x00ff0000)>>8)
38  | ((i&0x0000ff00)<<8)
39  | ((i&0x000000ff)<<24)); }
40 
41  static void SwapDouble(double &d)
42  {
43  uchar* pLeft = (uchar *) &d;
44  uchar* pRight = (uchar *) (pLeft + sizeof(double) - 1);
45 
46  for ( unsigned int n = 0; n < (sizeof(double) / 2); n++ )
47  {
48  uchar temp = *pLeft;
49  *pLeft = *pRight;
50  *pRight = temp;
51  ++pLeft; --pRight;
52  }
53  }
54 };
55 
56 
57 #endif // __SWAP__