Skip to content

Commit ea90b6e

Browse files
committed
Add istream and ostream capability to Xdr
1 parent 4a3de49 commit ea90b6e

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

include/utils/xdr_cxx.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,22 @@ class Xdr
7070
public:
7171

7272
/**
73-
* Constructor. Takes the filename and the mode.
73+
* File-based constructor. Takes the filename and the mode.
7474
* Valid modes are ENCODE, DECODE, READ, and WRITE.
7575
*/
7676
Xdr (std::string name="", const XdrMODE m=UNKNOWN);
7777

78+
/**
79+
* Output stream based constructor.
80+
* Assumes mode WRITE.
81+
*/
82+
Xdr (std::ostream & stream);
83+
/**
84+
* Input stream based constructor.
85+
* Assumes mode READ.
86+
*/
87+
Xdr (std::istream & stream);
88+
7889
/**
7990
* Destructor. Closes the file if it is open.
8091
*/

src/utils/xdr_cxx.C

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,42 @@ Xdr::Xdr (std::string name,
122122

123123

124124

125+
Xdr::Xdr (std::ostream & stream) :
126+
mode(WRITE),
127+
file_name(),
128+
#ifdef LIBMESH_HAVE_XDR
129+
fp(nullptr),
130+
#endif
131+
in(),
132+
out(std::make_unique<std::ostream>(stream.rdbuf())),
133+
comm_len(xdr_MAX_STRING_LENGTH),
134+
gzipped_file(false),
135+
bzipped_file(false),
136+
xzipped_file(false),
137+
version_number(LIBMESH_VERSION_ID(LIBMESH_MAJOR_VERSION, LIBMESH_MINOR_VERSION, LIBMESH_MICRO_VERSION))
138+
{
139+
}
140+
141+
142+
143+
Xdr::Xdr (std::istream & stream) :
144+
mode(READ),
145+
file_name(),
146+
#ifdef LIBMESH_HAVE_XDR
147+
fp(nullptr),
148+
#endif
149+
in(std::make_unique<std::istream>(stream.rdbuf())),
150+
out(),
151+
comm_len(xdr_MAX_STRING_LENGTH),
152+
gzipped_file(false),
153+
bzipped_file(false),
154+
xzipped_file(false),
155+
version_number(LIBMESH_VERSION_ID(LIBMESH_MAJOR_VERSION, LIBMESH_MINOR_VERSION, LIBMESH_MICRO_VERSION))
156+
{
157+
}
158+
159+
160+
125161
Xdr::~Xdr()
126162
{
127163
this->close();

0 commit comments

Comments
 (0)