OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
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

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

Public Member Functions

 ifstrstream ()
 Constructs an object of class ifstream.
 
 ifstrstream (const char *filename, std::ios_base::openmode mode=std::ios_base::in, bool checkFilename=false)
 Explicit constructor.
 
 ~ifstrstream ()
 virtual destructor will close the file(in single mode) and clear the stream buffer
 
void 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).
 
bool is_open ()
 Tests if the stream is currently associated with a valid buffer.
 
void close ()
 In single mode, closes a file.
 
_Buf * rdbuf ()
 Gets the stream buffer object associated with the stream.
 

Static Public Attributes

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

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 primary node will read the whole file and broadcast it to other secondary 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();
ifstrstream class provides a stream interface to read data from files.
void 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 mo...
bool is_open()
Tests if the stream is currently associated with a valid buffer.
void close()
In single mode, closes a file.

Definition at line 83 of file ifstrstream.hpp.

Member Typedef Documentation

◆ _Base

using OpenMD::ifstrstream::_Base = std::basic_istream<char, std::char_traits<char>>

Definition at line 93 of file ifstrstream.hpp.

◆ _Basic_ios

using OpenMD::ifstrstream::_Basic_ios = std::basic_ios<char, std::char_traits<char>>

Definition at line 92 of file ifstrstream.hpp.

◆ _Buf

using OpenMD::ifstrstream::_Buf = std::basic_streambuf<char, std::char_traits<char>>

Definition at line 94 of file ifstrstream.hpp.

◆ _FileBuf

using OpenMD::ifstrstream::_FileBuf = std::basic_filebuf<char, std::char_traits<char>>

Definition at line 96 of file ifstrstream.hpp.

◆ _StringBuf

using OpenMD::ifstrstream::_StringBuf = std::basic_stringbuf<char, std::char_traits<char>>

Definition at line 95 of file ifstrstream.hpp.

◆ char_type

using OpenMD::ifstrstream::char_type = char

Definition at line 86 of file ifstrstream.hpp.

◆ int_type

using OpenMD::ifstrstream::int_type = std::char_traits<char>::int_type

Definition at line 87 of file ifstrstream.hpp.

◆ off_type

using OpenMD::ifstrstream::off_type = std::char_traits<char>::off_type

Definition at line 89 of file ifstrstream.hpp.

◆ pos_type

using OpenMD::ifstrstream::pos_type = std::char_traits<char>::pos_type

Definition at line 88 of file ifstrstream.hpp.

◆ traits_type

using OpenMD::ifstrstream::traits_type = std::char_traits<char>

Definition at line 90 of file ifstrstream.hpp.

Constructor & Destructor Documentation

◆ ifstrstream() [1/2]

OpenMD::ifstrstream::ifstrstream ( )

Constructs an object of class ifstream.


Definition at line 62 of file ifstrstream.cpp.

◆ 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 83 of file ifstrstream.cpp.

◆ ~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 115 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.

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

Definition at line 159 of file ifstrstream.cpp.

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

◆ 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
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 145 of file ifstrstream.cpp.

Referenced by OpenMD::ElementsTable::Init().

◆ 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 primary node reads a file and broadcasts its content to the other secondary 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

The primary node reads a file and broadcasts its content to the secondary 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 127 of file ifstrstream.cpp.

Referenced by OpenMD::ElementsTable::Init().

◆ 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.
A pointer to the stream buffer object(filebuf in single mode, stringbuf in parallel mode) associated with the stream.

Definition at line 173 of file ifstrstream.cpp.

Member Data Documentation

◆ FileIOError

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

Definition at line 99 of file ifstrstream.hpp.

◆ FileNotExists

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

Definition at line 98 of file ifstrstream.hpp.


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