Make PostList subclasses return PostList* not Internal*
[xapian.git] / xapian-applications / omega / values.h
blobd6383d8a34d4b817ff589b7747c658b55d693d33
1 /* values.h: constants and functions for document value handling.
3 * Copyright (C) 2006,2010,2015 Olly Betts
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef OMEGA_INCLUDED_VALUES_H
21 #define OMEGA_INCLUDED_VALUES_H
23 #include <cstring>
24 #include <string>
26 #include <cstdint>
27 using std::uint32_t;
29 // Include these to get htonl, etc.
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
32 #endif
33 #ifdef HAVE_NETINET_IN_H
34 # include <netinet/in.h>
35 #endif
36 #ifdef __WIN32__
37 inline uint32_t htonl(uint32_t v) {
38 return (v << 24) | ((v & 0xff00) << 8) | ((v >> 8) & 0xff00) | (v >> 24);
40 # define ntohl(V) htonl(V)
41 #endif
43 enum value_slot {
44 VALUE_LASTMOD = 0, // 4 byte big endian value - seconds since 1970.
45 VALUE_MD5 = 1, // 16 byte MD5 checksum of original document.
46 VALUE_SIZE = 2, // sortable_serialise(<file size in bytes>).
47 VALUE_CTIME = 3 // Like VALUE_LASTMOD, but for last metadata change.
50 inline uint32_t binary_string_to_int(const std::string &s)
52 if (s.size() != 4) return static_cast<uint32_t>(-1);
53 uint32_t v;
54 std::memcpy(&v, s.data(), 4);
55 return ntohl(v);
58 inline std::string int_to_binary_string(uint32_t v)
60 v = htonl(v);
61 return std::string(reinterpret_cast<const char*>(&v), 4);
64 #endif