UIPstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::UIPstream
26 
27 Description
28  Input inter-processor communications stream operating on external
29  buffer.
30 
31 SourceFiles
32  UIPstream.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #include "Pstream.H"
37 
38 #ifndef UIPstream_H
39 #define UIPstream_H
40 
41 #include "UPstream.H"
42 #include "Istream.H"
43 #include "PstreamBuffers.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class UIPstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class UIPstream
55 :
56  public UPstream,
57  public Istream
58 {
59  // Private data
60 
61  int fromProcNo_;
62 
63  DynamicList<char>& externalBuf_;
64 
65  label& externalBufPosition_;
66 
67  const int tag_;
68 
69  const label comm_;
70 
71  const bool clearAtEnd_;
72 
73  int messageSize_;
74 
75 
76  // Private Member Functions
77 
78  //- Check the bufferPosition against messageSize_ for EOF
79  inline void checkEof();
80 
81  //- Read a T from the transfer buffer
82  template<class T>
83  inline void readFromBuffer(T&);
84 
85  //- Read data from the transfer buffer
86  inline void readFromBuffer(void* data, size_t count, size_t align);
87 
88 
89 public:
90 
91  // Constructors
92 
93  //- Construct given process index to read from and optional buffer size,
94  // read format and IO version
95  UIPstream
96  (
97  const commsTypes commsType,
98  const int fromProcNo,
99  DynamicList<char>& externalBuf,
100  label& externalBufPosition,
101  const int tag = UPstream::msgType(),
102  const label comm = UPstream::worldComm,
103  const bool clearAtEnd = false, // destroy externalBuf if at end
106  );
107 
108  //- Construct given buffers
109  UIPstream(const int fromProcNo, PstreamBuffers&);
110 
111 
112  //- Destructor
113  ~UIPstream();
114 
115 
116  // Member functions
117 
118  // Inquiry
119 
120  //- Return flags of output stream
121  ios_base::fmtflags flags() const
122  {
123  return ios_base::fmtflags(0);
124  }
125 
126 
127  // Read functions
128 
129  //- Read into given buffer from given processor and return the
130  // message size
131  static label read
132  (
133  const commsTypes commsType,
134  const int fromProcNo,
135  char* buf,
136  const std::streamsize bufSize,
137  const int tag = UPstream::msgType(),
138  const label communicator = 0
139  );
140 
141  //- Return next token from stream
142  Istream& read(token&);
143 
144  //- Read a character
145  Istream& read(char&);
146 
147  //- Read a word
148  Istream& read(word&);
149 
150  // Read a string (including enclosing double-quotes)
151  Istream& read(string&);
152 
153  //- Read a label
154  Istream& read(label&);
155 
156  //- Read a floatScalar
158 
159  //- Read a doubleScalar
161 
162  //- Read binary block
163  Istream& read(char*, std::streamsize);
164 
165  //- Rewind and return the stream so that it may be read again
166  Istream& rewind();
167 
168 
169  // Edit
170 
171  //- Set flags of stream
172  ios_base::fmtflags flags(const ios_base::fmtflags)
173  {
174  return ios_base::fmtflags(0);
175  }
176 
177 
178  // Print
179 
180  //- Print description of IOstream to Ostream
181  void print(Ostream&) const;
182 };
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #endif
192 
193 // ************************************************************************* //
UIPstream(const commsTypes commsType, const int fromProcNo, DynamicList< char > &externalBuf, label &externalBufPosition, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, const bool clearAtEnd=false, streamFormat format=BINARY, versionNumber version=currentVersion)
Construct given process index to read from and optional buffer size,.
Definition: UIPread.C:34
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
commsTypes
Types of communications.
Definition: UPstream.H:64
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: UIPstream.H:120
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:69
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:464
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:274
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:53
A class for handling words, derived from string.
Definition: word.H:59
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: UIPstream.C:330
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:49
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Read into given buffer from given processor and return the.
Definition: UIPread.C:79
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
~UIPstream()
Destructor.
Definition: UIPstream.C:81
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Helper class for allocating/freeing communicators.
Definition: UPstream.H:310
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:471
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
Version number type.
Definition: IOstream.H:96
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UIPstream.C:337
Inter-processor communications stream.
Definition: UPstream.H:58
Namespace for OpenFOAM.