66 std::basic_istream<char, std::char_traits<char>>(0), internalStringBuf_(),
68 this->init(&internalStringBuf_);
72 std::basic_istream<char, std::char_traits<char>>(0), internalFileBuf_(),
74 this->init(&internalFileBuf_);
88 std::basic_istream<char, std::char_traits<char>>(0),
89 internalStringBuf_(), isRead(false) {
90 this->init(&internalStringBuf_);
93 internalOpen(filename, mode | std::ios_base::in | std::ios_base::binary,
96 isRead = internalOpen(filename, mode | std::ios_base::in, checkFilename);
101 bool checkFilename) :
102 std::basic_istream<char, std::char_traits<char>>(0),
103 internalFileBuf_(), isRead(false) {
104 this->init(&internalFileBuf_);
107 internalOpen(filename, mode | std::ios_base::in | std::ios_base::binary,
110 isRead = internalOpen(filename, mode | std::ios_base::in, checkFilename);
131 bool checkFilename) {
135 internalOpen(filename, mode | std::ios_base::binary, checkFilename);
137 isRead = internalOpen(filename, mode, checkFilename);
153 return internalFileBuf_.is_open();
165 if (!internalFileBuf_.close()) this->setstate(std::ios_base::failbit);
178 return static_cast<_StringBuf*
>(&internalStringBuf_);
180 return static_cast<_FileBuf*
>(&internalFileBuf_);
194 bool ifstrstream::internalOpen(
const char* filename,
195 std::ios_base::openmode mode,
196 bool checkFilename) {
206 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
210 if (myRank == primaryNode) {
213 filenameLen = strlen(filename);
214 MPI_Bcast(&filenameLen, 1, MPI_INT, primaryNode, MPI_COMM_WORLD);
215 MPI_Bcast((
void*)filename, filenameLen, MPI_CHAR, primaryNode,
219 MPI_Allreduce(&diffFilename, &error, 1, MPI_INT, MPI_SUM,
223 if (error > 0)
return false;
226 std::ifstream fin(filename, mode);
229 fin.seekg(0, std::ios::end);
230 fileSize = fin.tellg();
231 fin.seekg(0, std::ios::beg);
234 fbuf =
new char[fileSize + 1];
238 fin.read(fbuf, fileSize);
240 if (fin.fail()) fileSize = FileIOError;
243 MPI_Bcast(&fileSize, 1, MPI_LONG, primaryNode, MPI_COMM_WORLD);
253 fbuf[fileSize] =
'\0';
254 MPI_Bcast(fbuf, fileSize + 1, MPI_CHAR, primaryNode, MPI_COMM_WORLD);
258 internalStringBuf_.str(fbuf);
261 fileSize = FileNotExists;
262 MPI_Bcast(&fileSize, 1, MPI_LONG, primaryNode, MPI_COMM_WORLD);
270 MPI_Bcast(&filenameLen, 1, MPI_INT, primaryNode, MPI_COMM_WORLD);
272 char* primaryFilename =
new char[filenameLen];
273 MPI_Bcast(primaryFilename, filenameLen, MPI_CHAR, primaryNode,
276 if (strcmp(primaryFilename, filename) == 0)
281 delete[] primaryFilename;
283 MPI_Allreduce(&diffFilename, &error, 1, MPI_INT, MPI_SUM,
286 if (error > 0)
return false;
289 MPI_Bcast(&fileSize, 1, MPI_LONG, primaryNode, MPI_COMM_WORLD);
292 fbuf =
new char[fileSize + 1];
296 MPI_Bcast(fbuf, fileSize + 1, MPI_CHAR, primaryNode, MPI_COMM_WORLD);
298 internalStringBuf_.str(fbuf);
301 }
else if (fileSize == FileNotExists) {
304 }
else if (fileSize == FileIOError) {
313 bool ifstrstream::internalOpen(
const char* filename,
314 std::ios_base::openmode mode,
bool) {
316 if (!internalFileBuf_.open(filename, mode)) {
317 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.