PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
PStream Class Reference

Deal with binary stream. More...

#include <PStream.h>

Public Member Functions

void close ()
 Close the stream. More...
 
bool isOpen () const
 Say if the stream is opened. More...
 
bool open (const PPath &fileName, const PString &mode="r")
 Open the current stream. More...
 
template<typename T >
PStreamoperator<< (const T &value)
 Flux operator for stream. More...
 
template<typename T >
PStreamoperator>> (T &value)
 Flux operator for stream. More...
 
 PStream ()
 Default constructor of PStream. More...
 
template<typename T >
bool read (T &value)
 Read a value from the stream. More...
 
template<typename T >
bool read (T *tabValue, size_t nbRow, size_t nbCol, size_t padding=0lu)
 Read a table values from the stream. More...
 
template<typename T >
bool read (T *tabValue, size_t nbValue)
 Read a value from the stream. More...
 
template<typename T >
bool write (const T &value)
 Write a value into the stream. More...
 
template<typename T >
bool write (const T *tabValue, size_t nbRow, size_t nbCol, size_t padding=0lu)
 Write a table values into the stream. More...
 
template<typename T >
bool write (const T *tabValue, size_t nbValue)
 Write a table values into the stream. More...
 
virtual ~PStream ()
 Destructor of PStream. More...
 

Private Member Functions

void initialisationPStream ()
 Initialisation function of the class PStream. More...
 

Private Attributes

FILE * p_fp
 Pointer to the main stream. More...
 

Detailed Description

Deal with binary stream.

Definition at line 14 of file PStream.h.

Constructor & Destructor Documentation

◆ PStream()

PStream::PStream ( )

Default constructor of PStream.

Definition at line 11 of file PStream.cpp.

11  {
13 }
void initialisationPStream()
Initialisation function of the class PStream.
Definition: PStream.cpp:47

References initialisationPStream().

+ Here is the call graph for this function:

◆ ~PStream()

PStream::~PStream ( )
virtual

Destructor of PStream.

Definition at line 16 of file PStream.cpp.

16  {
17  close();
18 }
void close()
Close the stream.
Definition: PStream.cpp:32

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

void PStream::close ( )

Close the stream.

Definition at line 32 of file PStream.cpp.

32  {
33  if(isOpen()){
34  fclose(p_fp);
35  p_fp = NULL;
36  }
37 }
FILE * p_fp
Pointer to the main stream.
Definition: PStream.h:51
bool isOpen() const
Say if the stream is opened.
Definition: PStream.cpp:42

References isOpen(), and p_fp.

Referenced by open(), testPStream(), testPStreamMatrix(), testPStreamTable(), and ~PStream().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialisationPStream()

void PStream::initialisationPStream ( )
private

Initialisation function of the class PStream.

Definition at line 47 of file PStream.cpp.

47  {
48  p_fp = NULL;
49 }

References p_fp.

Referenced by PStream().

+ Here is the caller graph for this function:

◆ isOpen()

bool PStream::isOpen ( ) const

Say if the stream is opened.

Returns
true if it is opened, false otherwise

Definition at line 42 of file PStream.cpp.

42  {
43  return p_fp != NULL;
44 }

References p_fp.

Referenced by close(), and open().

+ Here is the caller graph for this function:

◆ open()

bool PStream::open ( const PPath fileName,
const PString mode = "r" 
)

Open the current stream.

Parameters
fileName: name of the file to be used
mode: open mode, r : read only, write : write only, etc
Returns
true on success, false otherwise

Definition at line 25 of file PStream.cpp.

25  {
26  close();
27  p_fp = fopen(fileName.c_str(), mode.c_str());
28  return isOpen();
29 }

References close(), isOpen(), and p_fp.

Referenced by testPStream(), testPStreamMatrix(), and testPStreamTable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator<<()

template<typename T >
PStream & PStream::operator<< ( const T &  value)

Flux operator for stream.

Parameters
value: value to be put in the stream
Returns
modified stream

Definition at line 17 of file PStream_impl.h.

17  {
18  write(value);
19  return *this;
20 }
bool write(const T &value)
Write a value into the stream.
Definition: PStream_impl.h:37

References write().

+ Here is the call graph for this function:

◆ operator>>()

template<typename T >
PStream & PStream::operator>> ( T &  value)

Flux operator for stream.

Parameters
value: value to be read from the stream
Returns
modified stream

Definition at line 27 of file PStream_impl.h.

27  {
28  read(value);
29  return *this;
30 }
bool read(T &value)
Read a value from the stream.
Definition: PStream_impl.h:73

References read().

+ Here is the call graph for this function:

◆ read() [1/3]

template<typename T >
bool PStream::read ( T &  value)

Read a value from the stream.

Parameters
value: value to be read from the stream
Returns
true on success, false otherwise

Definition at line 73 of file PStream_impl.h.

73  {
74  return fread((void*)&value, sizeof(T), 1lu, p_fp) == 1lu;
75 }

References p_fp.

Referenced by operator>>(), read(), testPStreamMatrix(), and testPStreamTable().

+ Here is the caller graph for this function:

◆ read() [2/3]

template<typename T >
bool PStream::read ( T *  tabValue,
size_t  nbRow,
size_t  nbCol,
size_t  padding = 0lu 
)

Read a table values from the stream.

Parameters
tabValue: table of values to be read from the stream
nbRow: number of rows of the matrix
nbCol: number of columns of the matrix
padding: padding of the rows
Returns
true on success, false otherwise

Definition at line 94 of file PStream_impl.h.

94  {
95  bool b(true);
96  size_t rowSize(nbCol + padding);
97  for(size_t i(0lu); i < nbRow; ++i){
98  b &= read(tabValue + i*rowSize, nbCol);
99  }
100  return b;
101 }

References read().

+ Here is the call graph for this function:

◆ read() [3/3]

template<typename T >
bool PStream::read ( T *  tabValue,
size_t  nbValue 
)

Read a value from the stream.

Parameters
tabValue: table of values to be read from the stream
nbValue: number of values of the table

Definition at line 82 of file PStream_impl.h.

82  {
83  return fread((void*)tabValue, sizeof(T), nbValue, p_fp) == nbValue;
84 }

References p_fp.

◆ write() [1/3]

template<typename T >
bool PStream::write ( const T &  value)

Write a value into the stream.

Parameters
value: value to be written into the stream
Returns
true on success, false otherwise

Definition at line 37 of file PStream_impl.h.

37  {
38  return fwrite((const void*)&value, sizeof(T), 1lu, p_fp) == 1lu;
39 }

References p_fp.

Referenced by operator<<(), testPStreamMatrix(), testPStreamTable(), and write().

+ Here is the caller graph for this function:

◆ write() [2/3]

template<typename T >
bool PStream::write ( const T *  tabValue,
size_t  nbRow,
size_t  nbCol,
size_t  padding = 0lu 
)

Write a table values into the stream.

Parameters
tabValue: table of values to be written into the stream
nbRow: number of rows of the matrix
nbCol: number of columns of the matrix
padding: padding of the rows
Returns
true on success, false otherwise

Definition at line 59 of file PStream_impl.h.

59  {
60  bool b(true);
61  size_t rowSize(nbCol + padding);
62  for(size_t i(0lu); i < nbRow; ++i){
63  b &= write(tabValue + i*rowSize, nbCol);
64  }
65  return b;
66 }

References write().

+ Here is the call graph for this function:

◆ write() [3/3]

template<typename T >
bool PStream::write ( const T *  tabValue,
size_t  nbValue 
)

Write a table values into the stream.

Parameters
tabValue: table of values to be written into the stream
nbValue: number of values of the table
Returns
true on success, false otherwise

Definition at line 47 of file PStream_impl.h.

47  {
48  return fwrite((const void*)tabValue, sizeof(T), nbValue, p_fp) == nbValue;
49 }

References p_fp.

Member Data Documentation

◆ p_fp

FILE* PStream::p_fp
private

Pointer to the main stream.

Definition at line 51 of file PStream.h.

Referenced by close(), initialisationPStream(), isOpen(), open(), read(), and write().


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