| 47 | 
  | 
 * @version 1.0 | 
| 48 | 
  | 
 */ | 
| 49 | 
  | 
 | 
| 50 | 
– | 
#include "io/ifstrstream.hpp" | 
| 51 | 
– | 
 | 
| 50 | 
  | 
#ifdef IS_MPI | 
| 51 | 
  | 
#include <mpi.h> | 
| 52 | 
  | 
#endif | 
| 53 | 
  | 
 | 
| 54 | 
+ | 
#include "io/ifstrstream.hpp" | 
| 55 | 
+ | 
 | 
| 56 | 
  | 
namespace OpenMD { | 
| 57 | 
  | 
   | 
| 58 | 
  | 
  /**  Constructs an object of class ifstream.  */ | 
| 59 | 
  | 
#ifdef IS_MPI | 
| 60 | 
  | 
  ifstrstream::ifstrstream()  | 
| 61 | 
  | 
    :  std::basic_istream<char, std::char_traits<char> >(0), | 
| 62 | 
< | 
       internalStringBuf_(), isRead(false)  {     | 
| 62 | 
> | 
    internalStringBuf_(), isRead(false)  {     | 
| 63 | 
  | 
    this->init(&internalStringBuf_); | 
| 64 | 
  | 
  } | 
| 65 | 
  | 
#else | 
| 66 | 
  | 
  ifstrstream::ifstrstream()  | 
| 67 | 
  | 
    :  std::basic_istream<char, std::char_traits<char> >(0), | 
| 68 | 
< | 
       internalFileBuf_(), isRead(false)  {     | 
| 68 | 
> | 
    internalFileBuf_(), isRead(false)  {     | 
| 69 | 
  | 
    this->init(&internalFileBuf_); | 
| 70 | 
  | 
  } | 
| 71 | 
  | 
#endif | 
| 73 | 
  | 
  /** | 
| 74 | 
  | 
   * Explicit constructor | 
| 75 | 
  | 
   * @param filename String containing the name of the file to be opened | 
| 76 | 
< | 
   * @param mode Flags describing the requested i/o mode for the file, default value is ios_base::in       | 
| 76 | 
> | 
   * @param mode Flags describing the requested i/o mode for the file, | 
| 77 | 
> | 
   * default value is ios_base::in | 
| 78 | 
  | 
   * @param checkFilename Flags indicating checking the file name in parallel | 
| 79 | 
  | 
   */ | 
| 80 | 
  | 
#ifdef IS_MPI | 
| 94 | 
  | 
  } | 
| 95 | 
  | 
#endif   | 
| 96 | 
  | 
  /** | 
| 97 | 
< | 
   * virtual destructor will close the file(in single mode) and clear the stream buffer | 
| 97 | 
> | 
   * virtual destructor will close the file (in single mode) and clear | 
| 98 | 
> | 
   * the stream buffer | 
| 99 | 
  | 
   */ | 
| 100 | 
  | 
  ifstrstream::~ifstrstream(){ | 
| 101 | 
  | 
    close(); | 
| 102 | 
  | 
  } | 
| 103 | 
  | 
   | 
| 104 | 
  | 
  /** | 
| 105 | 
< | 
   * Opens a file and associats a buffer with the specified file to perform the i/o operations  | 
| 106 | 
< | 
   * (single mode). Master reads a file and brocasts its content to the other slave nodes. After | 
| 107 | 
< | 
   * brocasting, every nodes fall back to stringstream (parallel mode). | 
| 105 | 
> | 
   * Opens a file and associates a buffer with the specified file to | 
| 106 | 
> | 
   * perform the i/o operations (single mode). The master node reads a | 
| 107 | 
> | 
   * file and broadcasts its content to the other slave nodes. After | 
| 108 | 
> | 
   * broadcasting, all nodes fall back to stringstream (parallel | 
| 109 | 
> | 
   * mode). | 
| 110 | 
  | 
   * @param filename String containing the name of the file to be opened | 
| 111 | 
  | 
   * @param mode Flags describing the requested i/o mode for the file | 
| 112 | 
  | 
   * @param checkFilename Flags indicating checking the file name in parallel | 
| 119 | 
  | 
  } | 
| 120 | 
  | 
 | 
| 121 | 
  | 
  /** | 
| 122 | 
< | 
   * Tests if the stream is currently associated with a valid  buffer. | 
| 123 | 
< | 
   * @return true if a file has successfully been opened (single mode) or the whole file is read  | 
| 124 | 
< | 
   * and spreaded among all of the processors (parallel mode),  otherwise false is returned | 
| 122 | 
> | 
   * Tests if the stream is currently associated with a valid buffer. | 
| 123 | 
> | 
   * @return true if a file has successfully been opened (single mode) | 
| 124 | 
> | 
   * or the whole file has been read and spread among all of the | 
| 125 | 
> | 
   * processors (parallel mode), otherwise false is returned | 
| 126 | 
  | 
   */ | 
| 127 | 
  | 
  bool ifstrstream::is_open ( ) { | 
| 128 | 
  | 
#ifdef IS_MPI             | 
| 136 | 
  | 
  /** | 
| 137 | 
  | 
   * In single mode, closes a file. The stream's file buffer is | 
| 138 | 
  | 
   * released from its association with the currently open file. In | 
| 139 | 
< | 
   * parallel mode, clean the | 
| 139 | 
> | 
   * parallel mode, cleans up. | 
| 140 | 
  | 
   */ | 
| 141 | 
  | 
  void ifstrstream::close() { | 
| 142 | 
  | 
#ifndef IS_MPI             | 
| 162 | 
  | 
  }   | 
| 163 | 
  | 
   | 
| 164 | 
  | 
  /** | 
| 165 | 
< | 
     * Internal function used to open the file | 
| 166 | 
< | 
     * @return true if succesfully opens a file (single mode) or gets the file content (parallel mode) | 
| 167 | 
< | 
     * otherwise return false | 
| 168 | 
< | 
     * @param filename String containing the name of the file to be opened | 
| 169 | 
< | 
     * @param mode Flags describing the requested i/o mode for the file | 
| 170 | 
< | 
     * @param checkFilename Flags indicating checking the file name in parallel | 
| 171 | 
< | 
     * @todo use try - catch syntax to make the program more readable | 
| 172 | 
< | 
     */ | 
| 165 | 
> | 
   * Internal function used to open the file  | 
| 166 | 
> | 
   * @return true if succesfully opens a file (single mode) or gets | 
| 167 | 
> | 
   * the file content (parallel mode) otherwise return false | 
| 168 | 
> | 
   * @param filename String containing the name of the file to be opened | 
| 169 | 
> | 
   * @param mode Flags describing the requested i/o mode for the file | 
| 170 | 
> | 
   * @param checkFilename Flags indicating checking the file name in parallel | 
| 171 | 
> | 
   * @todo use try - catch syntax to make the program more readable | 
| 172 | 
> | 
   */ | 
| 173 | 
  | 
 | 
| 174 | 
  | 
  bool ifstrstream::internalOpen(const char* filename, std::ios_base::openmode mode, bool checkFilename){ | 
| 175 | 
  | 
     | 
| 198 | 
  | 
         | 
| 199 | 
  | 
        diffFilename = 0; | 
| 200 | 
  | 
        MPI::COMM_WORLD.Allreduce(&diffFilename, &error, 1, MPI::INT, MPI::SUM); | 
| 201 | 
< | 
 | 
| 201 | 
> | 
         | 
| 202 | 
  | 
        //if file names are different just return false | 
| 203 | 
  | 
        if (error > 0) | 
| 204 | 
  | 
          return false;    |