Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00039 #ifndef NAN_INCLUDED_CTR_TaggedIndex_h 00040 #define NAN_INCLUDED_CTR_TaggedIndex_h 00041 00051 #include <functional> 00052 00053 #include "MEM_sys_types.h" 00054 00055 enum { 00056 00057 empty_tag = 0x0, 00058 empty_index = 0xffffffff 00059 }; 00060 00061 template < 00062 int tag_shift, 00063 int index_mask 00064 > class CTR_TaggedIndex { 00065 public: 00066 CTR_TaggedIndex( 00067 ) : 00068 m_val ((empty_tag << tag_shift) | (empty_index & index_mask)) 00069 { 00070 } 00071 00072 CTR_TaggedIndex( 00073 const int val 00074 ) : 00075 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) { 00076 } 00077 00078 CTR_TaggedIndex( 00079 const unsigned int val 00080 ) : 00081 m_val ((val & index_mask) | ((empty_tag << tag_shift) & (~index_mask))) { 00082 } 00083 00084 CTR_TaggedIndex( 00085 const long int val 00086 ) : 00087 m_val ( ((long int) val & index_mask) 00088 | ( (empty_tag << tag_shift) 00089 & (~index_mask)) ) { 00090 } 00091 00092 CTR_TaggedIndex( 00093 const long unsigned int val 00094 ) : 00095 m_val ( ((long unsigned int)val & index_mask) 00096 | ( (empty_tag << tag_shift) 00097 & (~index_mask) ) ) { 00098 } 00099 00100 00101 #if defined(_WIN64) 00102 CTR_TaggedIndex( 00103 const uint64_t val 00104 ) : 00105 m_val ( ((uint64_t)val & index_mask) 00106 | ( (empty_tag << tag_shift) 00107 & (~index_mask) ) ) { 00108 } 00109 #endif 00110 00111 CTR_TaggedIndex( 00112 const CTR_TaggedIndex &my_index 00113 ): 00114 m_val(my_index.m_val) 00115 { 00116 } 00117 00118 bool 00119 operator == ( 00120 const CTR_TaggedIndex& rhs 00121 ) const { 00122 00123 return ((this->m_val & index_mask) == (rhs.m_val & index_mask)); 00124 } 00125 00126 operator unsigned int () const { 00127 return m_val & index_mask; 00128 } 00129 00130 operator unsigned long int () const { 00131 return (unsigned long int)(m_val & index_mask); 00132 } 00133 00134 operator int () const { 00135 return int(m_val & index_mask); 00136 } 00137 00138 operator long int () const { 00139 return (long int)(m_val & index_mask); 00140 } 00141 00142 #if defined(_WIN64) 00143 operator uint64_t () const { 00144 return (uint64_t)(m_val & index_mask); 00145 } 00146 #endif 00147 00148 bool 00149 IsEmpty( 00150 ) const { 00151 return ((m_val & index_mask) == (empty_index & index_mask)); 00152 } 00153 00154 00155 static 00156 CTR_TaggedIndex 00157 Empty( 00158 ) { 00159 return CTR_TaggedIndex(); 00160 } 00161 00162 void 00163 Invalidate( 00164 ) { 00165 m_val = (empty_tag << tag_shift) | (empty_index & index_mask); 00166 } 00167 00168 00169 unsigned int 00170 Tag ( 00171 ) const { 00172 return m_val >> tag_shift; 00173 } 00174 00175 void 00176 SetTag( 00177 unsigned int tag 00178 ) { 00179 m_val = (m_val & index_mask) | ((tag << tag_shift) & (~index_mask)); 00180 } 00181 00182 void 00183 EmptyTag( 00184 ) { 00185 m_val = (m_val & index_mask) | ((empty_tag << tag_shift) & (~index_mask)); 00186 } 00187 00188 bool 00189 IsEmptyTag( 00190 ) const { 00191 return (Tag() == Empty().Tag()); 00192 } 00193 00194 // functionals 00195 00196 struct greater : std::binary_function<CTR_TaggedIndex, CTR_TaggedIndex, bool> 00197 { 00198 bool 00199 operator()( 00200 const CTR_TaggedIndex& a, 00201 const CTR_TaggedIndex& b 00202 ) const { 00203 return (int(a) > int(b)); 00204 } 00205 }; 00206 00207 00208 private : 00209 CTR_TaggedIndex( 00210 const CTR_TaggedIndex *index 00211 ) {}; 00212 00213 unsigned int m_val; 00214 00215 00216 }; 00217 00218 #endif 00219