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.
56 empty_index = 0xffffffff
62 > class CTR_TaggedIndex {
66 m_val ((empty_tag << tag_shift) | (empty_index & index_mask))
73 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) {
77 const unsigned int val
79 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) {
85 m_val ( ((long int) val & index_mask)
86 | ( (empty_tag << tag_shift)
91 const long unsigned int val
93 m_val ( ((long unsigned int)val & index_mask)
94 | ( (empty_tag << tag_shift)
100 const CTR_TaggedIndex &my_index
102 m_val(my_index.m_val)
108 const CTR_TaggedIndex& rhs
111 return ((this->m_val & index_mask) == (rhs.m_val & index_mask));
114 operator unsigned int () const {
115 return m_val & index_mask;
118 operator unsigned long int () const {
119 return (unsigned long int)(m_val & index_mask);
122 operator int () const {
123 return int(m_val & index_mask);
126 operator long int () const {
127 return (long int)(m_val & index_mask);
133 return ((m_val & index_mask) == (empty_index & index_mask));
141 return CTR_TaggedIndex();
147 m_val = (empty_tag << tag_shift) | (empty_index & index_mask);
154 return m_val >> tag_shift;
161 m_val = (m_val & index_mask) | ((tag << tag_shift) & (~index_mask));
167 m_val = (m_val & index_mask) | ((empty_tag << tag_shift) & (~index_mask));
173 return (Tag() == Empty().Tag());
178 struct greater : std::binary_function<CTR_TaggedIndex, CTR_TaggedIndex, bool>
182 const CTR_TaggedIndex& a,
183 const CTR_TaggedIndex& b
185 return (int(a) > int(b));
192 const CTR_TaggedIndex *index