00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __LETYPE_H__
00021 #define __LETYPE_H__
00022
00023 #if __BYTE_ORDER == __LITTLE_ENDIAN
00024
00025 typedef u16 leu16;
00026 typedef u32 leu32;
00027 typedef u64 leu64;
00028
00029 #else
00030
00031 class leu16
00032 {
00033 public:
00034 leu16(void);
00035
00036 leu16(const leu16 &other);
00037 leu16& operator=(const leu16 &other);
00038
00039 leu16(const u16 &other);
00040 leu16& operator=(const u16 &other);
00041
00042 operator u16(void) const;
00043
00044 protected:
00045 u16 value;
00046 };
00047
00048 inline leu16::leu16(void)
00049 {
00050 }
00051
00052 inline leu16::leu16(const leu16 &other)
00053 : value(other.value)
00054 {
00055 }
00056
00057 inline leu16& leu16::operator =(const leu16 &other)
00058 {
00059 value = other.value;
00060 return *this;
00061 }
00062
00063 inline leu16::leu16(const u16 &other)
00064 {
00065 ((unsigned char*)&value)[0] = (unsigned char)((other >> 0) & 0xff);
00066 ((unsigned char*)&value)[1] = (unsigned char)((other >> 8) & 0xff);
00067 }
00068
00069 inline leu16& leu16::operator=(const u16 &other)
00070 {
00071 ((unsigned char*)&value)[0] = (unsigned char)((other >> 0) & 0xff);
00072 ((unsigned char*)&value)[1] = (unsigned char)((other >> 8) & 0xff);
00073
00074 return *this;
00075 }
00076
00077 inline leu16::operator u16(void) const
00078 {
00079 return ((unsigned char*)&value)[0] << 0 |
00080 ((unsigned char*)&value)[1] << 8;
00081 }
00082
00083
00084 class leu32
00085 {
00086 public:
00087 leu32(void);
00088
00089 leu32(const leu32 &other);
00090 leu32& operator=(const leu32 &other);
00091
00092 leu32(const u32 &other);
00093 leu32& operator=(const u32 &other);
00094
00095 operator u32(void) const;
00096
00097 protected:
00098 u32 value;
00099 };
00100
00101 inline leu32::leu32(void)
00102 {
00103 }
00104
00105 inline leu32::leu32(const leu32 &other)
00106 : value(other.value)
00107 {
00108 }
00109
00110 inline leu32& leu32::operator =(const leu32 &other)
00111 {
00112 value = other.value;
00113 return *this;
00114 }
00115
00116 inline leu32::leu32(const u32 &other)
00117 {
00118 ((unsigned char*)&value)[0] = (unsigned char)((other >> 0) & 0xff);
00119 ((unsigned char*)&value)[1] = (unsigned char)((other >> 8) & 0xff);
00120 ((unsigned char*)&value)[2] = (unsigned char)((other >> 16) & 0xff);
00121 ((unsigned char*)&value)[3] = (unsigned char)((other >> 24) & 0xff);
00122 }
00123
00124 inline leu32& leu32::operator=(const u32 &other)
00125 {
00126 ((unsigned char*)&value)[0] = (unsigned char)((other >> 0) & 0xff);
00127 ((unsigned char*)&value)[1] = (unsigned char)((other >> 8) & 0xff);
00128 ((unsigned char*)&value)[2] = (unsigned char)((other >> 16) & 0xff);
00129 ((unsigned char*)&value)[3] = (unsigned char)((other >> 24) & 0xff);
00130
00131 return *this;
00132 }
00133
00134 inline leu32::operator u32(void) const
00135 {
00136 return ((unsigned char*)&value)[0] << 0 |
00137 ((unsigned char*)&value)[1] << 8 |
00138 ((unsigned char*)&value)[2] << 16 |
00139 ((unsigned char*)&value)[3] << 24;
00140 }
00141
00142
00143 class leu64
00144 {
00145 public:
00146 leu64(void);
00147
00148 leu64(const leu64 &other);
00149 leu64& operator=(const leu64 &other);
00150
00151 leu64(const u64 &other);
00152 leu64& operator=(const u64 &other);
00153
00154 operator u64(void) const;
00155
00156 protected:
00157 u64 value;
00158 };
00159
00160 inline leu64::leu64(void)
00161 {
00162 }
00163
00164 inline leu64::leu64(const leu64 &other)
00165 : value(other.value)
00166 {
00167 }
00168
00169 inline leu64& leu64::operator =(const leu64 &other)
00170 {
00171 value = other.value;
00172 return *this;
00173 }
00174
00175 inline leu64::leu64(const u64 &other)
00176 {
00177 ((unsigned char*)&value)[0] = (unsigned char)((other >> 0) & 0xff);
00178 ((unsigned char*)&value)[1] = (unsigned char)((other >> 8) & 0xff);
00179 ((unsigned char*)&value)[2] = (unsigned char)((other >> 16) & 0xff);
00180 ((unsigned char*)&value)[3] = (unsigned char)((other >> 24) & 0xff);
00181 ((unsigned char*)&value)[4] = (unsigned char)((other >> 32) & 0xff);
00182 ((unsigned char*)&value)[5] = (unsigned char)((other >> 40) & 0xff);
00183 ((unsigned char*)&value)[6] = (unsigned char)((other >> 48) & 0xff);
00184 ((unsigned char*)&value)[7] = (unsigned char)((other >> 56) & 0xff);
00185 }
00186
00187 inline leu64& leu64::operator=(const u64 &other)
00188 {
00189 ((unsigned char*)&value)[0] = (unsigned char)((other >> 0) & 0xff);
00190 ((unsigned char*)&value)[1] = (unsigned char)((other >> 8) & 0xff);
00191 ((unsigned char*)&value)[2] = (unsigned char)((other >> 16) & 0xff);
00192 ((unsigned char*)&value)[3] = (unsigned char)((other >> 24) & 0xff);
00193 ((unsigned char*)&value)[4] = (unsigned char)((other >> 32) & 0xff);
00194 ((unsigned char*)&value)[5] = (unsigned char)((other >> 40) & 0xff);
00195 ((unsigned char*)&value)[6] = (unsigned char)((other >> 48) & 0xff);
00196 ((unsigned char*)&value)[7] = (unsigned char)((other >> 56) & 0xff);
00197
00198 return *this;
00199 }
00200
00201 inline leu64::operator u64(void) const
00202 {
00203 return (u64)(((unsigned char*)&value)[0]) << 0 |
00204 (u64)(((unsigned char*)&value)[1]) << 8 |
00205 (u64)(((unsigned char*)&value)[2]) << 16 |
00206 (u64)(((unsigned char*)&value)[3]) << 24 |
00207 (u64)(((unsigned char*)&value)[4]) << 32 |
00208 (u64)(((unsigned char*)&value)[5]) << 40 |
00209 (u64)(((unsigned char*)&value)[6]) << 48 |
00210 (u64)(((unsigned char*)&value)[7]) << 56;
00211 }
00212
00213 #endif
00214
00215 #endif // __LETYPE_H__