| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/image_processing/TePDIMatrix.hpp
Go to the documentation of this file.

    00001 /*
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright  2001, 2002, 2003 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular
    00017 purpose. The library provided hereunder is on an "as is" basis, and the
    00018 authors have no obligation to provide maintenance, support, updates,
    00019 enhancements, or modifications.
    00020 In no event shall INPE be held liable to any party
    00021 for direct, indirect, special, incidental, or consequential damages arising
    00022 out of the use of this library and its documentation.
    00023 */
    00024
    00025 #ifndef TEPDIMATRIX_HPP
    00026   #define TEPDIMATRIX_HPP
    00027
    00028   #include "../kernel/TeAgnostic.h"
    00029   #include "../kernel/TeSharedPtr.h"
    00030   #include "../kernel/TeTempFilesRemover.h"
    00031   #include "../kernel/TeUtils.h"
    00032
    00033   #include <string.h>
    00034
    00042   template< class ElementType >
    00043   class TePDIMatrix {
    00044     public :
    00047       typedef TeSharedPtr< TePDIMatrix< ElementType > > pointer;
    00048
    00052       enum MemoryPolicy
    00053       {
    00060         AutoMemPol,
    00064         RAMMemPol,
    00069         DiskMemPol
    00070       };
    00071
    00072       TePDIMatrix();
    00073
    00074       TePDIMatrix( const TePDIMatrix< ElementType >& external );
    00075
    00076       virtual ~TePDIMatrix();
    00077
    00084       void Reset();
    00085
    00093       void Reset( MemoryPolicy memoryPolicy );
    00094
    00104       bool Reset( unsigned int lines, unsigned int columns );
    00105
    00116       bool Reset( unsigned int lines, unsigned int columns,
    00117         MemoryPolicy memoryPolicy );
    00118
    00132       bool Reset( unsigned int lines, unsigned int columns,
    00133         MemoryPolicy memoryPolicy, unsigned long int maxTmpFileSize,
    00134         unsigned char maxMemPercentUsage );
    00135
    00140       void clear();
    00141
    00147       unsigned int GetLines() const;
    00148
    00154       unsigned int GetColumns() const;
    00155
    00161       bool IsEmpty() const;
    00162
    00171       const TePDIMatrix< ElementType >& operator=(
    00172         const TePDIMatrix< ElementType >& external );
    00173
    00181       inline ElementType& operator()( const unsigned int& line,
    00182         const unsigned int& column )
    00183       {
    00184         TEAGN_DEBUG_CONDITION( ( column < totalColumns_ ),
    00185           "Invalid columns" )
    00186
    00187         return getScanLine( line )[ column ];
    00188       };
    00189
    00197       inline const ElementType& operator()( const unsigned int& line,
    00198         const unsigned int& column ) const
    00199       {
    00200         TEAGN_DEBUG_CONDITION( ( column < totalColumns_ ),
    00201           "Invalid columns" )
    00202
    00203         return getScanLine( line )[ column ] ;
    00204       };
    00205
    00217       inline ElementType* operator[]( const unsigned int& line )
    00218       {
    00219         return getScanLine( line );
    00220       };
    00221
    00233       inline ElementType const* operator[]( const unsigned int& line ) const
    00234       {
    00235         return getScanLine( line );
    00236       };
    00237
    00242       MemoryPolicy getMemPolicy() const;
    00243
    00248       unsigned long int getMaxTmpFileSize() const;
    00249
    00250     protected :
    00251
    00255       class DiskLinesInfoNode
    00256       {
    00257         public :
    00258
    00259           FILE* filePtr_;
    00260           unsigned int fileOff_;
    00261
    00262           DiskLinesInfoNode() : filePtr_( 0 ), fileOff_( 0 ) {};
    00263           ~DiskLinesInfoNode() {};
    00264       };
    00265
    00269       class OpenDiskFilesInfoNode
    00270       {
    00271         public :
    00272
    00273           FILE* filePtr_;
    00274           char* fileName_;
    00275
    00276           OpenDiskFilesInfoNode() : filePtr_( 0 ), fileName_( 0 ) {};
    00277           ~OpenDiskFilesInfoNode() {};
    00278       };
    00279
    00283       unsigned long int maxTmpFileSize_;
    00284
    00289       unsigned char maxMemPercentUsage_;
    00290
    00294       unsigned int totalLines_;
    00295
    00299       unsigned int totalColumns_;
    00300
    00304       MemoryPolicy memoryPolicy_;
    00305
    00309       unsigned int lineSize_;
    00310
    00314       ElementType** allLinesPtrsVec_;
    00315
    00319       OpenDiskFilesInfoNode* openDiskFilesVec_;
    00320
    00324       unsigned int openDiskFilesVecSize_;
    00325
    00329       DiskLinesInfoNode* diskLinesVec_;
    00330
    00334       unsigned int* ramLinesIndexesVec_;
    00335
    00339       unsigned int ramLinesIndexesVecSize_;
    00340
    00346       mutable unsigned int nextSwapLineRamLinesIndexesVecIdx_;
    00347
    00352       mutable ElementType* swapLinePtr_;
    00353
    00357       void init();
    00358
    00364       bool allocateDiskLines( unsigned int startingLineIdx );
    00365
    00377       ElementType* getScanLine( const unsigned int& line ) const;
    00378
    00386       bool createNewDiskFile( unsigned long int size,
    00387         const std::string& filename, FILE** fileptr ) const;
    00388   };
    00389
    00390   template< class ElementType >
    00391   void TePDIMatrix< ElementType >::init()
    00392   {
    00393     maxTmpFileSize_ = 2ul * 1024ul * 1024ul * 1024ul;;
    00394     maxMemPercentUsage_ = 40;
    00395     totalLines_ = 0;
    00396     totalColumns_ = 0;
    00397     memoryPolicy_ = RAMMemPol;
    00398     lineSize_ = 0;
    00399     allLinesPtrsVec_ = 0;
    00400     openDiskFilesVec_ = 0;
    00401     openDiskFilesVecSize_ = 0;
    00402     diskLinesVec_ = 0;
    00403     ramLinesIndexesVec_ = 0;
    00404     ramLinesIndexesVecSize_ = 0;
    00405     nextSwapLineRamLinesIndexesVecIdx_ = 0;
    00406     swapLinePtr_ = 0;
    00407   }
    00408
    00409   template< class ElementType >
    00410   TePDIMatrix< ElementType >::TePDIMatrix()
    00411   {
    00412     init();
    00413   }
    00414
    00415   template< class ElementType >
    00416   TePDIMatrix< ElementType >::TePDIMatrix(
    00417     const TePDIMatrix< ElementType >& external )
    00418   {
    00419     init();
    00420
    00421     operator=( external );
    00422   }
    00423
    00424   template< class ElementType >
    00425     TePDIMatrix< ElementType >::~TePDIMatrix()
    00426   {
    00427     clear();
    00428   }
    00429
    00430   template< class ElementType >
    00431   void TePDIMatrix< ElementType >::Reset()
    00432   {
    00433     Reset( 0, 0, memoryPolicy_, maxTmpFileSize_, maxMemPercentUsage_ );
    00434   }
    00435
    00436   template< class ElementType >
    00437   void TePDIMatrix< ElementType >::Reset( MemoryPolicy memoryPolicy )
    00438   {
    00439     Reset( 0, 0, memoryPolicy, maxTmpFileSize_, maxMemPercentUsage_ );
    00440   }
    00441
    00442   template< class ElementType >
    00443   bool TePDIMatrix< ElementType >::Reset( unsigned int lines,
    00444     unsigned int columns )
    00445   {
    00446     return Reset( lines, columns, memoryPolicy_, maxTmpFileSize_,
    00447       maxMemPercentUsage_ );
    00448   }
    00449
    00450   template< class ElementType >
    00451   bool TePDIMatrix< ElementType >::Reset( unsigned int lines,
    00452     unsigned int columns, MemoryPolicy memoryPolicy )
    00453   {
    00454     return Reset( lines, columns, memoryPolicy, maxTmpFileSize_,
    00455       maxMemPercentUsage_ );
    00456   }
    00457
    00458   template< class ElementType >
    00459   bool TePDIMatrix< ElementType >::Reset( unsigned int lines,
    00460     unsigned int columns, MemoryPolicy memoryPolicy,
    00461     unsigned long int maxTmpFileSize,
    00462     unsigned char maxMemPercentUsage )
    00463   {
    00464     clear();
    00465
    00466     // Updating the global vars
    00467
    00468     maxTmpFileSize_ = maxTmpFileSize;
    00469     maxMemPercentUsage_ = maxMemPercentUsage;
    00470     memoryPolicy_ = memoryPolicy;
    00471
    00472     /* Update the old buffer if necessary */
    00473
    00474     if( ( lines > 0 ) && ( columns > 0 ) )
    00475     {
    00476       try
    00477       {
    00478         // Updating the global vars
    00479
    00480         totalLines_ = lines;
    00481         totalColumns_ = columns;
    00482         lineSize_ = sizeof( ElementType ) * totalColumns_;
    00483
    00484         // Allocating the lines pointers vectpr
    00485
    00486         allLinesPtrsVec_ = new ElementType*[ totalLines_ ];
    00487         if( allLinesPtrsVec_ == 0 )
    00488         {
    00489           clear();
    00490           TEAGN_LOG_AND_RETURN( "Tiles allocation error" )
    00491         }
    00492         else
    00493         {
    00494           for( unsigned int allLinesPtrsVecIdx = 0 ; allLinesPtrsVecIdx <
    00495             totalLines_ ; ++allLinesPtrsVecIdx )
    00496           {
    00497             allLinesPtrsVec_[ allLinesPtrsVecIdx ] = 0;
    00498           }
    00499         }
    00500
    00501         if( memoryPolicy_ == RAMMemPol )
    00502         {
    00503           for( unsigned int allLinesPtrsVecIdx = 0 ; allLinesPtrsVecIdx <
    00504             totalLines_ ; ++allLinesPtrsVecIdx )
    00505           {
    00506             allLinesPtrsVec_[ allLinesPtrsVecIdx ] =
    00507               new ElementType[ totalColumns_ ];
    00508
    00509             if( allLinesPtrsVec_[ allLinesPtrsVecIdx ] == 0 )
    00510             {
    00511               clear();
    00512               TEAGN_LOG_AND_RETURN( "Tiles allocation error" )
    00513             }
    00514           }
    00515         }
    00516         else
    00517         { // AutoMemPol, DiskMemPol
    00518
    00519           // Allocating the swap line pointer
    00520
    00521           swapLinePtr_ = new ElementType[ totalColumns_ ];
    00522           if( swapLinePtr_ == 0 )
    00523           {
    00524             clear();
    00525             TEAGN_LOG_AND_RETURN( "Swap line allocation error" )
    00526           }
    00527
    00528           // Defining the number of max RAM lines
    00529
    00530           unsigned int maxRAMLines = 1;
    00531
    00532           if( memoryPolicy_ == AutoMemPol )
    00533           {
    00534             // Defining the max number of RAM tiles
    00535
    00536             const double totalPhysMem = (double)TeGetTotalPhysicalMemory();
    00537
    00538             const double usedVMem = (double)TeGetUsedVirtualMemory();
    00539
    00540             const double totalVMem = (double)TeGetTotalVirtualMemory();
    00541
    00542             const double freeVMem = MIN( totalPhysMem,
    00543               ( totalVMem - usedVMem ) );
    00544
    00545             const double linesMem = ( ((double)maxMemPercentUsage_) / 100.0 ) *
    00546               freeVMem;
    00547
    00548             maxRAMLines = (unsigned int)MAX( 1, linesMem /
    00549               ((double)lineSize_) );
    00550           }
    00551
    00552           // Allocating RAM lines
    00553
    00554           ramLinesIndexesVecSize_ = MIN( maxRAMLines, totalLines_ );
    00555
    00556           ramLinesIndexesVec_ = new unsigned int[ ramLinesIndexesVecSize_ ];
    00557           if( ramLinesIndexesVec_ == 0 )
    00558           {
    00559             clear();
    00560             TEAGN_LOG_AND_RETURN( "Swap line allocation error" )
    00561           }
    00562
    00563           for( unsigned int allLinesPtrsVecIdx = 0 ; allLinesPtrsVecIdx <
    00564             ramLinesIndexesVecSize_ ; ++allLinesPtrsVecIdx )
    00565           {
    00566             allLinesPtrsVec_[ allLinesPtrsVecIdx ] =
    00567               new ElementType[ totalColumns_ ];
    00568
    00569             if( allLinesPtrsVec_[ allLinesPtrsVecIdx ] == 0 )
    00570             {
    00571               clear();
    00572               TEAGN_LOG_AND_RETURN( "Tiles allocation error" )
    00573             }
    00574             else
    00575             {
    00576               ramLinesIndexesVec_[ allLinesPtrsVecIdx ] =
    00577                 allLinesPtrsVecIdx;
    00578             }
    00579           }
    00580
    00581           // Allocating Disk lines
    00582
    00583           if( ! allocateDiskLines( ramLinesIndexesVecSize_ ) )
    00584           {
    00585             clear();
    00586             TEAGN_LOG_AND_RETURN( "Tiles allocation error" )
    00587           }
    00588         }
    00589       }
    00590       catch(...)
    00591       {
    00592         clear();
    00593
    00594         TEAGN_LOG_AND_RETURN( "Tiles allocation error" )
    00595       }
    00596     }
    00597
    00598     return true;
    00599   }
    00600
    00601   template< class ElementType >
    00602   void TePDIMatrix< ElementType >::clear()
    00603   {
    00604     if( allLinesPtrsVec_ )
    00605     {
    00606       for( unsigned int allLinesPtrsVecIdx = 0 ; allLinesPtrsVecIdx <
    00607         totalLines_ ; ++allLinesPtrsVecIdx )
    00608       {
    00609         if( allLinesPtrsVec_[ allLinesPtrsVecIdx ] )
    00610         {
    00611           delete[] allLinesPtrsVec_[ allLinesPtrsVecIdx ];
    00612         }
    00613       }
    00614
    00615       delete[] allLinesPtrsVec_;
    00616     }
    00617
    00618     if( openDiskFilesVec_ )
    00619     {
    00620       for( unsigned int openDiskFilesVecIdx = 0 ; openDiskFilesVecIdx <
    00621         openDiskFilesVecSize_ ; ++openDiskFilesVecIdx )
    00622       {
    00623         TeTempFilesRemover::instance().removeFile( openDiskFilesVec_[
    00624           openDiskFilesVecIdx ].fileName_ );
    00625         delete[] openDiskFilesVec_[ openDiskFilesVecIdx ].fileName_;
    00626       }
    00627
    00628       delete[] openDiskFilesVec_;
    00629     }
    00630
    00631     if( diskLinesVec_ ) delete[] diskLinesVec_;
    00632
    00633     if( ramLinesIndexesVec_ ) delete[] ramLinesIndexesVec_;
    00634
    00635     if( swapLinePtr_ ) delete[] swapLinePtr_;
    00636
    00637     init();
    00638   }
    00639
    00640   template< class ElementType >
    00641   unsigned int TePDIMatrix< ElementType >::GetLines() const
    00642   {
    00643     return totalLines_;
    00644   }
    00645
    00646
    00647   template< class ElementType >
    00648   unsigned int TePDIMatrix< ElementType >::GetColumns() const
    00649   {
    00650     return totalColumns_;
    00651   }
    00652
    00653
    00654   template< class ElementType >
    00655   bool TePDIMatrix< ElementType >::IsEmpty() const
    00656   {
    00657     return ( totalLines_ == 0 ) ? true : false;
    00658   }
    00659
    00660
    00661   template< class ElementType >
    00662   const TePDIMatrix< ElementType >& TePDIMatrix< ElementType >::operator=(
    00663     const TePDIMatrix< ElementType >& external )
    00664   {
    00665     TEAGN_TRUE_OR_THROW(
    00666       Reset( external.totalLines_, external.totalColumns_,
    00667       memoryPolicy_, maxTmpFileSize_, maxMemPercentUsage_ ),
    00668       "Unable to initiate the matrix object" );
    00669
    00670     unsigned int column = 0;;
    00671     ElementType const* inLinePtr = 0;
    00672     ElementType* outLinePtr = 0;
    00673
    00674     for( unsigned int line = 0 ; line < totalLines_ ; ++line )
    00675     {
    00676       inLinePtr = external.getScanLine( line );
    00677       outLinePtr = getScanLine( line );
    00678
    00679       for( column = 0 ; column < totalColumns_ ; ++column ) {
    00680         outLinePtr[ column ] = inLinePtr[ column ];
    00681       }
    00682     }
    00683
    00684     return *this;
    00685   }
    00686
    00687   template< class ElementType >
    00688   typename TePDIMatrix< ElementType >::MemoryPolicy TePDIMatrix< ElementType >::getMemPolicy() const
    00689   {
    00690     return memoryPolicy_;
    00691   }
    00692
    00693   template< class ElementType >
    00694   unsigned long int TePDIMatrix< ElementType >::getMaxTmpFileSize() const
    00695   {
    00696     return maxTmpFileSize_;
    00697   }
    00698
    00699   template< class ElementType >
    00700   bool TePDIMatrix< ElementType >::allocateDiskLines( unsigned int startingLineIdx )
    00701   {
    00702     const unsigned long int diskLinesNmb = totalLines_ - startingLineIdx;
    00703
    00704     if( diskLinesNmb )
    00705     {
    00706       const unsigned long int maxLinesPerFile = ( unsigned long int )
    00707         floor( ( (double)maxTmpFileSize_ ) / ( (double) lineSize_ ) );
    00708
    00709       const unsigned long int maxFileSize = (unsigned long int)
    00710         ( maxLinesPerFile * lineSize_ );
    00711
    00712       openDiskFilesVecSize_ = (unsigned int)ceil( ((double)diskLinesNmb)
    00713         / ((double)maxLinesPerFile) );
    00714
    00715       // Allocating the open disf files info vector
    00716
    00717       openDiskFilesVec_ = new OpenDiskFilesInfoNode[ openDiskFilesVecSize_ ];
    00718       if( openDiskFilesVec_ == 0 )
    00719       {
    00720         return false;
    00721       }
    00722
    00723       // Allocating the disk lines info vector
    00724
    00725       diskLinesVec_ = new DiskLinesInfoNode[ totalLines_ ];
    00726       if( diskLinesVec_ == 0 )
    00727       {
    00728         return false;
    00729       }
    00730
    00731       // Allocating each file
    00732
    00733       unsigned int remainingLinesNmb = diskLinesNmb;
    00734       unsigned int fileSize = 0;
    00735       unsigned int fileLinesNumber = 0;
    00736       OpenDiskFilesInfoNode auxFileData;
    00737       unsigned int diskLinesVecIdx = startingLineIdx;
    00738       std::string newTempFileName;
    00739
    00740       for( unsigned int fileIdx = 0 ; fileIdx < openDiskFilesVecSize_ ;
    00741         ++fileIdx )
    00742       {
    00743         // Defining the current file size
    00744
    00745         fileSize = maxFileSize;
    00746         fileLinesNumber = maxLinesPerFile;
    00747
    00748         if( remainingLinesNmb < maxLinesPerFile )
    00749         {
    00750           fileSize = (unsigned long int)( lineSize_ * remainingLinesNmb );
    00751           fileLinesNumber = remainingLinesNmb;
    00752         }
    00753
    00754         remainingLinesNmb -= fileLinesNumber;
    00755
    00756         // generating a temp file name
    00757
    00758         TEAGN_TRUE_OR_RETURN( TeGetTempFileName( newTempFileName ),
    00759           "Unable to get temporary file name" );
    00760
    00761         // allocating the file
    00762
    00763         if( ! createNewDiskFile( fileSize, newTempFileName,
    00764           &( auxFileData.filePtr_ ) ) )
    00765         {
    00766           TEAGN_LOGERR( "Unable to create temporary disk file" );
    00767           return false;
    00768         }
    00769         else
    00770         {
    00771           auxFileData.fileName_ = new char[ newTempFileName.size() + 1 ];
    00772           newTempFileName.copy( auxFileData.fileName_, newTempFileName.size(), 0 );
    00773           auxFileData.fileName_[ newTempFileName.size() ] = '\0';
    00774
    00775           openDiskFilesVec_[ fileIdx ] = auxFileData;
    00776
    00777           TeTempFilesRemover::instance().addFile( auxFileData.fileName_,
    00778             auxFileData.filePtr_ );
    00779
    00780           for( unsigned int lineIdx = 0; lineIdx < fileLinesNumber ; ++lineIdx )
    00781           {
    00782             diskLinesVec_[ diskLinesVecIdx ].filePtr_ = auxFileData.filePtr_;
    00783             diskLinesVec_[ diskLinesVecIdx ].fileOff_ = lineIdx * lineSize_;
    00784
    00785             ++diskLinesVecIdx;
    00786           }
    00787         }
    00788       }
    00789     }
    00790
    00791     return true;
    00792   }
    00793
    00794   template< class ElementType >
    00795   ElementType* TePDIMatrix< ElementType >::getScanLine( const unsigned int& line ) const
    00796   {
    00797     TEAGN_DEBUG_CONDITION( line < totalLines_, "Invalid tile index" );
    00798
    00799     if( allLinesPtrsVec_[ line ] )
    00800     {
    00801       return allLinesPtrsVec_[ line ];
    00802     }
    00803     else
    00804     {
    00805       // Finding the swap line index
    00806
    00807       TEAGN_DEBUG_CONDITION( nextSwapLineRamLinesIndexesVecIdx_ <
    00808         ramLinesIndexesVecSize_, "Internal error" );
    00809       unsigned int swapLineIdx = ramLinesIndexesVec_[
    00810         nextSwapLineRamLinesIndexesVecIdx_ ];
    00811
    00812       TEAGN_DEBUG_CONDITION( line < totalLines_, "Internal error" );
    00813       DiskLinesInfoNode& inLineData = diskLinesVec_[ line ];
    00814
    00815       TEAGN_DEBUG_CONDITION( swapLineIdx <
    00816         totalLines_, "Internal error" )
    00817       DiskLinesInfoNode& outLineData = diskLinesVec_[
    00818         swapLineIdx ];
    00819
    00820       /* Reading the required tile into RAM (swapTilePtr_) */
    00821
    00822       TEAGN_DEBUG_CONDITION( inLineData.filePtr_, "Internal error" );
    00823       TEAGN_TRUE_OR_THROW( 0 == fseek( inLineData.filePtr_,
    00824         (long)( inLineData.fileOff_ ), SEEK_SET ),
    00825         "File seek error" )
    00826
    00827       TEAGN_DEBUG_CONDITION( swapLinePtr_, "Internal error" );
    00828       TEAGN_TRUE_OR_THROW( 1 == fread( (void*)swapLinePtr_,
    00829         (size_t)( lineSize_ ), 1, inLineData.filePtr_ ),
    00830         "File read error" )
    00831
    00832       /* Flushing the swap tile to disk */
    00833
    00834       TEAGN_TRUE_OR_THROW( 0 == fseek( inLineData.filePtr_,
    00835         (long)( inLineData.fileOff_ ), SEEK_SET ),
    00836         "File seek error" );
    00837
    00838       TEAGN_DEBUG_CONDITION( swapLineIdx < totalLines_,
    00839         "Internal error" );
    00840       TEAGN_TRUE_OR_THROW( 1 == fwrite( (void*)allLinesPtrsVec_[
    00841         swapLineIdx ],
    00842         (size_t)( lineSize_ ), 1, inLineData.filePtr_ ),
    00843         "File write error" )
    00844
    00845       // Updating the tile pointers
    00846
    00847       ElementType* linePtr = allLinesPtrsVec_[ swapLineIdx ];
    00848
    00849       allLinesPtrsVec_[ swapLineIdx ] = 0;
    00850
    00851       allLinesPtrsVec_[ line ] = swapLinePtr_;
    00852
    00853       swapLinePtr_ = linePtr;
    00854
    00855       /* Updating the info vectors */
    00856
    00857       outLineData.filePtr_ = inLineData.filePtr_;
    00858       outLineData.fileOff_ = inLineData.fileOff_;
    00859
    00860       inLineData.filePtr_ = 0;
    00861       inLineData.fileOff_ = 0;
    00862
    00863       ramLinesIndexesVec_[ nextSwapLineRamLinesIndexesVecIdx_ ] =
    00864         line;
    00865       nextSwapLineRamLinesIndexesVecIdx_ =
    00866         ( ( nextSwapLineRamLinesIndexesVecIdx_ + 1 ) %
    00867         ramLinesIndexesVecSize_ );
    00868       TEAGN_DEBUG_CONDITION( nextSwapLineRamLinesIndexesVecIdx_ <
    00869         ramLinesIndexesVecSize_, "Internal error" );
    00870
    00871       return allLinesPtrsVec_[ line ];
    00872     }
    00873   }
    00874
    00875   template< class ElementType >
    00876   bool TePDIMatrix< ElementType >::createNewDiskFile( unsigned long int size,
    00877     const std::string& filename, FILE** fileptr ) const
    00878   {
    00879     TEAGN_TRUE_OR_RETURN( ! filename.empty(),
    00880       "Invalid file name" );
    00881
    00882     (*fileptr) = fopen( filename.c_str(), "wb+" );
    00883     TEAGN_TRUE_OR_RETURN( (*fileptr) != 0, "Invalid file pointer" )
    00884
    00885     long seekoff = (long)( size - 1 );
    00886
    00887     if( 0 != fseek( (*fileptr), seekoff, SEEK_SET ) )
    00888     {
    00889       fclose( (*fileptr) );
    00890       TEAGN_LOGERR( "File seek error" );
    00891       return false;
    00892     }
    00893
    00894     unsigned char c = '\0';
    00895     if( 1 != fwrite( &c, 1, 1, (*fileptr) ) )
    00896     {
    00897       fclose( (*fileptr) );
    00898       TEAGN_LOGERR( "File write error" );
    00899       return false;
    00900     }
    00901
    00902     return true;
    00903   }
    00904
    00905 #endif
    00906

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines