Back to index

salome-med  6.5.0
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
SauvUtilities::ASCIIReader Class Reference

ASCII sauve file reader. More...

#include <SauvMedConvertor.hxx>

Inheritance diagram for SauvUtilities::ASCIIReader:
Inheritance graph
[legend]
Collaboration diagram for SauvUtilities::ASCIIReader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ASCIIReader (const char *fileName)
 Constructor of ASCII sauve file reader.
virtual ~ASCIIReader ()
 Close the file.
virtual bool isASCII () const
 Return true.
virtual bool open ()
 Try to open an ASCII file.
virtual bool getNextLine (char *&line, bool raiseOEF=true)
 Return a next line of the file.
virtual void initNameReading (int nbValues, int width=8)
 Prepare for iterating over given nb of string values.
virtual void initIntReading (int nbValues)
 Prepare for iterating over given nb of integer values.
virtual void initDoubleReading (int nbValues)
 Prepare for iterating over given nb of real values.
virtual bool more () const
 Return true if not all values have been read.
virtual void next ()
 Go to the nex value.
virtual int getInt () const
 Return the current integer value.
virtual float getFloat () const
 Return the current float value.
virtual double getDouble () const
 Return the current double value.
virtual std::string getName () const
 Return the current string value.
int lineNb () const
virtual int index () const
def incrRef
def getHiddenCppPointer

Protected Attributes

std::string _fileName
std::string _curLocale
int _iRead
int _nbToRead

Private Member Functions

bool getLine (char *&line)
 Read a next line of the file if necessary.
void init (int nbToRead, int nbPosInLine, int width, int shift=0)
 Prepare for iterating over given nb of values.

Private Attributes

int _file
char * _start
char * _ptr
char * _eptr
int _lineNb
int _iPos
int _nbPosInLine
int _width
int _shift
char * _curPos

Detailed Description

ASCII sauve file reader.

Definition at line 308 of file SauvMedConvertor.hxx.


Constructor & Destructor Documentation

ASCIIReader::ASCIIReader ( const char *  fileName)

Constructor of ASCII sauve file reader.

Definition at line 453 of file SauvMedConvertor.cxx.

Close the file.

Definition at line 504 of file SauvMedConvertor.cxx.

{
  if (_file >= 0)
    {
      ::close (_file);
      if (_start != 0L)
        {
          delete [] _start;
          //delete [] _tmpBuf;
          _start = 0;
        }
      _file = -1;
    }
}

Member Function Documentation

double ASCIIReader::getDouble ( ) const [virtual]

Return the current double value.

Implements SauvUtilities::FileReader.

Definition at line 756 of file SauvMedConvertor.cxx.

{
  //std::string aStr (_curPos);

  // Correction: add missing 'E' specifier
  // int aPosStart = aStr.find_first_not_of(" \t");
  // if (aPosStart < (int)aStr.length()) {
  //   int aPosSign = aStr.find_first_of("+-", aPosStart + 1); // pass the leading symbol, as it can be a sign
  //   if (aPosSign < (int)aStr.length()) {
  //     if (aStr[aPosSign - 1] != 'e' && aStr[aPosSign - 1] != 'E')
  //       aStr.insert(aPosSign, "E", 1);
  //   }
  // }

  // Different Correction (more optimal)
  // Sample:
  //  0.00000000000000E+00 -2.37822406690632E+01  6.03062748797469E+01
  //  7.70000000000000-100  7.70000000000000+100  7.70000000000000+100
  //0123456789012345678901234567890123456789012345678901234567890123456789
  const size_t posE = 18;
  if ( _curPos[posE] != 'E' && _curPos[posE] != 'e' )
    {
      std::string aStr (_curPos);
      if ( aStr.size() < posE+1 )
        THROW_IK_EXCEPTION("No more doubles (line #" << lineNb() << ")");
      aStr.insert( posE, "E", 1 );
      return atof(aStr.c_str());
    }
  return atof( _curPos );
}

Here is the call graph for this function:

Here is the caller graph for this function:

float ASCIIReader::getFloat ( ) const [virtual]

Return the current float value.

Implements SauvUtilities::FileReader.

Definition at line 745 of file SauvMedConvertor.cxx.

{
  return getDouble();
}

Here is the call graph for this function:

getHiddenCppPointer(self) -> string

1

Definition at line 345 of file ParaMEDMEM.py.

00345 
00346     def getHiddenCppPointer(self):
00347         """
00348         getHiddenCppPointer(self) -> string
00349 
00350         1
00351         """
00352         return _ParaMEDMEM.RefCountObject_getHiddenCppPointer(self)

int ASCIIReader::getInt ( ) const [virtual]

Return the current integer value.

Implements SauvUtilities::FileReader.

Definition at line 722 of file SauvMedConvertor.cxx.

{
  // fix for two glued ints (issue 0021009):
  // Line nb    |   File contents
  // ------------------------------------------------------------------------------------
  // 53619905   |       1       2       6       8
  // 53619906   |                                                                SCALAIRE
  // 53619907   |    -63312600499       1       0       0       0      -2       0       2
  //   where -63312600499 is actualy -633 and 12600499
  char hold=_curPos[_width];
  _curPos[_width] = '\0';
  int result = atoi( _curPos );
  _curPos[_width] = hold;
  return result;
  //return atoi(str());
}
bool ASCIIReader::getLine ( char *&  line) [private]

Read a next line of the file if necessary.

Definition at line 539 of file SauvMedConvertor.cxx.

{
  bool aResult = true;
  // Check the state of the buffer;
  // if there is too little left, read the next portion of data
  int nBytesRest = _eptr - _ptr;
  if (nBytesRest < GIBI_MaxOutputLen)
    {
      if (nBytesRest > 0)
        {
          // move the remaining portion to the buffer beginning
          for ( int i = 0; i < nBytesRest; ++i )
            _start[i] = _ptr[i];
          //memcpy (_tmpBuf, _ptr, nBytesRest);
          //memcpy (_start, _tmpBuf, nBytesRest);
        }
      else
        {
          nBytesRest = 0;
        }
      _ptr = _start;
      const int nBytesRead = ::read (_file,
                                     &_start [nBytesRest],
                                     GIBI_BufferSize - nBytesRest);
      nBytesRest += nBytesRead;
      _eptr = &_start [nBytesRest];
    }
  // Check the buffer for the end-of-line
  char * ptr = _ptr;
  while (true)
    {
      // Check for end-of-the-buffer, the ultimate criterion for termination
      if (ptr >= _eptr)
        {
          if (nBytesRest <= 0)
            aResult = false;
          else
            _eptr[-1] = '\0';
          break;
        }
      // seek the line-feed character
      if (ptr[0] == '\n')
        {
          if (ptr[-1] == '\r')
            ptr[-1] = '\0';
          ptr[0] = '\0';
          ++ptr;
          break;
        }
      ++ptr;
    }
  // Output the result
  line = _ptr;
  _ptr = ptr;
  _lineNb++;

  return aResult;
}

Here is the caller graph for this function:

string ASCIIReader::getName ( ) const [virtual]

Return the current string value.

Implements SauvUtilities::FileReader.

Definition at line 793 of file SauvMedConvertor.cxx.

{
  int len = _width;
  while (( _curPos[len-1] == ' ' || _curPos[len-1] == 0) && len > 0 )
    len--;
  return string( _curPos, len );
}
bool ASCIIReader::getNextLine ( char *&  line,
bool  raiseOEF = true 
) [virtual]

Return a next line of the file.

Implements SauvUtilities::FileReader.

Definition at line 525 of file SauvMedConvertor.cxx.

{
  if ( getLine( line )) return true;
  if ( raiseOEF )
    THROW_IK_EXCEPTION("Unexpected EOF on ln "<<_lineNb);
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

def ParaMEDMEM.RefCountObject.incrRef (   self) [inherited]
incrRef(self)

1

Definition at line 337 of file ParaMEDMEM.py.

00337 
00338     def incrRef(self):
00339         """
00340         incrRef(self)
00341 
00342         1
00343         """
00344         return _ParaMEDMEM.RefCountObject_incrRef(self)

virtual int SauvUtilities::FileReader::index ( ) const [inline, virtual, inherited]

Definition at line 107 of file SauvUtilities.hxx.

{ return _iRead; }

Here is the caller graph for this function:

void ASCIIReader::init ( int  nbToRead,
int  nbPosInLine,
int  width,
int  shift = 0 
) [private]

Prepare for iterating over given nb of values.

Parameters:
nbToRead- nb of fields to read
nbPosInLine- nb of fields in one line
width- field width
shift- shift from line beginning to the field start

Definition at line 608 of file SauvMedConvertor.cxx.

{
  _nbToRead    = nbToRead;
  _nbPosInLine = nbPosInLine;
  _width       = width;
  _shift       = shift;
  _iPos = _iRead = 0;
  if ( _nbToRead )
    {
      getNextLine( _curPos );
      _curPos = _curPos + _shift;
    }
  else
    {
      _curPos = 0;
    }
  _curLocale.clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ASCIIReader::initDoubleReading ( int  nbValues) [virtual]

Prepare for iterating over given nb of real values.

Implements SauvUtilities::FileReader.

Definition at line 655 of file SauvMedConvertor.cxx.

{
  init( nbValues, 3, 22 );

  // Correction 2 of getDouble(): set "C" numeric locale to read numbers
  // with dot decimal point separator, as it is in SAUVE files
  _curLocale = setlocale(LC_NUMERIC, "C");
}

Here is the call graph for this function:

void ASCIIReader::initIntReading ( int  nbValues) [virtual]

Prepare for iterating over given nb of integer values.

Implements SauvUtilities::FileReader.

Definition at line 644 of file SauvMedConvertor.cxx.

{
  init( nbValues, 10, 8 );
}

Here is the call graph for this function:

void ASCIIReader::initNameReading ( int  nbValues,
int  width = 8 
) [virtual]

Prepare for iterating over given nb of string values.

Implements SauvUtilities::FileReader.

Definition at line 633 of file SauvMedConvertor.cxx.

{
  init( nbValues, 72 / ( width + 1 ), width, 1 );
}

Here is the call graph for this function:

bool ASCIIReader::isASCII ( ) const [virtual]

Return true.

Implements SauvUtilities::FileReader.

Definition at line 465 of file SauvMedConvertor.cxx.

{
  return true;
}
int SauvUtilities::ASCIIReader::lineNb ( ) const [inline]

Definition at line 325 of file SauvMedConvertor.hxx.

{ return _lineNb; }

Here is the caller graph for this function:

bool ASCIIReader::more ( ) const [virtual]

Return true if not all values have been read.

Implements SauvUtilities::FileReader.

Definition at line 670 of file SauvMedConvertor.cxx.

{
  bool result = false;
  if ( _iRead < _nbToRead)
    {
      if ( _curPos ) result = true;
    }
  return result;
}

Here is the caller graph for this function:

void ASCIIReader::next ( ) [virtual]

Go to the nex value.

Implements SauvUtilities::FileReader.

Definition at line 686 of file SauvMedConvertor.cxx.

{
  if ( !more() )
    THROW_IK_EXCEPTION("SauvUtilities::ASCIIReader::next(): no more() values to read");
  ++_iRead;
  ++_iPos;
  if ( _iRead < _nbToRead )
    {
      if ( _iPos >= _nbPosInLine )
        {
          getNextLine( _curPos );
          _curPos = _curPos + _shift;
          _iPos = 0;
        }
      else
        {
          _curPos = _curPos + _width + _shift;
        }
    }
  else
    {
      _curPos = 0;
      if ( !_curLocale.empty() )
        {
          setlocale(LC_NUMERIC, _curLocale.c_str());
          _curLocale.clear();
        }
    }
}

Here is the call graph for this function:

bool ASCIIReader::open ( ) [virtual]

Try to open an ASCII file.

Implements SauvUtilities::FileReader.

Definition at line 476 of file SauvMedConvertor.cxx.

{
#ifdef WNT
  _file = ::_open (_fileName.c_str(), _O_RDONLY|_O_BINARY);
#else
  _file = ::open (_fileName.c_str(), O_RDONLY);
#endif
  if (_file >= 0)
    {
      _start  = new char [GIBI_BufferSize]; // working buffer beginning
      //_tmpBuf = new char [GIBI_MaxOutputLen];
      _ptr    = _start;
      _eptr   = _start;
      _lineNb = 0;
    }
  else
    {
      //THROW_IK_EXCEPTION("Can't open file "<<_fileName << " fd: " << _file);
    }
  return (_file >= 0);
}

Member Data Documentation

std::string SauvUtilities::FileReader::_curLocale [protected, inherited]

Definition at line 114 of file SauvUtilities.hxx.

Definition at line 341 of file SauvMedConvertor.hxx.

Definition at line 336 of file SauvMedConvertor.hxx.

Definition at line 333 of file SauvMedConvertor.hxx.

std::string SauvUtilities::FileReader::_fileName [protected, inherited]

Definition at line 114 of file SauvUtilities.hxx.

Definition at line 340 of file SauvMedConvertor.hxx.

int SauvUtilities::FileReader::_iRead [protected, inherited]

Definition at line 115 of file SauvUtilities.hxx.

Definition at line 337 of file SauvMedConvertor.hxx.

Definition at line 340 of file SauvMedConvertor.hxx.

int SauvUtilities::FileReader::_nbToRead [protected, inherited]

Definition at line 115 of file SauvUtilities.hxx.

Definition at line 335 of file SauvMedConvertor.hxx.

Definition at line 340 of file SauvMedConvertor.hxx.

Definition at line 334 of file SauvMedConvertor.hxx.

Definition at line 340 of file SauvMedConvertor.hxx.


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