File: datatypes.cpp

package info (click to toggle)
turqstat 3.0-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 2,112 kB
  • ctags: 1,328
  • sloc: cpp: 17,929; perl: 252; makefile: 223; ansic: 75; sh: 16
file content (78 lines) | stat: -rw-r--r-- 1,961 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2001 Peter Karlsson
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include <config.h>
#if defined(WORDS_BIGENDIAN)
# include "datatypes.h"

le_uint16_t &le_uint16_t::operator=(uint16_t x)
{
    data[0] =  x       & 0xff;
    data[1] = (x >> 8) & 0xff;
    return *this;
}

le_uint16_t::operator uint16_t()
{
    return (data[1] << 8) | data[0];
}

le_int16_t &le_int16_t::operator=(int16_t x)
{
    data[0] =  uint16_t(x)       & 0xff;
    data[1] = (uint16_t(x) >> 8) & 0xff;
    return *this;
}

le_int16_t::operator int16_t()
{
    return int16_t((data[1] << 8) | data[0]);
}

le_uint32_t &le_uint32_t::operator=(uint32_t x)
{
    data[0] =  x        & 0xff;
    data[1] = (x >>  8) & 0xff;
    data[2] = (x >> 16) & 0xff;
    data[3] = (x >> 24) & 0xff;
    return *this;
}

le_uint32_t::operator uint32_t()
{
    return (data[3] << 24) |
           (data[2] << 16) |
           (data[1] <<  8) |
            data[0];
}

le_int32_t &le_int32_t::operator=(int32_t x)
{
    data[0] =  uint32_t(x)        & 0xff;
    data[1] = (uint32_t(x) >>  8) & 0xff;
    data[2] = (uint32_t(x) >> 16) & 0xff;
    data[3] = (uint32_t(x) >> 24) & 0xff;
    return *this;
}

le_int32_t::operator int32_t()
{
    return int32_t((data[3] << 24) |
                   (data[2] << 16) |
                   (data[1] <<  8) |
                    data[0]         );
}

#endif