QuOc

 

Public Member Functions | Private Member Functions | Private Attributes

aol::ipfstream Class Reference
[Input]

#include <platformDependent.h>

Inherits ifstream.

List of all members.

Public Member Functions

 ipfstream (const char *name)
 ~ipfstream ()
void close ()

Private Member Functions

FILE * openFile (const char *FileName)

Private Attributes

bool isPipe
bool isTemp
FILE * f
charTempFileName

Detailed Description

pfstream is a GNU extension and therefore unknown to the intel compiler We supply a substitution here

Definition at line 187 of file platformDependent.h.


Constructor & Destructor Documentation

aol::ipfstream::ipfstream ( const char name  ) 

Definition at line 448 of file platformDependent.cpp.

References f.

                                        : ifstream ( f = openFile ( name ) ) {
  if ( !f ) throw Exception ( string ( "Could not open file " ) + name, __FILE__, __LINE__ );
}

aol::ipfstream::~ipfstream (  )  [inline]

Definition at line 213 of file platformDependent.h.

               {
    close();
  }


Member Function Documentation

void aol::ipfstream::close (  )  [inline]

Definition at line 217 of file platformDependent.h.

               {
#if !(__GNUC__ >= 3)
    ifstream::close();
#endif
#if __GNUC__ >=3
    // Detach before closing file/pipe
    rdbuf ( NULL );
    if ( buf ) {
      delete buf;
      buf = NULL;
    }
#endif
    if ( f ) {
#ifdef WIN32
      fclose ( f );
#else
      if ( isPipe ) pclose ( f );
      else fclose ( f );
#endif
      f = NULL;
#ifdef WIN32
      if ( isTemp ) {
        remove ( TempFileName );
        delete[] TempFileName;
      }
#endif // WIN32
    }
  }

FILE * aol::ipfstream::openFile ( const char FileName  )  [private]

Definition at line 357 of file platformDependent.cpp.

References f, aol::fileNameEndsWith(), isPipe, isTemp, and TempFileName.

                                                 {
#ifndef WIN32
  char fullCommand[4096];
#endif
  if ( fileNameEndsWith ( FileName, ".bz2" ) ) {
#ifdef WIN32
#ifdef USE_LIB_BZ2
    FILE *tempf;
    BZFILE *tempb;
    TempFileName = new char[256];
    unsigned char buf[200000];
    sprintf ( TempFileName, "%s.pgm", FileName );
    int bzerror;
    tempf = fopen ( FileName, "rb" );
    if ( !tempf ){
      string errorMessage = "Could not open bz2 file ";
      errorMessage += FileName;
      errorMessage += " for reading.\n";
      throw Exception ( errorMessage, __FILE__, __LINE__ );
    }
    ofstream tempfile ( TempFileName, ofstream::binary );
    if ( !tempfile )
      throw Exception ( "Could not open tempfile for decompressing.", __FILE__, __LINE__ );

    tempb = BZ2_bzReadOpen ( &bzerror, tempf, 0, 0, NULL, 0 );
    while ( bzerror == BZ_OK ) {
      const int bytesRead = BZ2_bzRead ( &bzerror, tempb, buf, sizeof ( buf ) );
      tempfile.write ( reinterpret_cast<char*> ( buf ), bytesRead );
    }
    tempfile.close();
    BZ2_bzReadClose ( &bzerror, tempb );
    fclose ( tempf );
    f = fopen ( TempFileName, "rb" );
    isPipe = false;
    isTemp = true;
#else
    throw Exception ( "Reading bz2 compressed files without using bzlib under windows is impossible", __FILE__, __LINE__ );
#endif // USE_LIB_BZ2
#else
    sprintf ( fullCommand, "bunzip2 -c %s 2>/dev/null", FileName );
    f = popen ( fullCommand, "r" );
    isPipe = true;
#endif // WIN32
  } else if ( fileNameEndsWith ( FileName, ".gz" ) ) {
#ifdef WIN32
    throw Exception ( "Reading gz compressed files under windows is not implemented", __FILE__, __LINE__ );
#else
    sprintf ( fullCommand, "gunzip -c %s 2>/dev/null", FileName );
    f = popen ( fullCommand, "r" );
    isPipe = true;
#endif // WIN32
  } else {
#ifdef WIN32
    f = fopen ( FileName, "rb" );
    isTemp = false;
#else
    f = fopen ( FileName, "r" );
#endif
    isPipe = false;
  }
  return f;
}


Member Data Documentation

FILE* aol::ipfstream::f [private]

Definition at line 200 of file platformDependent.h.

Referenced by ipfstream(), and openFile().

Definition at line 199 of file platformDependent.h.

Referenced by openFile().

Definition at line 199 of file platformDependent.h.

Referenced by openFile().

Definition at line 201 of file platformDependent.h.

Referenced by openFile().


The documentation for this class was generated from the following files:

Generated on Fri Sep 9 2011 21:09:13 for QuocMesh by doxygen 1.7.1