OpenMD  2.5
Molecular Dynamics in the Open
OpenMD::ifstrstream Class Reference

ifstrstream class provides a stream interface to read data from files. More...

#include "io/ifstrstream.hpp"

Inheritance diagram for OpenMD::ifstrstream:

Public Types

typedef char char_type
 
typedef std::char_traits< char >::int_type int_type
 
typedef std::char_traits< char >::pos_type pos_type
 
typedef std::char_traits< char >::off_type off_type
 
typedef std::char_traits< char > traits_type
 
typedef std::basic_ios< char, std::char_traits< char > > _Basic_ios
 
typedef std::basic_istream< char, std::char_traits< char > > _Base
 
typedef std::basic_streambuf< char, std::char_traits< char > > _Buf
 
typedef std::basic_stringbuf< char, std::char_traits< char > > _StringBuf
 
typedef std::basic_filebuf< char, std::char_traits< char > > _FileBuf
 

Public Member Functions

 ifstrstream ()
 
 ifstrstream (const char *filename, std::ios_base::openmode mode=std::ios_base::in, bool checkFilename=false)
 
 ~ifstrstream ()
 
void open (const char *filename, std::ios_base::openmode mode=std::ios_base::in, bool checkFilename=false)
 
bool is_open ()
 
void close ()
 
_Bufrdbuf ()
 

Static Public Attributes

static const int FileNotExists = -1
 
static const int FileIOError = -2
 

Private Member Functions

bool internalOpen (const char *filename, std::ios_base::openmode mode, bool checkFilename)
 

Private Attributes

_StringBuf internalStringBuf_
 
_FileBuf internalFileBuf_
 
bool isRead
 

Detailed Description

ifstrstream class provides a stream interface to read data from files.

In single mode, it falls back to ifstream, as we don't need to read the whole file into memory. In parallel mode, the master node will read the whole file and broadcast it to other slave nodes. After broadcasting, every node will fall back to stringstream.

const int MAXLEN = 1024;
char buffer[MAXLEN];
in.open("Shapes.frc");
if (in.is_open()) {
in.getline(buffer, MAXLEN);
}
in.close();

Definition at line 81 of file ifstrstream.hpp.

Member Typedef Documentation

◆ _Base

typedef std::basic_istream<char, std::char_traits<char> > OpenMD::ifstrstream::_Base

Definition at line 91 of file ifstrstream.hpp.

◆ _Basic_ios

typedef std::basic_ios<char, std::char_traits<char> > OpenMD::ifstrstream::_Basic_ios

Definition at line 90 of file ifstrstream.hpp.

◆ _Buf

typedef std::basic_streambuf<char, std::char_traits<char> > OpenMD::ifstrstream::_Buf

Definition at line 92 of file ifstrstream.hpp.

◆ _FileBuf

typedef std::basic_filebuf<char, std::char_traits<char> > OpenMD::ifstrstream::_FileBuf

Definition at line 94 of file ifstrstream.hpp.

◆ _StringBuf

typedef std::basic_stringbuf<char, std::char_traits<char> > OpenMD::ifstrstream::_StringBuf

Definition at line 93 of file ifstrstream.hpp.

◆ char_type

Definition at line 84 of file ifstrstream.hpp.

◆ int_type

typedef std::char_traits<char>::int_type OpenMD::ifstrstream::int_type

Definition at line 85 of file ifstrstream.hpp.

◆ off_type

typedef std::char_traits<char>::off_type OpenMD::ifstrstream::off_type

Definition at line 87 of file ifstrstream.hpp.

◆ pos_type

typedef std::char_traits<char>::pos_type OpenMD::ifstrstream::pos_type

Definition at line 86 of file ifstrstream.hpp.

◆ traits_type

typedef std::char_traits<char> OpenMD::ifstrstream::traits_type

Definition at line 88 of file ifstrstream.hpp.

Constructor & Destructor Documentation

◆ ifstrstream() [1/2]

OpenMD::ifstrstream::ifstrstream ( )

Constructs an object of class ifstream.

Definition at line 60 of file ifstrstream.cpp.

References internalFileBuf_, internalStringBuf_, and isRead.

Referenced by ifstrstream().

◆ ifstrstream() [2/2]

OpenMD::ifstrstream::ifstrstream ( const char *  filename,
std::ios_base::openmode  mode = std::ios_base::in,
bool  checkFilename = false 
)
explicit

Explicit constructor

Parameters
filenameString containing the name of the file to be opened
modeFlags describing the requested i/o mode for the file, default value is ios_base::in
checkFilenameFlags indicating checking the file name in parallel

Definition at line 81 of file ifstrstream.cpp.

References ifstrstream(), internalFileBuf_, internalOpen(), internalStringBuf_, and isRead.

◆ ~ifstrstream()

OpenMD::ifstrstream::~ifstrstream ( )

virtual destructor will close the file(in single mode) and clear the stream buffer

virtual destructor will close the file (in single mode) and clear the stream buffer

Definition at line 100 of file ifstrstream.cpp.

References close().

Member Function Documentation

◆ close()

void OpenMD::ifstrstream::close ( )

In single mode, closes a file. The stream's file buffer is released from its association with the currently open file. In parallel mode, clean up.

In single mode, closes a file. The stream's file buffer is released from its association with the currently open file. In parallel mode, cleans up.

Definition at line 140 of file ifstrstream.cpp.

References internalFileBuf_, and isRead.

Referenced by OpenMD::ElementsTable::Init(), and ~ifstrstream().

◆ internalOpen()

bool OpenMD::ifstrstream::internalOpen ( const char *  filename,
std::ios_base::openmode  mode,
bool  checkFilename 
)
private

Internal function used to open the file

Returns
true if succesfully opens a file (single mode) or gets the file content (parallel mode) otherwise returns false
Parameters
filenameString containing the name of the file to be opened
modeFlags describing the requested i/o mode for the file
checkFilenameFlags indicating checking the file name in parallel
Todo:
use try - catch syntax to make the program more readable

Internal function used to open the file

Returns
true if succesfully opens a file (single mode) or gets the file content (parallel mode) otherwise return false
Parameters
filenameString containing the name of the file to be opened
modeFlags describing the requested i/o mode for the file
checkFilenameFlags indicating checking the file name in parallel
Todo:
use try - catch syntax to make the program more readable

Definition at line 173 of file ifstrstream.cpp.

References FileIOError, FileNotExists, internalFileBuf_, and internalStringBuf_.

Referenced by ifstrstream(), and open().

◆ is_open()

bool OpenMD::ifstrstream::is_open ( )

Tests if the stream is currently associated with a valid buffer.

Returns
true if a file has successfully been opened (single mode) or the whole file has been read and spread among all of the processors (parallel mode), otherwise false is returned

Definition at line 126 of file ifstrstream.cpp.

References internalFileBuf_, and isRead.

Referenced by OpenMD::ForceField::openForceFieldFile(), and OpenMD::ShapeAtomTypesSectionParser::parseShapeFile().

◆ open()

void OpenMD::ifstrstream::open ( const char *  filename,
std::ios_base::openmode  mode = std::ios_base::in,
bool  checkFilename = false 
)

Opens a file and associates a buffer with the specified file to perform the i/o operations (single mode). The master node reads a file and broadcasts its content to the other slave nodes. After broadcasting, all nodes fall back to stringstream (parallel mode).

Parameters
filenameString containing the name of the file to be opened
modeFlags describing the requested i/o mode for the file
checkFilenameFlags indicating checking the file name in parallel

Definition at line 113 of file ifstrstream.cpp.

References internalOpen(), and isRead.

Referenced by OpenMD::ElementsTable::Init(), OpenMD::ForceField::openForceFieldFile(), and OpenMD::ShapeAtomTypesSectionParser::parseShapeFile().

◆ rdbuf()

std::basic_streambuf< char, std::char_traits< char > > * OpenMD::ifstrstream::rdbuf ( )

Gets the stream buffer object associated with the stream

Returns
A pointer to the stream buffer object (filebuf in single mode, stringbuf in parallel mode) associated with the stream.

Gets the stream buffer object associated with the stream

Returns
A pointer to the stream buffer object(filebuf in single mode, stringbuf in parallel mode) associated with the stream.

Definition at line 155 of file ifstrstream.cpp.

References internalFileBuf_, and internalStringBuf_.

Member Data Documentation

◆ FileIOError

const int OpenMD::ifstrstream::FileIOError = -2
static

Definition at line 97 of file ifstrstream.hpp.

Referenced by internalOpen().

◆ FileNotExists

const int OpenMD::ifstrstream::FileNotExists = -1
static

Definition at line 96 of file ifstrstream.hpp.

Referenced by internalOpen().

◆ internalFileBuf_

_FileBuf OpenMD::ifstrstream::internalFileBuf_
private

internal stream buffer

Definition at line 169 of file ifstrstream.hpp.

Referenced by close(), ifstrstream(), internalOpen(), is_open(), and rdbuf().

◆ internalStringBuf_

_StringBuf OpenMD::ifstrstream::internalStringBuf_
private

Definition at line 168 of file ifstrstream.hpp.

Referenced by ifstrstream(), internalOpen(), and rdbuf().

◆ isRead

bool OpenMD::ifstrstream::isRead
private

internal stream buffer

Definition at line 170 of file ifstrstream.hpp.

Referenced by close(), ifstrstream(), is_open(), and open().


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