2 * @brief constants and functions for document value handling.
4 /* Copyright (C) 2006,2010,2015,2019 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef OMEGA_INCLUDED_VALUES_H
22 #define OMEGA_INCLUDED_VALUES_H
25 # error config.h must be included first in each C++ source file
34 VALUE_LASTMOD
= 0, // 4 byte big endian value - seconds since 1970.
35 VALUE_MD5
= 1, // 16 byte MD5 checksum of original document.
36 VALUE_SIZE
= 2, // sortable_serialise(<file size in bytes>).
37 VALUE_CTIME
= 3 // Like VALUE_LASTMOD, but for last metadata change.
40 #ifndef WORDS_BIGENDIAN
41 inline std::uint32_t bswap32(std::uint32_t v
) {
42 # if HAVE_DECL___BUILTIN_BSWAP32
43 return __builtin_bswap32(v
);
44 # elif HAVE_DECL__BYTESWAP_ULONG
45 return _byteswap_ulong(v
);
47 return (v
<< 24) | ((v
& 0xff00) << 8) | ((v
>> 8) & 0xff00) | (v
>> 24);
52 inline std::uint32_t binary_string_to_int(const std::string
&s
)
54 if (s
.size() != 4) return static_cast<std::uint32_t>(-1);
56 std::memcpy(&v
, s
.data(), 4);
57 #ifndef WORDS_BIGENDIAN
63 inline std::string
int_to_binary_string(std::uint32_t v
)
65 #ifndef WORDS_BIGENDIAN
68 return std::string(reinterpret_cast<const char*>(&v
), 4);