3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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 Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
32 * Copyright (C) 2001 NaN Technologies B.V.
33 * Simple tagged index class.
36 #ifndef NAN_INCLUDED_CTR_TaggedIndex_h
37 #define NAN_INCLUDED_CTR_TaggedIndex_h
40 * This class is supposed to be a simple tagged index class. If these
41 * were indices into a mesh then we would never need 32 bits for such indices.
42 * It is often handy to have a few extra bits around to mark objects etc. We
43 * steal a few bits of CTR_TaggedIndex objects for this purpose. From the outside
44 * it will behave like a standard unsigned int but just carry the extra tag
45 * information around with it.
53 empty_index = 0xffffffff
59 > class CTR_TaggedIndex {
63 m_val ((empty_tag << tag_shift) | (empty_index & index_mask))
70 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) {
74 const unsigned int val
76 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) {
82 m_val ( ((long int) val & index_mask)
83 | ( (empty_tag << tag_shift)
88 const long unsigned int val
90 m_val ( ((long unsigned int)val & index_mask)
91 | ( (empty_tag << tag_shift)
98 const unsigned __int64 val
100 m_val ( ((unsigned __int64)val & index_mask)
101 | ( (empty_tag << tag_shift)
102 & (~index_mask) ) ) {
107 const CTR_TaggedIndex &my_index
109 m_val(my_index.m_val)
115 const CTR_TaggedIndex& rhs
118 return ((this->m_val & index_mask) == (rhs.m_val & index_mask));
121 operator unsigned int () const {
122 return m_val & index_mask;
125 operator unsigned long int () const {
126 return (unsigned long int)(m_val & index_mask);
129 operator int () const {
130 return int(m_val & index_mask);
133 operator long int () const {
134 return (long int)(m_val & index_mask);
138 operator unsigned __int64 () const {
139 return (unsigned __int64)(m_val & index_mask);
146 return ((m_val & index_mask) == (empty_index & index_mask));
154 return CTR_TaggedIndex();
160 m_val = (empty_tag << tag_shift) | (empty_index & index_mask);
167 return m_val >> tag_shift;
174 m_val = (m_val & index_mask) | ((tag << tag_shift) & (~index_mask));
180 m_val = (m_val & index_mask) | ((empty_tag << tag_shift) & (~index_mask));
186 return (Tag() == Empty().Tag());
191 struct greater : std::binary_function<CTR_TaggedIndex, CTR_TaggedIndex, bool>
195 const CTR_TaggedIndex& a,
196 const CTR_TaggedIndex& b
198 return (int(a) > int(b));
205 const CTR_TaggedIndex *index