Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
base.hpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2 -*- */
2 /* Copyright(C) 2011 Brazil
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License version 2.1 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public
14  License along with this library; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef GRN_DAT_BASE_HPP_
19 #define GRN_DAT_BASE_HPP_
20 
21 #include "dat.hpp"
22 
23 namespace grn {
24 namespace dat {
25 
26 // The most significant bit represents whether or not the node is a linker.
27 // BASE of a linker represents the position of its associated key and BASE of
28 // a non-linker represents the offset to its child nodes.
30  public:
31  Base() : value_(0) {}
32 
33  bool operator==(const Base &rhs) const {
34  return value_ == rhs.value_;
35  }
36 
37  bool is_linker() const {
38  return (value_ & IS_LINKER_FLAG) == IS_LINKER_FLAG;
39  }
40  UInt32 offset() const {
41  GRN_DAT_DEBUG_THROW_IF(is_linker());
42  return value_;
43  }
44  UInt32 key_pos() const {
45  GRN_DAT_DEBUG_THROW_IF(!is_linker());
46  return value_ & ~IS_LINKER_FLAG;
47  }
48 
49  void set_offset(UInt32 x) {
50  GRN_DAT_DEBUG_THROW_IF((x & IS_LINKER_FLAG) != 0);
52  value_ = x;
53  }
54  void set_key_pos(UInt32 x) {
55  GRN_DAT_DEBUG_THROW_IF((x & IS_LINKER_FLAG) != 0);
57  value_ = IS_LINKER_FLAG | x;
58  }
59 
60  private:
61  UInt32 value_;
62 
63  static const UInt32 IS_LINKER_FLAG = 0x80000000U;
64 };
65 
66 } // namespace dat
67 } // namespace grn
68 
69 #endif // GRN_DAT_BASE_HPP_