#include <RioMMIndex.h>
Data Structures | |
class | FileSection |
class | SlideSection |
Public Member Functions | |
CRioMMIndex (RioBlock, int, int, const char *) | |
~CRioMMIndex (void) | |
bool | InsertFile (const char *, RioBlock) |
bool | InsertSlide (int, int, RioBlock, RioBlock) |
bool | GetContext (RioBlock, TString &, int *, int *, RioBlock *) const |
ContextResult | ResetContext (RioBlock) |
ContextResult | UpdateContext (RioBlock, TString &, int *, int *, RioBlock *) |
const char * | GetArchiveName (void) const |
int | GetMajor (void) const |
int | GetMinor (void) const |
bool | IsValid (void) const |
Private Attributes | |
int | number_of_files |
int | number_of_slides |
int | major |
int | minor |
TString | archive_name |
FileSection * | first_file |
FileSection * | last_file |
FileSection * | current_file |
SlideSection * | current_slide |
Definition at line 37 of file RioMMIndex.h.
CRioMMIndex::CRioMMIndex | ( | RioBlock | idcs, | |
int | maj, | |||
int | min, | |||
const char * | arch | |||
) |
Definition at line 144 of file RioMMIndex.cpp.
00145 { 00146 #ifdef RIO_DEBUG2 00147 RioErr << "[RioMMIndex]: Entrei no construtor: idcs=" << idcs << endl; 00148 #endif 00149 00150 // number_of_indices = idcs; 00151 major = maj; 00152 minor = min; 00153 archive_name = arch; 00154 number_of_files = 0; 00155 number_of_slides = 0; 00156 first_file = NULL; 00157 last_file = NULL; 00158 current_file = NULL; 00159 current_slide = NULL; 00160 00161 #ifdef RIO_DEBUG2 00162 RioErr << "[RioMMIndex]: Saindo do construtor" << endl; 00163 #endif 00164 }
CRioMMIndex::~CRioMMIndex | ( | void | ) |
Definition at line 166 of file RioMMIndex.cpp.
00167 { 00168 if( first_file ) 00169 delete first_file; 00170 }
const char * CRioMMIndex::GetArchiveName | ( | void | ) | const |
Definition at line 515 of file RioMMIndex.cpp.
00516 { 00517 return (const char *)archive_name; 00518 }
bool CRioMMIndex::GetContext | ( | RioBlock | idx, | |
TString & | fname, | |||
int * | sld, | |||
int * | cmd, | |||
RioBlock * | cidx | |||
) | const |
Definition at line 320 of file RioMMIndex.cpp.
00322 { 00323 FileSection * temp_file; 00324 SlideSection * temp_slide; 00325 00326 if( number_of_files == 0 || idx < first_file->GetIndex( ) ) 00327 { 00328 #ifdef RIO_DEBUG2 00329 RioErr << "Index outside of slides range" << endl; 00330 #endif 00331 return false; 00332 } 00333 00334 for( temp_file = first_file; 00335 temp_file->GetNextFile( ) != NULL; 00336 temp_file = temp_file->GetNextFile( ) ) 00337 { 00338 if( idx < temp_file->GetNextFile( )->GetIndex( ) ) 00339 { 00340 break; 00341 } 00342 } 00343 00344 if( temp_file->GetFirstSlide( ) == NULL || 00345 idx < temp_file->GetFirstSlide( )->GetIndex( ) ) 00346 { 00347 return false; 00348 } 00349 00350 for( temp_slide = temp_file->GetFirstSlide( ); 00351 temp_slide->GetNextSlide( ) != NULL; 00352 temp_slide = temp_slide->GetNextSlide( ) ) 00353 { 00354 if( idx < temp_slide->GetNextSlide( )->GetIndex( ) ) 00355 { 00356 break; 00357 } 00358 } 00359 00360 fname = temp_file->GetFileName( ); 00361 *sld = temp_slide->GetSlideNumber( ); 00362 *cmd = temp_slide->GetCommands( ); 00363 *cidx = temp_slide->GetFirstCommandIndex( ); 00364 return true; 00365 }
int CRioMMIndex::GetMajor | ( | void | ) | const |
Definition at line 520 of file RioMMIndex.cpp.
00521 { 00522 return major; 00523 }
int CRioMMIndex::GetMinor | ( | void | ) | const |
Definition at line 525 of file RioMMIndex.cpp.
00526 { 00527 return minor; 00528 }
bool CRioMMIndex::InsertFile | ( | const char * | fname, | |
RioBlock | idx | |||
) |
Definition at line 172 of file RioMMIndex.cpp.
00173 { 00174 FileSection * new_file, 00175 * temp_file; 00176 00177 new_file = new FileSection( fname, idx ); 00178 /* Cannot allocate structure */ 00179 if( new_file == NULL ) 00180 { 00181 #ifdef RIO_DEBUG2 00182 RioErr << "Not enough memory" << endl; 00183 #endif 00184 return false; 00185 } 00186 00187 /* First insertion */ 00188 if( number_of_files == 0 ) 00189 { 00190 first_file = last_file = new_file; 00191 } 00192 /* Insertion at the end - most common case */ 00193 else if( idx > last_file->GetIndex( ) ) 00194 { 00195 last_file->SetNextFile( new_file ); 00196 last_file = new_file; 00197 } 00198 /* Insertion at the beginning - not so common case */ 00199 else if( idx < first_file->GetIndex( ) ) 00200 { 00201 new_file->SetNextFile( first_file ); 00202 first_file = new_file; 00203 } 00204 /* Insertion in the middle - unexpected, but allowed case */ 00205 else 00206 { 00207 for( temp_file = first_file; 00208 temp_file->GetNextFile( ) != NULL; 00209 temp_file = temp_file->GetNextFile( ) ) 00210 { 00211 if( idx < temp_file->GetNextFile( )->GetIndex( ) ) 00212 { 00213 new_file->SetNextFile( temp_file->GetNextFile( ) ); 00214 temp_file->SetNextFile( new_file ); 00215 break; 00216 } 00217 } 00218 if( temp_file->GetNextFile( ) == NULL ) 00219 { 00220 RioErr << "RioMMIndex - Unknown error" << endl; 00221 delete new_file; 00222 return false; 00223 } 00224 } 00225 00226 number_of_files++; 00227 return true; 00228 }
Definition at line 230 of file RioMMIndex.cpp.
00231 { 00232 FileSection * temp_file; 00233 SlideSection * new_slide, 00234 * temp_slide; 00235 00236 /* Insertion outside files */ 00237 if( number_of_files == 0 || idx < first_file->GetIndex( ) ) 00238 { 00239 RioErr << "RioMMIndex - Slides must be inserted within a file" << endl; 00240 return false; 00241 } 00242 00243 /* Insertion at last file - most common case */ 00244 if( idx > last_file->GetIndex( ) ) 00245 { 00246 temp_file = last_file; 00247 } 00248 /* Insertion in the middle - unexpected, but allowed case */ 00249 else 00250 { 00251 for( temp_file = first_file; 00252 temp_file->GetNextFile( ) != NULL; 00253 temp_file = temp_file->GetNextFile( ) ) 00254 { 00255 if( idx < temp_file->GetNextFile( )->GetIndex( ) ) 00256 { 00257 break; 00258 } 00259 } 00260 } 00261 00262 /* Create new slide section */ 00263 new_slide = new SlideSection( sld, idx, cmd, cidx ); 00264 /* Cannot allocate structure */ 00265 if( new_slide == NULL ) 00266 { 00267 RioErr << "RioMMIndex - Not enough memory" << endl; 00268 return false; 00269 } 00270 00271 /* First insertion in the file */ 00272 if( temp_file->GetFirstSlide( ) == NULL ) 00273 { 00274 temp_file->SetFirstSlide( new_slide ); 00275 temp_file->SetLastSlide( new_slide ); 00276 } 00277 /* Insertion at the end of the file - most common case */ 00278 else if( idx > temp_file->GetLastSlide( )->GetIndex( ) ) 00279 { 00280 temp_file->GetLastSlide( )->SetNextSlide( new_slide ); 00281 temp_file->SetLastSlide( new_slide ); 00282 } 00283 /* Insertion at the beginning - not so common case */ 00284 else if( idx < temp_file->GetFirstSlide( )->GetIndex( ) ) 00285 { 00286 new_slide->SetNextSlide( temp_file->GetFirstSlide( ) ); 00287 temp_file->SetFirstSlide( new_slide ); 00288 } 00289 /* Insertion in the middle - unexpected, but allowed case */ 00290 else 00291 { 00292 for( temp_slide = temp_file->GetFirstSlide( ); 00293 temp_slide->GetNextSlide( ) != NULL; 00294 temp_slide = temp_slide->GetNextSlide( ) ) 00295 { 00296 if( idx < temp_slide->GetNextSlide( )->GetIndex( ) ) 00297 { 00298 new_slide->SetNextSlide( temp_slide->GetNextSlide( ) ); 00299 temp_slide->SetNextSlide( new_slide ); 00300 break; 00301 } 00302 } 00303 if( temp_slide->GetNextSlide( ) == NULL ) 00304 { 00305 RioErr << "RioMMINDEX - Unknown error" << endl; 00306 delete new_slide; 00307 return false; 00308 } 00309 } 00310 00311 number_of_slides++; 00312 return true; 00313 }
bool CRioMMIndex::IsValid | ( | void | ) | const |
Definition at line 530 of file RioMMIndex.cpp.
00531 { 00532 FileSection * temp_file; 00533 00534 if( number_of_files < 1 ) 00535 return false; 00536 00537 for( temp_file = first_file; 00538 temp_file->GetNextFile( ) != NULL; 00539 temp_file = temp_file->GetNextFile( ) ) 00540 { 00541 if( temp_file->GetFirstSlide( ) == NULL ) 00542 return false; 00543 } 00544 00545 return true; 00546 }
ContextResult CRioMMIndex::ResetContext | ( | RioBlock | idx | ) |
Definition at line 372 of file RioMMIndex.cpp.
00373 { 00374 FileSection * temp_file; 00375 SlideSection * temp_slide; 00376 00377 if( number_of_files == 0 || idx < first_file->GetIndex( ) ) 00378 { 00379 #ifdef RIO_DEBUG2 00380 RioErr << "Index outside of slides range" << endl; 00381 #endif 00382 return CONTEXT_FAILED; 00383 } 00384 00385 for( temp_file = first_file; 00386 temp_file->GetNextFile( ) != NULL; 00387 temp_file = temp_file->GetNextFile( ) ) 00388 { 00389 if( idx < temp_file->GetNextFile( )->GetIndex( ) ) 00390 { 00391 break; 00392 } 00393 } 00394 00395 if( temp_file->GetFirstSlide( ) == NULL || 00396 idx < temp_file->GetFirstSlide( )->GetIndex( ) ) 00397 { 00398 return CONTEXT_FAILED; 00399 } 00400 00401 for( temp_slide = temp_file->GetFirstSlide( ); 00402 temp_slide->GetNextSlide( ) != NULL; 00403 temp_slide = temp_slide->GetNextSlide( ) ) 00404 { 00405 if( idx < temp_slide->GetNextSlide( )->GetIndex( ) ) 00406 { 00407 break; 00408 } 00409 } 00410 00411 current_file = temp_file; 00412 current_slide = temp_slide; 00413 return CONTEXT_CHANGED; 00414 }
ContextResult CRioMMIndex::UpdateContext | ( | RioBlock | idx, | |
TString & | fname, | |||
int * | sld, | |||
int * | cmd, | |||
RioBlock * | cidx | |||
) |
Definition at line 422 of file RioMMIndex.cpp.
00424 { 00425 FileSection * temp_file; 00426 SlideSection * temp_slide; 00427 ContextResult result; 00428 00429 if( current_file == NULL ) 00430 { 00431 result = ResetContext( idx ); 00432 if( result == CONTEXT_CHANGED ) 00433 { 00434 fname = current_file->GetFileName( ); 00435 *sld = current_slide->GetSlideNumber( ); 00436 *cmd = current_slide->GetCommands( ); 00437 *cidx = current_slide->GetFirstCommandIndex( ); 00438 } 00439 return result; 00440 } 00441 00442 if( number_of_files == 0 || idx < first_file->GetIndex( ) ) 00443 { 00444 #ifdef RIO_DEBUG2 00445 RioErr << "Index outside of slides range" << endl; 00446 #endif 00447 return CONTEXT_FAILED; 00448 } 00449 00450 // If the index is not before the current file 00451 // forward processing - the most common case for sequential access 00452 if( idx >= current_file->GetIndex( ) ) 00453 { 00454 temp_file = current_file; 00455 } 00456 else 00457 { 00458 temp_file = first_file; 00459 } 00460 00461 for( ; temp_file->GetNextFile( ) != NULL; 00462 temp_file = temp_file->GetNextFile( ) ) 00463 { 00464 if( idx < temp_file->GetNextFile( )->GetIndex( ) ) 00465 { 00466 break; 00467 } 00468 } 00469 00470 if( temp_file->GetFirstSlide( ) == NULL || 00471 idx < temp_file->GetFirstSlide( )->GetIndex( ) ) 00472 { 00473 #ifdef RIO_DEBUG2 00474 RioErr << "Found a file with no slides" << endl; 00475 #endif 00476 return CONTEXT_FAILED; 00477 } 00478 00479 // If the index is not before the current slide 00480 // forward processing - the most common case for sequential access 00481 if( temp_file == current_file && idx >= current_slide->GetIndex( ) ) 00482 { 00483 temp_slide = current_slide; 00484 } 00485 else 00486 { 00487 temp_slide = temp_file->GetFirstSlide( ); 00488 } 00489 00490 for( ; temp_slide->GetNextSlide( ) != NULL; 00491 temp_slide = temp_slide->GetNextSlide( ) ) 00492 { 00493 if( idx < temp_slide->GetNextSlide( )->GetIndex( ) ) 00494 { 00495 break; 00496 } 00497 } 00498 00499 fname = temp_file->GetFileName( ); 00500 *sld = temp_slide->GetSlideNumber( ); 00501 *cmd = temp_slide->GetCommands( ); 00502 *cidx = temp_slide->GetFirstCommandIndex( ); 00503 00504 if( temp_file == current_file && temp_slide == current_slide ) 00505 { 00506 return CONTEXT_NOTCHANGED; 00507 } 00508 00509 current_file = temp_file; 00510 current_slide = temp_slide; 00511 00512 return CONTEXT_CHANGED; 00513 }
TString CRioMMIndex::archive_name [private] |
Definition at line 91 of file RioMMIndex.h.
FileSection* CRioMMIndex::current_file [private] |
Definition at line 97 of file RioMMIndex.h.
SlideSection* CRioMMIndex::current_slide [private] |
Definition at line 98 of file RioMMIndex.h.
FileSection* CRioMMIndex::first_file [private] |
Definition at line 93 of file RioMMIndex.h.
FileSection * CRioMMIndex::last_file [private] |
Definition at line 93 of file RioMMIndex.h.
int CRioMMIndex::major [private] |
Definition at line 90 of file RioMMIndex.h.
int CRioMMIndex::minor [private] |
Definition at line 90 of file RioMMIndex.h.
int CRioMMIndex::number_of_files [private] |
Definition at line 87 of file RioMMIndex.h.
int CRioMMIndex::number_of_slides [private] |
Definition at line 88 of file RioMMIndex.h.