ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/branches/new_design/OOPSE-3.0/src/io/basic_ifstrstream.hpp
(Generate patch)

Comparing:
trunk/OOPSE-3.0/src/io/basic_ifstrstream.hpp (file contents), Revision 1577 by tim, Fri Oct 15 18:20:44 2004 UTC vs.
branches/new_design/OOPSE-3.0/src/io/basic_ifstrstream.hpp (file contents), Revision 1720 by tim, Sat Nov 6 05:21:55 2004 UTC

# Line 33 | Line 33
33   #ifndef IO_IFSTRSTREAM_HPP
34   #define IO_IFSTRSTREAM_HPP
35  
36 + #include <cassert>
37   #include <cstring>
38   #include <fstream>
39   #include <sstream>
# Line 45 | Line 46 | using namespace std;
46   using namespace std;
47   /**
48   * @class basic_ifstrstream basic_ifstrstream.hpp "io/basic_ifstrstream.hpp"
49 < * @brief class provides a stream interface to read data from files.
49 > * @brief basic_ifstrstream class provides a stream interface to read data from files.
50   * <p>In single mode, it falls back to ifstream. Don't need to read the whole file into memory.
51   * In parallel mode, the master node will read the whole file and brocast it to other slave nodes.
52   * After brocasting, every node will fall back to stringstream.</p>
# Line 80 | Line 81 | class basic_ifstrstream : public basic_istream<_CharT,
81          typedef basic_filebuf<_CharT, _Traits>            _Buf;
82   #endif
83  
84 <        static  const int FileNoExists = -1;
84 >        static  const int FileNotExists = -1;
85          static const int FileIOError = -2;
86          
87      public:
# Line 175 | Line 176 | class basic_ifstrstream : public basic_istream<_CharT,
176           * parallel mode) associated with the stream.
177           */
178          _Buf* rdbuf() const{
179 <            return const_cast<_Buf*>(internalBuf_);
179 >            return static_cast<_Buf*>(internalBuf_);
180          }
181  
182      private:
# Line 209 | Line 210 | class basic_ifstrstream : public basic_istream<_CharT,
210  
211                      //check the filename is the same
212                      filenameLen = strlen(filename);
213 <                    commStatus = MPI_Bcast(filenameLen, 1, MPI_INT, masterNode, MPI_COMM_WORLD);    
214 <                    commStatus = MPI_Bcast(filename, filenameLen, MPI_CHAR, masterNode, MPI_COMM_WORLD);    
213 >                    commStatus = MPI_Bcast(&filenameLen, 1, MPI_INT, masterNode, MPI_COMM_WORLD);    
214 >                    commStatus = MPI_Bcast((void*)filename, filenameLen, MPI_CHAR, masterNode, MPI_COMM_WORLD);    
215  
216                      diffFilename = 0;
217 <                    commStatus = MPI_Allreduce(diffFilename, error, 1,  MPI_INT,  MPI_COMM_WORLD);            
217 >                    commStatus = MPI_Allreduce(&diffFilename, &error, 1,  MPI_INT, MPI_SUM,  MPI_COMM_WORLD);            
218  
219                      //if file names are different just return false
220                      if (error > 0)
# Line 225 | Line 226 | class basic_ifstrstream : public basic_istream<_CharT,
226  
227                  if (fin.is_open()) {
228                      
229 <                    fin.in.seekg(0, ios::end);
229 >                    fin.seekg(0, ios::end);
230                      fileSize = fin.tellg();
231 <
231 >                    fin.seekg(0, ios::beg);
232 >                    
233                      // '\0' need one more char
234                      fbuf = new char[fileSize+1];
235                      
# Line 264 | Line 266 | class basic_ifstrstream : public basic_istream<_CharT,
266                      fin.close();                    
267                      delete fbuf;
268                  }else{
269 <                    fileSize = FileNoExists;
269 >                    fileSize = FileNotExists;
270                      commStatus = MPI_Bcast(&fileSize, 1, MPI_LONG, masterNode, MPI_COMM_WORLD);  
271                      return false;
272                  }
273                
274 <             } else{
274 >             } else{ //slave nodes
275 >
276                      //check file name
277                      if (checkFilename) {
278 <                        commStatus = MPI_Bcast(filenameLen, 1, MPI_INT, masterNode, MPI_COMM_WORLD);    
278 >                        commStatus = MPI_Bcast(&filenameLen, 1, MPI_INT, masterNode, MPI_COMM_WORLD);    
279  
280                          char * masterFilename = new char[filenameLen];
281                          commStatus = MPI_Bcast(masterFilename, filenameLen, MPI_CHAR, masterNode, MPI_COMM_WORLD);    
# Line 284 | Line 287 | class basic_ifstrstream : public basic_istream<_CharT,
287  
288                          delete masterFilename;
289                          
290 <                        commStatus = MPI_Allreduce(diffFilename, error, 1,  MPI_INT,  MPI_COMM_WORLD);    
290 >                        commStatus = MPI_Allreduce(&diffFilename, &error, 1,  MPI_INT,  MPI_SUM, MPI_COMM_WORLD);    
291  
292                          if (error > 0)
293                              return false;                        
# Line 309 | Line 312 | class basic_ifstrstream : public basic_istream<_CharT,
312  
313                          delete fbuf;
314  
315 <                    } else if (fileSize == FileNoExists ) {
315 >                    } else if (fileSize == FileNotExists ) {
316                          return false;
317  
318                      } else if (fileSize == FileIOError ) {
# Line 338 | Line 341 | typedef basic_istringstream<char, char_traits<char>, a
341          bool isRead;                                                                    /** file opened flag */
342   };
343  
344 < typedef basic_istringstream<char, char_traits<char>, allocator<char> > ifstringstream;
344 > typedef basic_ifstrstream<char, char_traits<char>, allocator<char> > ifstrstream;
345   }//namespace oopse
346   #endif //IO_IFSTRSTREAM_HPP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines