~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/kvilib/system/KviByteOrder.h

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _KVI_BYTEORDER_H_
 
2
#define _KVI_BYTEORDER_H_
 
3
 
 
4
//=============================================================================
 
5
//
 
6
//   File : KviByteOrder.h
 
7
//   Creation date : Mon Dec 25 2006 19:56:16 CEST by Szymon Stefanek
 
8
//   Based on file : kvi_bswap.h
 
9
//   Creation date : Fri Mar 19 1999 03:15:21 CEST by Szymon Stefanek
 
10
//
 
11
//   This file is part of the KVIrc irc client distribution
 
12
//   Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net)
 
13
//
 
14
//   This program is FREE software. You can redistribute it and/or
 
15
//   modify it under the terms of the GNU General Public License
 
16
//   as published by the Free Software Foundation; either version 2
 
17
//   of the License, or (at your opinion) any later version.
 
18
//
 
19
//   This program is distributed in the HOPE that it will be USEFUL,
 
20
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
22
//   See the GNU General Public License for more details.
 
23
//
 
24
//   You should have received a copy of the GNU General Public License
 
25
//   along with this program. If not, write to the Free Software Foundation,
 
26
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
27
//
 
28
//=============================================================================
 
29
 
 
30
#include "kvi_settings.h"
 
31
#include "kvi_inttypes.h"
 
32
 
 
33
namespace KviByteOrder
 
34
{
 
35
        /**
 
36
        * \brief Swaps the endianess of a kvi_u64_t
 
37
        *
 
38
        * \param i the original value
 
39
        * \return kvi_u64_t
 
40
        */
 
41
        inline kvi_u64_t swap64(kvi_u64_t i)
 
42
        {
 
43
                // abcdefgh to hgfedcba
 
44
                return ((i << 56) |                /* h to a */
 
45
                        ((i & 0xff00) << 40) |     /* g to b */
 
46
                        ((i & 0xff0000) << 24) |   /* f to c */
 
47
                        ((i & 0xff000000) << 8) |  /* e to d */
 
48
                        ((i >> 8) & 0xff000000) |  /* d to e */
 
49
                        ((i >> 24) & 0xff0000) |   /* c to f */
 
50
                        ((i >> 40) & 0xff00) |     /* b to g */
 
51
                        (i >> 56));                /* a to h */
 
52
        }
 
53
        
 
54
        /**
 
55
        * \brief Swaps the endianess of a kvi_u32_t
 
56
        *
 
57
        * \param i the original value
 
58
        * \return kvi_u32_t
 
59
        */
 
60
        inline kvi_u32_t swap32(kvi_u32_t i)
 
61
        {
 
62
                // abcd to dcba
 
63
                return ((i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24));
 
64
        }
 
65
        
 
66
        /**
 
67
        * \brief Swaps the endianess of a kvi_u16_t
 
68
        *
 
69
        * \param i the original value
 
70
        * \return kvi_u16_t
 
71
        */
 
72
        inline kvi_u16_t swap16(kvi_u16_t i)
 
73
        {
 
74
                // ab to ba
 
75
                return ((i << 8) | (i >> 8));
 
76
        }
 
77
        
 
78
 
 
79
        //
 
80
        // Byte Orders Reminder
 
81
        //   Number                             0xaabbccdd
 
82
        //   Little Endian Stores               0xdd 0xcc 0xbb 0xaa
 
83
        //   Big Endian Stores                  0xaa 0xbb 0xcc 0xdd
 
84
        //   Perverse Middle Endian             0xbb 0xaa 0xdd 0xcc or another braindamaged combination (unsupported)
 
85
        //   Network Byte Order is Big Endian
 
86
        //   Intel Stuff uses Little Endian
 
87
        //   PPC is Big Endian
 
88
        //   Universal binaries on MacOSX use both Big and Little Endian
 
89
        //
 
90
 
 
91
#ifdef BIG_ENDIAN_MACHINE_BYTE_ORDER
 
92
 
 
93
        inline kvi_u16_t localCpuToLittleEndian16(kvi_u16_t u)
 
94
        {
 
95
                return swap16(u);
 
96
        }
 
97
        
 
98
        inline kvi_u32_t localCpuToLittleEndian32(kvi_u32_t u)
 
99
        {
 
100
                return swap32(u);
 
101
        }
 
102
 
 
103
        inline kvi_u64_t localCpuToLittleEndian64(kvi_u64_t u)
 
104
        {
 
105
                return swap64(u);
 
106
        }
 
107
 
 
108
        inline kvi_u16_t littleEndianToLocalCpu16(kvi_u16_t u)
 
109
        {
 
110
                return swap16(u);
 
111
        }
 
112
 
 
113
        inline kvi_u32_t littleEndianToLocalCpu32(kvi_u32_t u)
 
114
        {
 
115
                return swap32(u);
 
116
        }
 
117
 
 
118
        inline kvi_u64_t littleEndianToLocalCpu64(kvi_u64_t u)
 
119
        {
 
120
                return swap64(u);
 
121
        }
 
122
 
 
123
#else //!BIG_ENDIAN_MACHINE_BYTE_ORDER
 
124
 
 
125
        // We ASSUME that the local cpu is little endian.. if it isn't.. well :)
 
126
        #define LOCAL_CPU_LITTLE_ENDIAN 1
 
127
 
 
128
        inline kvi_u16_t localCpuToLittleEndian16(kvi_u16_t u)
 
129
        {
 
130
                return u;
 
131
        }
 
132
        
 
133
        inline kvi_u32_t localCpuToLittleEndian32(kvi_u32_t u)
 
134
        {
 
135
                return u;
 
136
        }
 
137
 
 
138
        inline kvi_u64_t localCpuToLittleEndian64(kvi_u64_t u)
 
139
        {
 
140
                return u;
 
141
        }
 
142
 
 
143
        inline kvi_u16_t littleEndianToLocalCpu16(kvi_u16_t u)
 
144
        {
 
145
                return u;
 
146
        }
 
147
 
 
148
        inline kvi_u32_t littleEndianToLocalCpu32(kvi_u32_t u)
 
149
        {
 
150
                return u;
 
151
        }
 
152
 
 
153
        inline kvi_u64_t littleEndianToLocalCpu64(kvi_u64_t u)
 
154
        {
 
155
                return u;
 
156
        }
 
157
 
 
158
#endif //!BIG_ENDIAN_MACHINE_BYTE_ORDER
 
159
 
 
160
} // namespace KviByteOrder
 
161
 
 
162
 
 
163
 
 
164
 
 
165
 
 
166
 
 
167
 
 
168
#endif // !_KVI_BYTEORDER_H_