Remove unused header include
[xapian.git] / xapian-core / common / unaligned.h
blob4553a2425f15760df4a14c76c855144087fbe2b6
1 /** @file unaligned.h
2 * @brief Read/write unaligned 1, 2, 4 byte integers.
3 */
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002,2004,2008,2011 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 * USA
23 #ifndef XAPIAN_INCLUDED_UNALIGNED_H
24 #define XAPIAN_INCLUDED_UNALIGNED_H
26 #include "omassert.h"
28 // FIXME: 65536 in Asserts below is the max chert block size. We should
29 // abstract this out, and use the current block_size to catch overruns better.
30 inline int
31 getint1(const unsigned char *p, int c)
33 AssertRel(c, >=, 0);
34 AssertRel(c, <, 65536);
35 return p[c];
38 inline void
39 setint1(unsigned char *p, int c, int x)
41 AssertRel(c, >=, 0);
42 AssertRel(c, <, 65536);
43 p[c] = static_cast<unsigned char>(x);
46 inline int
47 getint2(const unsigned char *p, int c)
49 AssertRel(c, >=, 0);
50 AssertRel(c, <, 65536 - 1);
51 return p[c] << 8 | p[c + 1];
54 inline void
55 setint2(unsigned char *p, int c, int x)
57 AssertRel(c, >=, 0);
58 AssertRel(c, <, 65536 - 1);
59 p[c] = static_cast<unsigned char>(x >> 8);
60 p[c + 1] = static_cast<unsigned char>(x);
63 inline int
64 getint4(const unsigned char *p, int c)
66 AssertRel(c, >=, 0);
67 AssertRel(c, <, 65536 - 3);
68 return p[c] << 24 | p[c + 1] << 16 | p[c + 2] << 8 | p[c + 3];
71 inline void
72 setint4(unsigned char *p, int c, int x)
74 AssertRel(c, >=, 0);
75 AssertRel(c, <, 65536 - 3);
76 p[c] = static_cast<unsigned char>(x >> 24);
77 p[c + 1] = static_cast<unsigned char>(x >> 16);
78 p[c + 2] = static_cast<unsigned char>(x >> 8);
79 p[c + 3] = static_cast<unsigned char>(x);
82 #endif // XAPIAN_INCLUDED_UNALIGNED_H