63 std::basic_istream<char, std::char_traits<char>>(0), internalStringBuf_(),
65 this->init(&internalStringBuf_);
69 std::basic_istream<char, std::char_traits<char>>(0), internalFileBuf_(),
71 this->init(&internalFileBuf_);
85 std::basic_istream<char, std::char_traits<char>>(0),
86 internalStringBuf_(), isRead(false) {
87 this->init(&internalStringBuf_);
90 internalOpen(filename, mode | std::ios_base::in | std::ios_base::binary,
93 isRead = internalOpen(filename, mode | std::ios_base::in, checkFilename);
99 std::basic_istream<char, std::char_traits<char>>(0),
100 internalFileBuf_(), isRead(false) {
101 this->init(&internalFileBuf_);
104 internalOpen(filename, mode | std::ios_base::in | std::ios_base::binary,
107 isRead = internalOpen(filename, mode | std::ios_base::in, checkFilename);
128 bool checkFilename) {
132 internalOpen(filename, mode | std::ios_base::binary, checkFilename);
134 isRead = internalOpen(filename, mode, checkFilename);
150 return internalFileBuf_.is_open();
162 if (!internalFileBuf_.close()) this->setstate(std::ios_base::failbit);
175 return static_cast<_StringBuf*
>(&internalStringBuf_);
177 return static_cast<_FileBuf*
>(&internalFileBuf_);
191 bool ifstrstream::internalOpen(
const char* filename,
192 std::ios_base::openmode mode,
193 bool checkFilename) {
203 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
207 if (myRank == primaryNode) {
210 filenameLen = strlen(filename);
211 MPI_Bcast(&filenameLen, 1, MPI_INT, primaryNode, MPI_COMM_WORLD);
212 MPI_Bcast((
void*)filename, filenameLen, MPI_CHAR, primaryNode,
216 MPI_Allreduce(&diffFilename, &error, 1, MPI_INT, MPI_SUM,
220 if (error > 0)
return false;
223 std::ifstream fin(filename, mode);
226 fin.seekg(0, std::ios::end);
227 fileSize = fin.tellg();
228 fin.seekg(0, std::ios::beg);
231 fbuf =
new char[fileSize + 1];
235 fin.read(fbuf, fileSize);
237 if (fin.fail()) fileSize = FileIOError;
240 MPI_Bcast(&fileSize, 1, MPI_LONG, primaryNode, MPI_COMM_WORLD);
250 fbuf[fileSize] =
'\0';
251 MPI_Bcast(fbuf, fileSize + 1, MPI_CHAR, primaryNode, MPI_COMM_WORLD);
255 internalStringBuf_.str(fbuf);
258 fileSize = FileNotExists;
259 MPI_Bcast(&fileSize, 1, MPI_LONG, primaryNode, MPI_COMM_WORLD);
267 MPI_Bcast(&filenameLen, 1, MPI_INT, primaryNode, MPI_COMM_WORLD);
269 char* primaryFilename =
new char[filenameLen];
270 MPI_Bcast(primaryFilename, filenameLen, MPI_CHAR, primaryNode,
273 if (strcmp(primaryFilename, filename) == 0)
278 delete[] primaryFilename;
280 MPI_Allreduce(&diffFilename, &error, 1, MPI_INT, MPI_SUM,
283 if (error > 0)
return false;
286 MPI_Bcast(&fileSize, 1, MPI_LONG, primaryNode, MPI_COMM_WORLD);
289 fbuf =
new char[fileSize + 1];
293 MPI_Bcast(fbuf, fileSize + 1, MPI_CHAR, primaryNode, MPI_COMM_WORLD);
295 internalStringBuf_.str(fbuf);
298 }
else if (fileSize == FileNotExists) {
301 }
else if (fileSize == FileIOError) {
310 bool ifstrstream::internalOpen(
const char* filename,
311 std::ios_base::openmode mode,
bool) {
313 if (!internalFileBuf_.open(filename, mode)) {
314 this->setstate(std::ios_base::failbit);
_Buf * rdbuf()
Gets the stream buffer object associated with the stream.
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...
~ifstrstream()
virtual destructor will close the file(in single mode) and clear the stream buffer
bool is_open()
Tests if the stream is currently associated with a valid buffer.
ifstrstream()
Constructs an object of class ifstream.
void close()
In single mode, closes a file.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.