00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef XAPIAN_INCLUDED_UNALIGNED_H
00023 #define XAPIAN_INCLUDED_UNALIGNED_H
00024
00025 #include "omassert.h"
00026
00027
00028
00029 inline int
00030 getint1(const unsigned char *p, int c)
00031 {
00032 AssertRel(c, >=, 0);
00033 AssertRel(c, <, 65536);
00034 return p[c];
00035 }
00036
00037 inline void
00038 setint1(unsigned char *p, int c, int x)
00039 {
00040 AssertRel(c, >=, 0);
00041 AssertRel(c, <, 65536);
00042 p[c] = static_cast<unsigned char>(x);
00043 }
00044
00045 inline int
00046 getint2(const unsigned char *p, int c)
00047 {
00048 AssertRel(c, >=, 0);
00049 AssertRel(c, <, 65536 - 1);
00050 return p[c] << 8 | p[c + 1];
00051 }
00052
00053 inline void
00054 setint2(unsigned char *p, int c, int x)
00055 {
00056 AssertRel(c, >=, 0);
00057 AssertRel(c, <, 65536 - 1);
00058 p[c] = static_cast<unsigned char>(x >> 8);
00059 p[c + 1] = static_cast<unsigned char>(x);
00060 }
00061
00062 inline int
00063 getint4(const unsigned char *p, int c)
00064 {
00065 AssertRel(c, >=, 0);
00066 AssertRel(c, <, 65536 - 3);
00067 return p[c] << 24 | p[c + 1] << 16 | p[c + 2] << 8 | p[c + 3];
00068 }
00069
00070 inline void
00071 setint4(unsigned char *p, int c, int x)
00072 {
00073 AssertRel(c, >=, 0);
00074 AssertRel(c, <, 65536 - 3);
00075 p[c] = static_cast<unsigned char>(x >> 24);
00076 p[c + 1] = static_cast<unsigned char>(x >> 16);
00077 p[c + 2] = static_cast<unsigned char>(x >> 8);
00078 p[c + 3] = static_cast<unsigned char>(x);
00079 }
00080
00081 #endif // XAPIAN_INCLUDED_UNALIGNED_H