Back to index

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

XDR (binary) sauve file reader. More...

#include <SauvMedConvertor.hxx>

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

List of all members.

Public Member Functions

 XDRReader (const char *fileName)
 Constructor of a binary sauve file reader.
virtual ~XDRReader ()
 Close the XDR sauve file.
virtual bool isASCII () const
 Return false.
virtual bool open ()
 Try to open an XRD file.
virtual bool getNextLine (char *&line, bool raiseOEF=true)
 A stub.
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.
virtual int index () const
def incrRef
def getHiddenCppPointer

Protected Attributes

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

Private Types

enum  { _xdr_kind_null, _xdr_kind_char, _xdr_kind_int, _xdr_kind_double }

Private Member Functions

void init (int nbToRead, int width=0)
 Prepare for iterating over given nb of values.

Private Attributes

FILE * _xdrs_file
void * _xdrs
int * _xdr_ivals
double * _xdr_dvals
char * _xdr_cvals
int _width
int _xdr_kind

Detailed Description

XDR (binary) sauve file reader.

Definition at line 347 of file SauvMedConvertor.hxx.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
_xdr_kind_null 
_xdr_kind_char 
_xdr_kind_int 
_xdr_kind_double 

Definition at line 376 of file SauvMedConvertor.hxx.


Constructor & Destructor Documentation

XDRReader::XDRReader ( const char *  fileName)

Constructor of a binary sauve file reader.

Definition at line 807 of file SauvMedConvertor.cxx.

XDRReader::~XDRReader ( ) [virtual]

Close the XDR sauve file.

Definition at line 817 of file SauvMedConvertor.cxx.

{
#ifdef HAS_XDR  
  if ( _xdrs_file )
    {
      xdr_destroy((XDR*)_xdrs);
      free((XDR*)_xdrs);
      ::fclose(_xdrs_file);
      _xdrs_file = NULL;
    }
#endif
}

Member Function Documentation

double XDRReader::getDouble ( ) const [virtual]

Return the current double value.

Implements SauvUtilities::FileReader.

Definition at line 1049 of file SauvMedConvertor.cxx.

{
  if(_iRead < _nbToRead)
    {
      return _xdr_dvals[_iRead];
    }
  else
    {
      double result = 0;
#ifdef HAS_XDR
      xdr_double((XDR*)_xdrs, &result);
#endif
      return result;
    }
}
float XDRReader::getFloat ( ) const [virtual]

Return the current float value.

Implements SauvUtilities::FileReader.

Definition at line 1034 of file SauvMedConvertor.cxx.

{
  float result = 0;
#ifdef HAS_XDR
  xdr_float((XDR*)_xdrs, &result);
#endif
  return result;
}
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 XDRReader::getInt ( ) const [virtual]

Return the current integer value.

Implements SauvUtilities::FileReader.

Definition at line 1012 of file SauvMedConvertor.cxx.

{
  if(_iRead < _nbToRead)
    {
      return _xdr_ivals[_iRead];
    }
  else
    {
      int result = 0;
#ifdef HAS_XDR
      xdr_int((XDR*)_xdrs, &result);
#endif
      return result;
    }
}
std::string XDRReader::getName ( ) const [virtual]

Return the current string value.

Implements SauvUtilities::FileReader.

Definition at line 1071 of file SauvMedConvertor.cxx.

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

A stub.

Implements SauvUtilities::FileReader.

Definition at line 882 of file SauvMedConvertor.cxx.

{
  return true;
}
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 XDRReader::init ( int  nbToRead,
int  width = 0 
) [private]

Prepare for iterating over given nb of values.

Parameters:
nbToRead- nb of fields to read
width- field width

Definition at line 895 of file SauvMedConvertor.cxx.

{
  if(_iRead < _nbToRead)
    {
      cout << "_iRead, _nbToRead : " << _iRead << " " << _nbToRead << endl;
      cout << "Unfinished iteration before new one !" << endl;
      THROW_IK_EXCEPTION("SauvUtilities::XDRReader::init(): Unfinished iteration before new one !");
    }
  _iRead    = 0;
  _nbToRead = nbToRead;
  _width    = width;
}

Here is the caller graph for this function:

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

Prepare for iterating over given nb of real values.

Implements SauvUtilities::FileReader.

Definition at line 956 of file SauvMedConvertor.cxx.

{
  init( nbValues );
  _xdr_kind = _xdr_kind_double;
  if(nbValues)
    {
#ifdef HAS_XDR
      unsigned int nels = nbValues;
      unsigned int actual_nels;
      _xdr_dvals = (double*)malloc(nels*sizeof(double));
      xdr_array((XDR*)_xdrs, (char **)&_xdr_dvals, &actual_nels, nels, sizeof(double), (xdrproc_t)xdr_double);
#endif
    }
}

Here is the call graph for this function:

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

Prepare for iterating over given nb of integer values.

Implements SauvUtilities::FileReader.

Definition at line 935 of file SauvMedConvertor.cxx.

{
  init( nbValues );
  _xdr_kind = _xdr_kind_int;
  if(nbValues)
    {
#ifdef HAS_XDR
      unsigned int nels = nbValues;
      unsigned int actual_nels;
      _xdr_ivals = (int*)malloc(nels*sizeof(int));
      xdr_array((XDR*)_xdrs, (char **)&_xdr_ivals, &actual_nels, nels, sizeof(int), (xdrproc_t)xdr_int);
#endif
    }
}

Here is the call graph for this function:

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

Prepare for iterating over given nb of string values.

Implements SauvUtilities::FileReader.

Definition at line 914 of file SauvMedConvertor.cxx.

{
  init( nbValues, width );
  _xdr_kind = _xdr_kind_char;
  if(nbValues*width)
    {
      unsigned int nels = nbValues*width;
      _xdr_cvals = (char*)malloc((nels+1)*sizeof(char));
#ifdef HAS_XDR
      xdr_string((XDR*)_xdrs, &_xdr_cvals, nels);
#endif
      _xdr_cvals[nels] = '\0';
    }
}

Here is the call graph for this function:

bool XDRReader::isASCII ( ) const [virtual]

Return false.

Implements SauvUtilities::FileReader.

Definition at line 836 of file SauvMedConvertor.cxx.

{
  return false;
}
bool XDRReader::more ( ) const [virtual]

Return true if not all values have been read.

Implements SauvUtilities::FileReader.

Definition at line 977 of file SauvMedConvertor.cxx.

{
  return _iRead < _nbToRead;
}

Here is the caller graph for this function:

void XDRReader::next ( ) [virtual]

Go to the nex value.

Implements SauvUtilities::FileReader.

Definition at line 988 of file SauvMedConvertor.cxx.

{
  if ( !more() )
    THROW_IK_EXCEPTION("SauvUtilities::XDRReader::next(): no more() values to read");

  ++_iRead;
  if ( _iRead < _nbToRead )
    {
    }
  else
    {
      if(_xdr_kind == _xdr_kind_char) free(_xdr_cvals);
      if(_xdr_kind == _xdr_kind_int) free(_xdr_ivals);
      if(_xdr_kind == _xdr_kind_double) free(_xdr_dvals);
      _xdr_kind = _xdr_kind_null;
    }
}

Here is the call graph for this function:

bool XDRReader::open ( ) [virtual]

Try to open an XRD file.

Implements SauvUtilities::FileReader.

Definition at line 847 of file SauvMedConvertor.cxx.

{
  bool xdr_ok = false;
#ifdef HAS_XDR
  if ((_xdrs_file = ::fopen(_fileName.c_str(), "r")))
    {
      _xdrs = (XDR *)malloc(sizeof(XDR));
      xdrstdio_create((XDR*)_xdrs, _xdrs_file, XDR_DECODE);

      const int maxsize = 10;
      char icha[maxsize+1];
      char* icha2 = icha;
      if (( xdr_ok = xdr_string((XDR*)_xdrs, &icha2, maxsize)))
        {
          icha[maxsize] = '\0';
          xdr_ok = (strcmp(icha, "CASTEM XDR") == 0);
        }
      if ( !xdr_ok )
        {
          xdr_destroy((XDR*)_xdrs);
          free((XDR*)_xdrs);
          fclose(_xdrs_file);
          _xdrs_file = NULL;
        }
    }
#endif
  return xdr_ok;
}

Member Data Documentation

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

Definition at line 114 of file SauvUtilities.hxx.

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

Definition at line 114 of file SauvUtilities.hxx.

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

Definition at line 115 of file SauvUtilities.hxx.

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

Definition at line 115 of file SauvUtilities.hxx.

Definition at line 374 of file SauvMedConvertor.hxx.

Definition at line 373 of file SauvMedConvertor.hxx.

Definition at line 372 of file SauvMedConvertor.hxx.

Definition at line 371 of file SauvMedConvertor.hxx.

Definition at line 375 of file SauvMedConvertor.hxx.

Definition at line 370 of file SauvMedConvertor.hxx.

Definition at line 369 of file SauvMedConvertor.hxx.


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