3 * ***** BEGIN GPL/BL DUAL 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. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL/BL DUAL LICENSE BLOCK *****
35 * Copyright (C) 2001 NaN Technologies B.V.
36 * Simple tagged index class.
39 #ifndef NAN_INCLUDED_CTR_TaggedIndex_h
40 #define NAN_INCLUDED_CTR_TaggedIndex_h
43 * This class is supposed to be a simple tagged index class. If these
44 * were indices into a mesh then we would never need 32 bits for such indices.
45 * It is often handy to have a few extra bits around to mark objects etc. We
46 * steal a few bits of CTR_TaggedIndex objects for this purpose. From the outside
47 * it will behave like a standard unsigned int but just carry the extra tag
48 * information around with it.
61 empty_index = 0xffffffff
67 > class CTR_TaggedIndex {
71 m_val ((empty_tag << tag_shift) | (empty_index & index_mask))
78 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) {
82 const unsigned int val
84 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) {
90 m_val ( ((long int) val & index_mask)
91 | ( (empty_tag << tag_shift)
96 const long unsigned int val
98 m_val ( ((long unsigned int)val & index_mask)
99 | ( (empty_tag << tag_shift)
100 & (~index_mask) ) ) {
105 const CTR_TaggedIndex &my_index
107 m_val(my_index.m_val)
113 const CTR_TaggedIndex& rhs
116 return ((this->m_val & index_mask) == (rhs.m_val & index_mask));
119 operator unsigned int () const {
120 return m_val & index_mask;
123 operator unsigned long int () const {
124 return (unsigned long int)(m_val & index_mask);
127 operator int () const {
128 return int(m_val & index_mask);
131 operator long int () const {
132 return (long int)(m_val & index_mask);
138 return ((m_val & index_mask) == (empty_index & index_mask));
146 return CTR_TaggedIndex();
152 m_val = (empty_tag << tag_shift) | (empty_index & index_mask);
159 return m_val >> tag_shift;
166 m_val = (m_val & index_mask) | ((tag << tag_shift) & (~index_mask));
172 m_val = (m_val & index_mask) | ((empty_tag << tag_shift) & (~index_mask));
178 return (Tag() == Empty().Tag());
183 struct greater : std::binary_function<CTR_TaggedIndex, CTR_TaggedIndex, bool>
187 const CTR_TaggedIndex& a,
188 const CTR_TaggedIndex& b
190 return (int(a) > int(b));
197 const CTR_TaggedIndex *index