35 |
|
* |
36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
38 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
39 |
< |
* [4] Vardeman & Gezelter, in progress (2009). |
38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
39 |
> |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
> |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
|
/** |
59 |
|
|
60 |
|
/** |
61 |
|
* @class ifstrstream ifstrstream.hpp "io/ifstrstream.hpp" |
62 |
< |
* @brief ifstrstream class provides a stream interface to read data from files. |
63 |
< |
* <p>In single mode, it falls back to ifstream. Don't need to read the whole file into memory. |
64 |
< |
* In parallel mode, the master node will read the whole file and brocast it to other slave nodes. |
65 |
< |
* After brocasting, every node will fall back to stringstream.</p> |
62 |
> |
* @brief ifstrstream class provides a stream interface to read data |
63 |
> |
* from files. |
64 |
> |
* <p>In single mode, it falls back to ifstream, as we don't need to |
65 |
> |
* read the whole file into memory. In parallel mode, the master |
66 |
> |
* node will read the whole file and broadcast it to other slave |
67 |
> |
* nodes. After broadcasting, every node will fall back to |
68 |
> |
* stringstream.</p> |
69 |
|
* |
70 |
|
* @code |
71 |
|
* const int MAXLEN = 1024; |
78 |
|
* in.close(); |
79 |
|
* @endcode |
80 |
|
*/ |
81 |
< |
class ifstrstream : public std::basic_istream<char, std::char_traits<char> > { |
81 |
> |
class ifstrstream : public std::basic_istream<char, std::char_traits<char> > { |
82 |
|
public: |
83 |
|
//traits |
84 |
|
typedef char char_type; |
85 |
|
typedef std::char_traits<char>::int_type int_type; |
86 |
|
typedef std::char_traits<char>::pos_type pos_type; |
87 |
|
typedef std::char_traits<char>::off_type off_type; |
88 |
< |
typedef std::char_traits<char> traits_type; |
89 |
< |
|
88 |
> |
typedef std::char_traits<char> traits_type; |
89 |
> |
|
90 |
|
typedef std::basic_ios<char, std::char_traits<char> > _Basic_ios; |
91 |
|
typedef std::basic_istream<char, std::char_traits<char> > _Base; |
92 |
|
typedef std::basic_streambuf<char, std::char_traits<char> > _Buf; |
93 |
|
typedef std::basic_stringbuf<char, std::char_traits<char> > _StringBuf; |
94 |
|
typedef std::basic_filebuf<char, std::char_traits<char> > _FileBuf; |
95 |
|
|
92 |
– |
|
96 |
|
static const int FileNotExists = -1; |
97 |
|
static const int FileIOError = -2; |
98 |
|
|
103 |
|
|
104 |
|
/** |
105 |
|
* Explicit constructor |
106 |
< |
* @filename String containing the name of the file to be opened |
107 |
< |
* @mode Flags describing the requested i/o mode for the file, default value is ios_base::in |
108 |
< |
* @checkFilename Flags indicating checking the file name in parallel |
106 |
> |
* @param filename String containing the name of the file to be opened |
107 |
> |
* @param mode Flags describing the requested i/o mode for the |
108 |
> |
* file, default value is ios_base::in |
109 |
> |
* @param checkFilename Flags indicating checking the file name in parallel |
110 |
|
*/ |
111 |
|
explicit ifstrstream(const char* filename, std::ios_base::openmode mode = std::ios_base::in, bool checkFilename = false); |
112 |
|
|
113 |
|
/** |
114 |
< |
* virtual destructor will close the file(in single mode) and clear the stream buffer |
114 |
> |
* virtual destructor will close the file(in single mode) and |
115 |
> |
* clear the stream buffer |
116 |
|
*/ |
117 |
|
~ifstrstream(); |
118 |
|
|
119 |
|
/** |
120 |
< |
* Opens a file and associats a buffer with the specified file to perform the i/o operations |
121 |
< |
* (single mode). Master reads a file and brocasts its content to the other slave nodes. After |
122 |
< |
* brocasting, every nodes fall back to stringstream (parallel mode). |
123 |
< |
* @filename String containing the name of the file to be opened |
124 |
< |
* @mode Flags describing the requested i/o mode for the file |
125 |
< |
* @checkFilename Flags indicating checking the file name in parallel |
120 |
> |
* Opens a file and associates a buffer with the specified file to |
121 |
> |
* perform the i/o operations (single mode). The master node reads |
122 |
> |
* a file and broadcasts its content to the other slave |
123 |
> |
* nodes. After broadcasting, all nodes fall back to stringstream |
124 |
> |
* (parallel mode). |
125 |
> |
* @param filename String containing the name of the file to be opened |
126 |
> |
* @param mode Flags describing the requested i/o mode for the file |
127 |
> |
* @param checkFilename Flags indicating checking the file name in parallel |
128 |
|
*/ |
129 |
|
void open(const char* filename, std::ios_base::openmode mode = std::ios_base::in, bool checkFilename = false); |
130 |
|
|
124 |
– |
|
131 |
|
/** |
132 |
< |
* Tests if the stream is currently associated with a valid buffer. |
133 |
< |
* @return true if a file has successfully been opened (single mode) or the whole file is read |
134 |
< |
* and spreaded among all of the processors (parallel mode), otherwise false is returned |
132 |
> |
* Tests if the stream is currently associated with a valid buffer. |
133 |
> |
* @return true if a file has successfully been opened (single |
134 |
> |
* mode) or the whole file has been read and spread among all of |
135 |
> |
* the processors (parallel mode), otherwise false is returned |
136 |
> |
|
137 |
|
*/ |
138 |
|
bool is_open ( ); |
139 |
|
|
140 |
|
/** |
141 |
< |
* In single mode, closes a file. The stream's file buffer is released from its association with |
142 |
< |
* the currently open file. In parallel mode, clean the |
141 |
> |
* In single mode, closes a file. The stream's file buffer is |
142 |
> |
* released from its association with the currently open file. In |
143 |
> |
* parallel mode, clean up. |
144 |
|
*/ |
145 |
|
void close(); |
146 |
|
|
147 |
|
/** |
148 |
|
* Gets the stream buffer object associated with the stream |
149 |
< |
* @return A pointer to the stream buffer object(filebuf in single mode, |
150 |
< |
* stringbuf in parallel mode) associated with the stream. |
149 |
> |
* @return A pointer to the stream buffer object (filebuf in |
150 |
> |
* single mode, stringbuf in parallel mode) associated with the |
151 |
> |
* stream. |
152 |
|
*/ |
153 |
|
_Buf* rdbuf(); |
154 |
|
|
156 |
|
|
157 |
|
/** |
158 |
|
* Internal function used to open the file |
159 |
< |
* @return true if succesfully opens a file (single mode) or gets the file content (parallel mode) |
160 |
< |
* otherwise return false |
161 |
< |
* @filename String containing the name of the file to be opened |
162 |
< |
* @mode Flags describing the requested i/o mode for the file |
159 |
> |
* @return true if succesfully opens a file (single mode) or gets the file content (parallel mode) |
160 |
> |
* otherwise returns false |
161 |
> |
* @param filename String containing the name of the file to be opened |
162 |
> |
* @param mode Flags describing the requested i/o mode for the file |
163 |
> |
* @param checkFilename Flags indicating checking the file name in parallel |
164 |
|
* @todo use try - catch syntax to make the program more readable |
165 |
|
*/ |
166 |
|
bool internalOpen(const char* filename, std::ios_base::openmode mode, bool checkFilename); |
167 |
< |
|
168 |
< |
_StringBuf internalStringBuf_; /** internal stream buffer */ |
169 |
< |
_FileBuf internalFileBuf_; /** internal stream buffer */ |
170 |
< |
bool isRead; /** file opened flag */ |
171 |
< |
}; |
161 |
< |
|
167 |
> |
|
168 |
> |
_StringBuf internalStringBuf_; /** internal stream buffer */ |
169 |
> |
_FileBuf internalFileBuf_; /** internal stream buffer */ |
170 |
> |
bool isRead; /** file opened flag */ |
171 |
> |
}; |
172 |
|
} |
173 |
|
#endif |