00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #include <stdlib.h>
00073 #include <iostream>
00074
00075
00076 #include "BesDChain/CDFootPrint.h"
00077
00078
00079
00080
00081
00082
00083
00084
00085 uint32_t CDFootPrint::m_numberIssued = 0 ;
00086 uint32_t CDFootPrint::m_numberFootprints = 0 ;
00087
00088
00089 std::ostream& operator << ( std::ostream& os, const CDFootPrint& obj ) {
00090 os << "0x" << std::hex;
00091 for ( int i = obj.m_size-1; i >= 0; i-- ) {
00092 os << obj.m_array[i];
00093 }
00094 os << std::dec;
00095
00096 return os;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106 CDFootPrint::CDFootPrint() :
00107 m_size(0),
00108 m_array(0)
00109 {
00110 ++m_numberFootprints;
00111 }
00112
00113
00114
00115 CDFootPrint::CDFootPrint( const CDFootPrint& aOtherPrint ) :
00116 m_size(0) ,
00117 m_array(0)
00118 {
00119
00120
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 }
00130
00131
00132
00133 CDFootPrint::~CDFootPrint()
00134 {
00135
00136
00137
00138 delete [] m_array ;
00139 if( 0 == --m_numberFootprints ) {
00140 reset();
00141 }
00142 }
00143
00144
00145
00146
00147
00148 const CDFootPrint& CDFootPrint::operator=( const CDFootPrint& aOtherPrint )
00149 {
00150 if ( this == &aOtherPrint ) {
00151
00152
00153
00154 return( *this ) ;
00155 }
00156
00157
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 }
00167
00168 const CDFootPrint& CDFootPrint::operator+=( const CDFootPrint& aOtherPrint )
00169 {
00170 if ( this == &aOtherPrint ) {
00171
00172
00173
00174 return(*this);
00175 }
00176 if ( m_size >= aOtherPrint.m_size ) {
00177
00178
00179
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
00190
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
00199
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
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
00216
00217 delete [] m_array ;
00218
00219
00220
00221 m_size = aOtherPrint.m_size;
00222 m_array = tmp_ptr ;
00223 }
00224 return ( *this ) ;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234 CDFootPrint& CDFootPrint::fresh( void )
00235 {
00236 if ( m_size != 0 ) {
00237
00238
00239
00240 return ( *this ) ;
00241 }
00242
00243 const uint32_t kBitsInByte = 8 ;
00244
00245
00246
00247 uint32_t freshNumber = m_numberIssued++ ;
00248
00249
00250
00251 uint32_t element = freshNumber / ( kBitsInByte * sizeof( uint32_t ) ) ;
00252 uint32_t offsetInElement = freshNumber % ( kBitsInByte * sizeof( uint32_t ) ) ;
00253
00254
00255
00256 resize( element + 1 ) ;
00257
00258
00259
00260 for ( uint32_t index = 0 ;
00261 index < element ;
00262 ++index ) {
00263 m_array[ index ] = uint32_t( 0 );
00264 }
00265
00266
00267
00268 m_array[ element ] = uint32_t(1) << offsetInElement ;
00269 return ( *this ) ;
00270 }
00271
00272
00273
00274
00275
00276
00277 void CDFootPrint::resize( const uint32_t aNewSize )
00278 {
00279 if ( aNewSize == m_size ) {
00280
00281
00282
00283 return ;
00284 }
00285
00286
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
00296
00297 m_size = aNewSize ;
00298 m_array = tmp_ptr ;
00299
00300 return ;
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310 bool CDFootPrint::operator==(const CDFootPrint& aOtherPrint ) const
00311 {
00312 if ( this == &aOtherPrint ) {
00313
00314
00315
00316 return( !false ) ;
00317 }
00318
00319
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
00330
00331 uint32_t index = 0;
00332 while ( ( index != shorterSize ) &&
00333 ( m_array[ index ] == aOtherPrint.m_array[ index ] ) ) {
00334 ++index ;
00335 }
00336
00337
00338
00339
00340 if ( index != shorterSize ) {
00341 return ( false ) ;
00342 }
00343
00344
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 }
00361
00362
00363
00364
00365 bool CDFootPrint::operator!=( const CDFootPrint& aOtherPrint ) const
00366 {
00367 return ( ! operator == ( aOtherPrint ) ) ;
00368 }
00369
00370
00371
00372
00373 CDFootPrint CDFootPrint::operator+( const CDFootPrint& aOtherPrint ) const
00374 {
00375 CDFootPrint result( *this ) ;
00376 result += aOtherPrint ;
00377 return ( result ) ;
00378 }
00379
00380
00381
00382
00383
00384 bool CDFootPrint::overlap( const CDFootPrint& aOtherPrint) const
00385 {
00386 if (this == & aOtherPrint) {
00387
00388
00389
00390 return( !false );
00391 }
00392
00393
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
00404
00405 uint32_t index = 0;
00406 while ( ( index != shorterSize ) &&
00407 ( 0 == ( m_array[ index ] & aOtherPrint.m_array[ index ] ) ) ) {
00408 ++index ;
00409 }
00410
00411
00412
00413
00414 return ( index != shorterSize ) ;
00415 }
00416
00417
00418
00419
00420 bool CDFootPrint::contains( const CDFootPrint& aOtherPrint) const
00421 {
00422 if (this == & aOtherPrint) {
00423
00424
00425
00426 return(! false);
00427 }
00428
00429
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
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
00449
00450
00451 if ( index != shorterSize ) {
00452 return ( false ) ;
00453 }
00454
00455
00456
00457 if ( m_size > aOtherPrint.m_size ) {
00458 return ( !false ) ;
00459 }
00460
00461
00462
00463 while( ( index != aOtherPrint.m_size ) &&
00464 (aOtherPrint.m_array[ index ] == uint32_t( 0 ) ) ) {
00465 ++index ;
00466 }
00467
00468
00469
00470
00471 return ( aOtherPrint.m_size == index ) ;
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481 void CDFootPrint::reset()
00482 {
00483 m_numberIssued = 0 ;
00484 }
00485