#include <CDFootPrint.h>
Public Member Functions | |
CDFootPrint () | |
CDFootPrint (const CDFootPrint &) | |
virtual | ~CDFootPrint () |
const CDFootPrint & | operator= (const CDFootPrint &) |
const CDFootPrint & | operator+= (const CDFootPrint &aOtherPrint) |
CDFootPrint & | fresh () |
bool | operator== (const CDFootPrint &aOtherPrint) const |
bool | operator!= (const CDFootPrint &aOtherPrint) const |
CDFootPrint | operator+ (const CDFootPrint &aOtherPrint) const |
bool | overlap (const CDFootPrint &aOtherPrint) const |
bool | contains (const CDFootPrint &aOtherPrint) const |
uint32_t | ToUInt32 () const |
Static Public Member Functions | |
static void | reset () |
Private Member Functions | |
void | resize (const uint32_t aNewSize) |
Private Attributes | |
uint32_t | m_size |
uint32_t * | m_array |
Static Private Attributes | |
static uint32_t | m_numberIssued = 0 |
static uint32_t | m_numberFootprints = 0 |
Friends | |
class | FingerPrint |
std::ostream & | operator<< (std::ostream &os, const CDFootPrint &obj) |
Definition at line 80 of file CDFootPrint.h.
CDFootPrint::CDFootPrint | ( | ) |
Definition at line 106 of file CDFootPrint.cxx.
References m_numberFootprints.
00106 : 00107 m_size(0), 00108 m_array(0) 00109 { 00110 ++m_numberFootprints; 00111 }
CDFootPrint::CDFootPrint | ( | const CDFootPrint & | ) |
Definition at line 115 of file CDFootPrint.cxx.
References m_array, m_numberFootprints, m_size, and resize().
00115 : 00116 m_size(0) , 00117 m_array(0) 00118 { 00119 // 00120 // book the memory and copy contents of aOtherPrint 00121 // 00122 resize( aOtherPrint.m_size ); 00123 for ( uint32_t index = 0 ; 00124 index != m_size ; 00125 ++index ) { 00126 m_array[ index ] = aOtherPrint.m_array[ index ] ; 00127 } 00128 ++m_numberFootprints; 00129 }
CDFootPrint::~CDFootPrint | ( | ) | [virtual] |
Definition at line 133 of file CDFootPrint.cxx.
References m_array, m_numberFootprints, and reset().
00134 { 00135 // 00136 // delete memory 00137 // 00138 delete [] m_array ; 00139 if( 0 == --m_numberFootprints ) { 00140 reset(); 00141 } 00142 }
bool CDFootPrint::contains | ( | const CDFootPrint & | aOtherPrint | ) | const |
Definition at line 420 of file CDFootPrint.cxx.
References m_array, and m_size.
00421 { 00422 if (this == & aOtherPrint) { 00423 // 00424 // if being tested with itself return `true' 00425 // 00426 return(! false); 00427 } 00428 // 00429 // find the shortest length to compare the two memoery sections 00430 // 00431 uint32_t shorterSize ; 00432 if ( m_size > aOtherPrint.m_size ) { 00433 shorterSize = aOtherPrint.m_size ; 00434 } 00435 else { 00436 shorterSize = m_size ; 00437 } 00438 00439 // 00440 // for shorter CDFootPrint check aOtherPrint is within this one 00441 // 00442 uint32_t index = 0 ; 00443 while ( ( index != shorterSize ) && 00444 ( m_array[ index ] ==( m_array[index] | aOtherPrint.m_array[index] ) ) ) { 00445 ++index ; 00446 } 00447 // 00448 // if check finished before the shorter CDFootPrint was covered, 00449 // then aOtherPrint has at least one bit outside this CDFootPrint 00450 // 00451 if ( index != shorterSize ) { 00452 return ( false ) ; 00453 } 00454 // 00455 // if this CDFootPrint is the longer then aOtherPrint is totally contained 00456 // 00457 if ( m_size > aOtherPrint.m_size ) { 00458 return ( !false ) ; 00459 } 00460 // 00461 // as aOtherPrint is longer need to check rest of it is zero 00462 // 00463 while( ( index != aOtherPrint.m_size ) && 00464 (aOtherPrint.m_array[ index ] == uint32_t( 0 ) ) ) { 00465 ++index ; 00466 } 00467 // 00468 // if check finished before aOtherPrint was finished 00469 // then aOtherPrint has at least one bit in the rest of it 00470 // 00471 return ( aOtherPrint.m_size == index ) ; 00472 }
CDFootPrint & CDFootPrint::fresh | ( | ) |
Definition at line 234 of file CDFootPrint.cxx.
References m_array, m_numberIssued, m_size, and resize().
00235 { 00236 if ( m_size != 0 ) { 00237 // 00238 // if already assigned a value do nothing 00239 // 00240 return ( *this ) ; 00241 } 00242 00243 const uint32_t kBitsInByte = 8 ; 00244 // 00245 // Take a number and increase the number of CDFootPrints issued 00246 // 00247 uint32_t freshNumber = m_numberIssued++ ; 00248 // 00249 // calculate which bit, and which element to set 00250 // 00251 uint32_t element = freshNumber / ( kBitsInByte * sizeof( uint32_t ) ) ; 00252 uint32_t offsetInElement = freshNumber % ( kBitsInByte * sizeof( uint32_t ) ) ; 00253 // 00254 // book enough memory 00255 // 00256 resize( element + 1 ) ; 00257 // 00258 // fill all but the last part of the memory with zeros 00259 // 00260 for ( uint32_t index = 0 ; 00261 index < element ; 00262 ++index ) { 00263 m_array[ index ] = uint32_t( 0 ); 00264 } 00265 // 00266 // fill in last part of memory with correct bit set 00267 // 00268 m_array[ element ] = uint32_t(1) << offsetInElement ; 00269 return ( *this ) ; 00270 }
bool CDFootPrint::operator!= | ( | const CDFootPrint & | aOtherPrint | ) | const |
CDFootPrint CDFootPrint::operator+ | ( | const CDFootPrint & | aOtherPrint | ) | const |
Definition at line 373 of file CDFootPrint.cxx.
00374 { 00375 CDFootPrint result( *this ) ; 00376 result += aOtherPrint ; 00377 return ( result ) ; 00378 }
const CDFootPrint & CDFootPrint::operator+= | ( | const CDFootPrint & | aOtherPrint | ) |
Definition at line 168 of file CDFootPrint.cxx.
References m_array, and m_size.
00169 { 00170 if ( this == &aOtherPrint ) { 00171 // 00172 // if Footprint is added and assigned to itself do nothing. 00173 // 00174 return(*this); 00175 } 00176 if ( m_size >= aOtherPrint.m_size ) { 00177 // 00178 // if this Footprint is larger or equal than to aOtherPrint, 00179 // only `or' with the contents of aOtherPoint 00180 // 00181 for ( uint32_t index = 0 ; 00182 index != aOtherPrint.m_size ; 00183 ++index) { 00184 m_array[ index ] |= aOtherPrint.m_array[ index ] ; 00185 } 00186 } 00187 else { 00188 // 00189 // if this Footprint is smaller than to aOtherPrint book new memory 00190 // Note: can not use resize, as this thorws away old memory 00191 // 00192 uint32_t* tmp_ptr = new uint32_t[ aOtherPrint.m_size ]; 00193 if ( 0 == tmp_ptr ) { 00194 std::cerr << "No memory to allocate another kinematicData" << std::endl ; 00195 exit( 1 ) ; 00196 } 00197 // 00198 // for the length of the old memory, fill the new memory with 00199 // `or' of old and aOtherPrint 00200 // 00201 for ( uint32_t index_1 = 0 ; 00202 index_1 != m_size ; 00203 ++index_1 ) { 00204 tmp_ptr[ index_1 ] = m_array[ index_1 ] | aOtherPrint.m_array[ index_1 ] ; 00205 } 00206 // 00207 // for the rest of length of the new memory, fill with aOtherPrint 00208 // 00209 for ( uint32_t index_2 = m_size ; 00210 index_2 != aOtherPrint.m_size ; 00211 ++index_2) { 00212 tmp_ptr[ index_2 ] = aOtherPrint.m_array[ index_2 ] ; 00213 } 00214 // 00215 // delete old memory 00216 // 00217 delete [] m_array ; 00218 // 00219 // update member data elements 00220 // 00221 m_size = aOtherPrint.m_size; 00222 m_array = tmp_ptr ; 00223 } 00224 return ( *this ) ; 00225 }
const CDFootPrint & CDFootPrint::operator= | ( | const CDFootPrint & | ) |
Definition at line 148 of file CDFootPrint.cxx.
References m_array, m_size, and resize().
00149 { 00150 if ( this == &aOtherPrint ) { 00151 // 00152 // if Footprint is assigned to itself do nothing. 00153 // 00154 return( *this ) ; 00155 } 00156 // 00157 // book the memory and copy contents of aOtherPrint 00158 // 00159 resize( aOtherPrint.m_size ) ; 00160 for ( uint32_t index = 0 ; 00161 index != m_size ; 00162 ++index ) { 00163 m_array[ index ] = aOtherPrint.m_array[ index ] ; 00164 } 00165 return ( *this ) ; 00166 }
bool CDFootPrint::operator== | ( | const CDFootPrint & | aOtherPrint | ) | const |
Definition at line 310 of file CDFootPrint.cxx.
References m_array, and m_size.
00311 { 00312 if ( this == &aOtherPrint ) { 00313 // 00314 // if being compare with itself return `true' 00315 // 00316 return( !false ) ; 00317 } 00318 // 00319 // find the shortest length to compare the two memory sections 00320 // 00321 uint32_t shorterSize ; 00322 if ( m_size > aOtherPrint.m_size ) { 00323 shorterSize = aOtherPrint.m_size ; 00324 } 00325 else { 00326 shorterSize = m_size ; 00327 } 00328 // 00329 // check shorter CDFootPrint matches the section longer CDFootPrint 00330 // 00331 uint32_t index = 0; 00332 while ( ( index != shorterSize ) && 00333 ( m_array[ index ] == aOtherPrint.m_array[ index ] ) ) { 00334 ++index ; 00335 } 00336 // 00337 // if check finished before the shorter CDFootPrint was covered, 00338 // then two CDFootPrints are unequal 00339 // 00340 if ( index != shorterSize ) { 00341 return ( false ) ; 00342 } 00343 // 00344 // check that the rest of the longer footprint is zero 00345 // 00346 if ( m_size >= aOtherPrint.m_size ) { 00347 while ( ( index != m_size ) && 00348 ( m_array[ index ] == uint32_t( 0 ) ) ) { 00349 ++index ; 00350 } 00351 return ( m_size == index ); 00352 } 00353 else { 00354 while( ( index != aOtherPrint.m_size ) && 00355 (aOtherPrint.m_array[ index ] == uint32_t( 0 ) ) ) { 00356 ++index ; 00357 } 00358 return ( aOtherPrint.m_size == index ); 00359 } 00360 }
bool CDFootPrint::overlap | ( | const CDFootPrint & | aOtherPrint | ) | const |
Definition at line 384 of file CDFootPrint.cxx.
References m_array, and m_size.
Referenced by CDCandidate::overlap().
00385 { 00386 if (this == & aOtherPrint) { 00387 // 00388 // if being tested with itself return `true' 00389 // 00390 return( !false ); 00391 } 00392 // 00393 // find the shortest length to compare the two memoery sections 00394 // 00395 uint32_t shorterSize ; 00396 if ( m_size > aOtherPrint.m_size ) { 00397 shorterSize = aOtherPrint.m_size ; 00398 } 00399 else { 00400 shorterSize = m_size ; 00401 } 00402 // 00403 // check shorter CDFootPrint matches the section longer CDFootPrint 00404 // 00405 uint32_t index = 0; 00406 while ( ( index != shorterSize ) && 00407 ( 0 == ( m_array[ index ] & aOtherPrint.m_array[ index ] ) ) ) { 00408 ++index ; 00409 } 00410 // 00411 // if check finished before the shorter CDFootPrint was covered, 00412 // then two CDFootPrints have at least one bit in common 00413 // 00414 return ( index != shorterSize ) ; 00415 }
void CDFootPrint::reset | ( | ) | [static] |
Definition at line 481 of file CDFootPrint.cxx.
References m_numberIssued.
Referenced by ~CDFootPrint().
00482 { 00483 m_numberIssued = 0 ; 00484 }
void CDFootPrint::resize | ( | const uint32_t | aNewSize | ) | [private] |
Definition at line 277 of file CDFootPrint.cxx.
References m_array, and m_size.
Referenced by CDFootPrint(), fresh(), and operator=().
00278 { 00279 if ( aNewSize == m_size ) { 00280 // 00281 // if Footprint is already the right size do nothing. 00282 // 00283 return ; 00284 } 00285 // 00286 // allocate a new section of memory, and delete old section 00287 // 00288 uint32_t* tmp_ptr = new uint32_t[ aNewSize ] ; 00289 if ( 0 == tmp_ptr ) { 00290 std::cerr << "No memory to allocate another kinematicData" << std::endl ; 00291 exit( 1 ) ; 00292 } 00293 delete [] m_array ; 00294 // 00295 // update member data elements 00296 // 00297 m_size = aNewSize ; 00298 m_array = tmp_ptr ; 00299 // 00300 return ; 00301 }
uint32_t CDFootPrint::ToUInt32 | ( | ) | const [inline] |
friend class FingerPrint [friend] |
Definition at line 84 of file CDFootPrint.h.
std::ostream& operator<< | ( | std::ostream & | os, | |
const CDFootPrint & | obj | |||
) | [friend] |
uint32_t* CDFootPrint::m_array [private] |
Definition at line 122 of file CDFootPrint.h.
Referenced by CDFootPrint(), contains(), fresh(), operator+=(), operator<<(), operator=(), operator==(), overlap(), resize(), ToUInt32(), and ~CDFootPrint().
uint32_t CDFootPrint::m_numberFootprints = 0 [static, private] |
uint32_t CDFootPrint::m_numberIssued = 0 [static, private] |
uint32_t CDFootPrint::m_size [private] |
Definition at line 121 of file CDFootPrint.h.
Referenced by CDFootPrint(), contains(), fresh(), operator+=(), operator<<(), operator=(), operator==(), overlap(), and resize().