libMesh
Public Member Functions | Private Member Functions | Private Attributes | List of all members
libMesh::Xdr Class Reference

This class implements a C++ interface to the XDR (eXternal Data Representation) format. More...

#include <xdr_cxx.h>

Public Member Functions

 Xdr (const std::string &name="", const XdrMODE m=UNKNOWN)
 Constructor. More...
 
 ~Xdr ()
 Destructor. More...
 
void open (const std::string &name)
 Opens the file. More...
 
void close ()
 Closes the file if it is open. More...
 
bool is_open () const
 
bool is_eof ()
 
bool reading () const
 
bool writing () const
 
XdrMODE access_mode () const
 
template<typename T >
void data (T &a, const char *comment="")
 Inputs or outputs a single value. More...
 
template<typename T >
Xdroperator<< (T &a)
 Same, but provides an ostream like interface. More...
 
template<typename T >
Xdroperator>> (T &a)
 Same, but provides an istream like interface. More...
 
template<typename T >
void data_stream (T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
 Inputs or outputs a raw data stream. More...
 
void comment (std::string &)
 Writes or reads (ignores) a comment line. More...
 
void set_version (int ver)
 Sets the version of the file that is being read. More...
 
int version () const
 Gets the version of the file that is being read. More...
 
template<>
void data_stream (double *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (float *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (long double *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (Real *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (std::complex< double > *val, const unsigned int len, const unsigned int line_break)
 
template<>
void data_stream (std::complex< long double > *val, const unsigned int len, const unsigned int line_break)
 

Private Member Functions

template<typename T >
void do_read (T &a)
 Helper method for reading different data types. More...
 
template<typename T >
void do_read (std::complex< T > &a)
 
template<typename T >
void do_read (std::vector< T > &a)
 
template<typename T >
void do_read (std::vector< std::complex< T >> &a)
 
template<typename T >
void do_write (T &a)
 Helper method for writing different data types. More...
 
template<typename T >
void do_write (std::complex< T > &a)
 
template<typename T >
void do_write (std::vector< T > &a)
 
template<typename T >
void do_write (std::vector< std::complex< T >> &a)
 
template<>
void do_read (std::string &a)
 

Private Attributes

const XdrMODE mode
 The mode used for accessing the file. More...
 
std::string file_name
 The file name. More...
 
std::unique_ptr< XDR > xdrs
 Pointer to the standard XDR struct. More...
 
FILE * fp
 File pointer. More...
 
std::unique_ptr< std::istream > in
 The input file stream. More...
 
std::unique_ptr< std::ostream > out
 The output file stream. More...
 
const int comm_len
 A buffer to put comment strings into. More...
 
char comm [xdr_MAX_STRING_LENGTH]
 
bool gzipped_file
 Are we reading/writing zipped files? More...
 
bool bzipped_file
 
bool xzipped_file
 
int version_number
 Version of the file being read. More...
 

Detailed Description

This class implements a C++ interface to the XDR (eXternal Data Representation) format.

XDR is useful for creating platform-independent binary files. This class was created to handle equation system output as a replacement for XdrIO since that is somewhat limited.

Author
Benjamin Kirk
Date
2003

C++ interface for the XDR (eXternal Data Representation) format.

Definition at line 65 of file xdr_cxx.h.

Constructor & Destructor Documentation

◆ Xdr()

libMesh::Xdr::Xdr ( const std::string &  name = "",
const XdrMODE  m = UNKNOWN 
)

Constructor.

Takes the filename and the mode. Valid modes are ENCODE, DECODE, READ, and WRITE.

Definition at line 136 of file xdr_cxx.C.

137  :
138  mode(m),
139  file_name(name),
140 #ifdef LIBMESH_HAVE_XDR
141  fp(nullptr),
142 #endif
143  in(),
144  out(),
146  gzipped_file(false),
147  bzipped_file(false),
148  xzipped_file(false)
149 {
150  this->open(name);
151 }

References open().

◆ ~Xdr()

libMesh::Xdr::~Xdr ( )

Destructor.

Closes the file if it is open.

Definition at line 155 of file xdr_cxx.C.

156 {
157  this->close();
158 }

References close().

Member Function Documentation

◆ access_mode()

XdrMODE libMesh::Xdr::access_mode ( ) const
inline
Returns
The mode used to access the file. Valid modes are ENCODE, DECODE, READ, or WRITE.

Definition at line 122 of file xdr_cxx.h.

122 { return mode; }

References mode.

◆ close()

void libMesh::Xdr::close ( )

Closes the file if it is open.

Definition at line 273 of file xdr_cxx.C.

274 {
275  switch (mode)
276  {
277  case ENCODE:
278  case DECODE:
279  {
280 #ifdef LIBMESH_HAVE_XDR
281 
282  if (xdrs)
283  {
284  xdr_destroy (xdrs.get());
285  xdrs.reset();
286  }
287 
288  if (fp)
289  {
290  fflush(fp);
291  fclose(fp);
292  fp = nullptr;
293  }
294 #else
295 
296  libmesh_error_msg("ERROR: Functionality is not available.\n" \
297  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
298  << "The XDR interface is not available in this installation");
299 
300 #endif
301  file_name = "";
302  return;
303  }
304 
305  case READ:
306  {
307  if (in.get() != nullptr)
308  {
309  in.reset();
310 
311  if (bzipped_file || xzipped_file)
312  remove_unzipped_file(file_name);
313  }
314  file_name = "";
315  return;
316  }
317 
318  case WRITE:
319  {
320  if (out.get() != nullptr)
321  {
322  out.reset();
323 
324  if (bzipped_file)
325  bzip_file(std::string(file_name.begin(), file_name.end()-4));
326 
327  else if (xzipped_file)
328  xzip_file(std::string(file_name.begin(), file_name.end()-3));
329  }
330  file_name = "";
331  return;
332  }
333 
334  default:
335  libmesh_error_msg("Invalid mode = " << mode);
336  }
337 }

References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, in, mode, out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.

Referenced by libMesh::EquationSystems::_read_impl(), libMesh::RBEvaluation::legacy_read_offline_data_from_files(), libMesh::RBSCMEvaluation::legacy_read_offline_data_from_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::CheckpointIO::read(), libMesh::RBParametrized::read_parameter_ranges_from_file(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::RBParametrized::write_parameter_ranges_to_file(), and ~Xdr().

◆ comment()

void libMesh::Xdr::comment ( std::string &  comment_in)

Writes or reads (ignores) a comment line.

Definition at line 1661 of file xdr_cxx.C.

1662 {
1663  switch (mode)
1664  {
1665  case ENCODE:
1666  case DECODE:
1667  {
1668  return;
1669  }
1670 
1671  case READ:
1672  {
1673  libmesh_assert(in.get());
1674  libmesh_assert (in->good());
1675  in->getline(comm, comm_len);
1676  return;
1677  }
1678 
1679  case WRITE:
1680  {
1681  libmesh_assert(out.get());
1682  libmesh_assert (out->good());
1683  *out << "\t " << comment_in << '\n';
1684  return;
1685  }
1686 
1687  default:
1688  libmesh_error_msg("Invalid mode = " << mode);
1689  }
1690 }

References comm, comm_len, libMesh::DECODE, libMesh::ENCODE, in, libMesh::libmesh_assert(), mode, out, libMesh::READ, and libMesh::WRITE.

Referenced by libMesh::System::read_serialized_data(), and libMesh::System::write_serialized_data().

◆ data()

template<typename T >
template void libMesh::Xdr::data< Real > ( T &  a,
const char *  comment = "" 
)

Inputs or outputs a single value.

Definition at line 766 of file xdr_cxx.C.

767 {
768  switch (mode)
769  {
770  case ENCODE:
771  case DECODE:
772  {
773 #ifdef LIBMESH_HAVE_XDR
774 
776 
777  xdr_translate(xdrs.get(), a);
778 
779 #else
780 
781  libmesh_error_msg("ERROR: Functionality is not available.\n" \
782  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
783  << "The XDR interface is not available in this installation");
784 
785 #endif
786  return;
787  }
788 
789  case READ:
790  {
791  libmesh_assert(in.get());
792  libmesh_assert (in->good());
793 
794  this->do_read(a);
795 
796  return;
797  }
798 
799  case WRITE:
800  {
801  libmesh_assert(out.get());
802  libmesh_assert (out->good());
803 
804  // We will use scientific notation sufficient to exactly
805  // represent our floating point precision in the following
806  // output. The desired precision and format will
807  // automatically determine the width.
808  *out << std::scientific
809  << std::setprecision(std::numeric_limits<T>::max_digits10);
810 
811  this->do_write(a);
812 
813  // If there's a comment provided, write a tab character and
814  // then the comment.
815  if (std::string(comment_in) != "")
816  *out << "\t " << comment_in;
817 
818  // Go to the next line.
819  *out << '\n';
820 
821  return;
822  }
823 
824  default:
825  libmesh_error_msg("Invalid mode = " << mode);
826  }
827 }

References libMesh::DECODE, do_read(), do_write(), libMesh::ENCODE, in, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by libMesh::EquationSystems::_read_impl(), do_read(), do_write(), operator<<(), operator>>(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_bc_names(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::CheckpointIO::read_integers_names(), libMesh::System::read_legacy_data(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::System::read_parallel_data(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::CheckpointIO::select_split_config(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::EquationSystems::write(), libMesh::CheckpointIO::write_bc_names(), libMesh::CheckpointIO::write_bcs(), libMesh::CheckpointIO::write_connectivity(), libMesh::System::write_header(), libMesh::CheckpointIO::write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::System::write_parallel_data(), libMesh::CheckpointIO::write_remote_elem(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), and libMesh::CheckpointIO::write_subdomain_names().

◆ data_stream() [1/7]

template<>
void libMesh::Xdr::data_stream ( double *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 947 of file xdr_cxx.C.

948 {
949  switch (mode)
950  {
951  case ENCODE:
952  case DECODE:
953  {
954 #ifdef LIBMESH_HAVE_XDR
955 
956  libmesh_assert (this->is_open());
957 
958  if (len > 0)
959  xdr_vector(xdrs.get(),
960  (char *) val,
961  len,
962  sizeof(double),
963  (xdrproc_t) xdr_double);
964 
965 #else
966 
967  libmesh_error_msg("ERROR: Functionality is not available.\n" \
968  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
969  << "The XDR interface is not available in this installation");
970 
971 #endif
972  return;
973  }
974 
975  case READ:
976  {
977  libmesh_assert(in.get());
978  libmesh_assert (in->good());
979 
980  for (unsigned int i=0; i<len; i++)
981  {
982  libmesh_assert(in.get());
983  libmesh_assert (in->good());
984  *in >> val[i];
985  }
986 
987  return;
988  }
989 
990  case WRITE:
991  {
992  libmesh_assert(out.get());
993  libmesh_assert (out->good());
994 
995  // Save stream flags
996  std::ios_base::fmtflags out_flags = out->flags();
997 
998  // We will use scientific notation sufficient to exactly
999  // represent our floating point precision in the following
1000  // output. The desired precision and format will
1001  // automatically determine the width.
1002  *out << std::scientific
1003  << std::setprecision(std::numeric_limits<double>::max_digits10);
1004 
1005  if (line_break == libMesh::invalid_uint)
1006  for (unsigned int i=0; i<len; i++)
1007  {
1008  libmesh_assert(out.get());
1009  libmesh_assert (out->good());
1010  *out << val[i] << ' ';
1011  }
1012  else
1013  {
1014  const unsigned imax = std::min(line_break, len);
1015  unsigned int cnt=0;
1016  while (cnt < len)
1017  {
1018  for (unsigned int i=0; i<imax; i++)
1019  {
1020  libmesh_assert(out.get());
1021  libmesh_assert (out->good());
1022  *out << val[cnt++];
1023 
1024  // Write a space unless this is the last character on the current line.
1025  if (i+1 != imax)
1026  *out << " ";
1027  }
1028  libmesh_assert(out.get());
1029  libmesh_assert (out->good());
1030  *out << '\n';
1031  }
1032  }
1033 
1034  // Restore stream flags
1035  out->flags(out_flags);
1036 
1037  return;
1038  }
1039 
1040  default:
1041  libmesh_error_msg("Invalid mode = " << mode);
1042  }
1043 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

◆ data_stream() [2/7]

template<>
void libMesh::Xdr::data_stream ( float *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1047 of file xdr_cxx.C.

1048 {
1049  switch (mode)
1050  {
1051  case ENCODE:
1052  case DECODE:
1053  {
1054 #ifdef LIBMESH_HAVE_XDR
1055 
1056  libmesh_assert (this->is_open());
1057 
1058  if (len > 0)
1059  xdr_vector(xdrs.get(),
1060  (char *) val,
1061  len,
1062  sizeof(float),
1063  (xdrproc_t) xdr_float);
1064 
1065 #else
1066 
1067  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1068  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1069  << "The XDR interface is not available in this installation");
1070 
1071 #endif
1072  return;
1073  }
1074 
1075  case READ:
1076  {
1077  libmesh_assert(in.get());
1078  libmesh_assert (in->good());
1079 
1080  for (unsigned int i=0; i<len; i++)
1081  {
1082  libmesh_assert(in.get());
1083  libmesh_assert (in->good());
1084  *in >> val[i];
1085  }
1086 
1087  return;
1088  }
1089 
1090  case WRITE:
1091  {
1092  libmesh_assert(out.get());
1093  libmesh_assert (out->good());
1094 
1095  // Save stream flags
1096  std::ios_base::fmtflags out_flags = out->flags();
1097 
1098  // We will use scientific notation sufficient to exactly
1099  // represent our floating point precision in the following
1100  // output. The desired precision and format will
1101  // automatically determine the width.
1102  *out << std::scientific
1103  << std::setprecision(std::numeric_limits<float>::max_digits10);
1104 
1105  if (line_break == libMesh::invalid_uint)
1106  for (unsigned int i=0; i<len; i++)
1107  {
1108  libmesh_assert(out.get());
1109  libmesh_assert (out->good());
1110  *out << val[i] << ' ';
1111  }
1112  else
1113  {
1114  const unsigned imax = std::min(line_break, len);
1115  unsigned int cnt=0;
1116  while (cnt < len)
1117  {
1118  for (unsigned int i=0; i<imax; i++)
1119  {
1120  libmesh_assert(out.get());
1121  libmesh_assert (out->good());
1122  *out << val[cnt++];
1123 
1124  // Write a space unless this is the last character on the current line.
1125  if (i+1 != imax)
1126  *out << " ";
1127  }
1128  libmesh_assert(out.get());
1129  libmesh_assert (out->good());
1130  *out << '\n';
1131  }
1132  }
1133 
1134  // Restore stream flags
1135  out->flags(out_flags);
1136 
1137  return;
1138  }
1139 
1140  default:
1141  libmesh_error_msg("Invalid mode = " << mode);
1142  }
1143 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

◆ data_stream() [3/7]

template<>
void libMesh::Xdr::data_stream ( long double *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1147 of file xdr_cxx.C.

1148 {
1149  switch (mode)
1150  {
1151  case ENCODE:
1152  case DECODE:
1153  {
1154 #ifdef LIBMESH_HAVE_XDR
1155 
1156  libmesh_assert (this->is_open());
1157 
1158  // FIXME[JWP]: How to implement this for long double? Mac OS
1159  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1160  // Linux... for now, reading/writing XDR files with long
1161  // doubles drops back to double precision, but you can still
1162  // write long double ASCII files of course.
1163  // if (len > 0)
1164  // xdr_vector(xdrs.get(),
1165  // (char *) val,
1166  // len,
1167  // sizeof(double),
1168  // (xdrproc_t) xdr_quadruple);
1169 
1170  if (len > 0)
1171  {
1172  std::vector<double> io_buffer (len);
1173 
1174  // Fill io_buffer if we are writing.
1175  if (mode == ENCODE)
1176  for (unsigned int i=0, cnt=0; i<len; i++)
1177  io_buffer[cnt++] = double(val[i]);
1178 
1179  xdr_vector(xdrs.get(),
1180  reinterpret_cast<char *>(io_buffer.data()),
1181  len,
1182  sizeof(double),
1183  (xdrproc_t) xdr_double);
1184 
1185  // Fill val array if we are reading.
1186  if (mode == DECODE)
1187  for (unsigned int i=0, cnt=0; i<len; i++)
1188  {
1189  val[i] = io_buffer[cnt++];
1190  }
1191  }
1192 
1193 #else
1194 
1195  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1196  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1197  << "The XDR interface is not available in this installation");
1198 
1199 #endif
1200  return;
1201  }
1202 
1203  case READ:
1204  {
1205  libmesh_assert(in.get());
1206  libmesh_assert (in->good());
1207 
1208  for (unsigned int i=0; i<len; i++)
1209  {
1210  libmesh_assert(in.get());
1211  libmesh_assert (in->good());
1212  *in >> val[i];
1213  }
1214 
1215  return;
1216  }
1217 
1218  case WRITE:
1219  {
1220  libmesh_assert(out.get());
1221  libmesh_assert (out->good());
1222 
1223  // Save stream flags
1224  std::ios_base::fmtflags out_flags = out->flags();
1225 
1226  // We will use scientific notation sufficient to exactly
1227  // represent our floating point precision in the following
1228  // output. The desired precision and format will
1229  // automatically determine the width.
1230  *out << std::scientific
1231  << std::setprecision(std::numeric_limits<long double>::max_digits10);
1232 
1233  if (line_break == libMesh::invalid_uint)
1234  for (unsigned int i=0; i<len; i++)
1235  {
1236  libmesh_assert(out.get());
1237  libmesh_assert (out->good());
1238  *out << val[i] << ' ';
1239  }
1240  else
1241  {
1242  const unsigned imax = std::min(line_break, len);
1243  unsigned int cnt=0;
1244  while (cnt < len)
1245  {
1246  for (unsigned int i=0; i<imax; i++)
1247  {
1248  libmesh_assert(out.get());
1249  libmesh_assert (out->good());
1250  *out << val[cnt++];
1251 
1252  // Write a space unless this is the last character on the current line.
1253  if (i+1 != imax)
1254  *out << " ";
1255  }
1256  libmesh_assert(out.get());
1257  libmesh_assert (out->good());
1258  *out << '\n';
1259  }
1260  }
1261 
1262  // Restore stream flags
1263  out->flags(out_flags);
1264 
1265  return;
1266  }
1267 
1268  default:
1269  libmesh_error_msg("Invalid mode = " << mode);
1270  }
1271 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

◆ data_stream() [4/7]

template<>
void libMesh::Xdr::data_stream ( Real val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1276 of file xdr_cxx.C.

1277 {
1278  switch (mode)
1279  {
1280  case ENCODE:
1281  case DECODE:
1282  {
1283 #ifdef LIBMESH_HAVE_XDR
1284 
1285  libmesh_assert (this->is_open());
1286 
1287  // FIXME[RHS]: This has the same "xdr_quadruple may not be
1288  // defined" problem as long double, and the problem may be
1289  // much worse since even _Quad/__float128 aren't standard
1290  // either.
1291  // if (len > 0)
1292  // xdr_vector(xdrs.get(),
1293  // (char *) val,
1294  // len,
1295  // sizeof(double),
1296  // (xdrproc_t) xdr_quadruple);
1297 
1298  if (len > 0)
1299  {
1300  std::vector<double> io_buffer (len);
1301 
1302  // Fill io_buffer if we are writing.
1303  if (mode == ENCODE)
1304  for (unsigned int i=0, cnt=0; i<len; i++)
1305  io_buffer[cnt++] = double(val[i]);
1306 
1307  xdr_vector(xdrs.get(),
1308  reinterpret_cast<char *>(io_buffer.data()),
1309  len,
1310  sizeof(double),
1311  (xdrproc_t) xdr_double);
1312 
1313  // Fill val array if we are reading.
1314  if (mode == DECODE)
1315  for (unsigned int i=0, cnt=0; i<len; i++)
1316  {
1317  val[i] = io_buffer[cnt++];
1318  }
1319  }
1320 
1321 #else
1322 
1323  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1324  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1325  << "The XDR interface is not available in this installation");
1326 
1327 #endif
1328  return;
1329  }
1330 
1331  case READ:
1332  {
1333  libmesh_assert(in.get());
1334  libmesh_assert (in->good());
1335 
1336  for (unsigned int i=0; i<len; i++)
1337  {
1338  libmesh_assert(in.get());
1339  libmesh_assert (in->good());
1340  *in >> val[i];
1341  }
1342 
1343  return;
1344  }
1345 
1346  case WRITE:
1347  {
1348  libmesh_assert(out.get());
1349  libmesh_assert (out->good());
1350 
1351  // Save stream flags
1352  std::ios_base::fmtflags out_flags = out->flags();
1353 
1354  // We will use scientific notation with a precision of 36
1355  // digits in the following output. The desired precision and
1356  // format will automatically determine the width.
1357  *out << std::scientific
1358  << std::setprecision(36);
1359 
1360  if (line_break == libMesh::invalid_uint)
1361  for (unsigned int i=0; i<len; i++)
1362  {
1363  libmesh_assert(out.get());
1364  libmesh_assert (out->good());
1365  *out << val[i] << ' ';
1366  }
1367  else
1368  {
1369  const unsigned imax = std::min(line_break, len);
1370  unsigned int cnt=0;
1371  while (cnt < len)
1372  {
1373  for (unsigned int i=0; i<imax; i++)
1374  {
1375  libmesh_assert(out.get());
1376  libmesh_assert (out->good());
1377  *out << val[cnt++];
1378 
1379  // Write a space unless this is the last character on the current line.
1380  if (i+1 != imax)
1381  *out << " ";
1382  }
1383  libmesh_assert(out.get());
1384  libmesh_assert (out->good());
1385  *out << '\n';
1386  }
1387  }
1388 
1389  // Restore stream flags
1390  out->flags(out_flags);
1391 
1392  return;
1393  }
1394 
1395  default:
1396  libmesh_error_msg("Invalid mode = " << mode);
1397  }
1398 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

◆ data_stream() [5/7]

template<>
void libMesh::Xdr::data_stream ( std::complex< double > *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1405 of file xdr_cxx.C.

1406 {
1407  switch (mode)
1408  {
1409  case ENCODE:
1410  case DECODE:
1411  {
1412 #ifdef LIBMESH_HAVE_XDR
1413 
1414  libmesh_assert (this->is_open());
1415 
1416 
1417  if (len > 0)
1418  {
1419  std::vector<double> io_buffer (2*len);
1420 
1421  // Fill io_buffer if we are writing.
1422  if (mode == ENCODE)
1423  for (unsigned int i=0, cnt=0; i<len; i++)
1424  {
1425  io_buffer[cnt++] = val[i].real();
1426  io_buffer[cnt++] = val[i].imag();
1427  }
1428 
1429  xdr_vector(xdrs.get(),
1430  reinterpret_cast<char *>(io_buffer.data()),
1431  2*len,
1432  sizeof(double),
1433  (xdrproc_t) xdr_double);
1434 
1435  // Fill val array if we are reading.
1436  if (mode == DECODE)
1437  for (unsigned int i=0, cnt=0; i<len; i++)
1438  {
1439  double re = io_buffer[cnt++];
1440  double im = io_buffer[cnt++];
1441  val[i] = std::complex<double>(re,im);
1442  }
1443  }
1444 #else
1445 
1446  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1447  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1448  << "The XDR interface is not available in this installation");
1449 
1450 #endif
1451  return;
1452  }
1453 
1454  case READ:
1455  {
1456  libmesh_assert(in.get());
1457  libmesh_assert (in->good());
1458 
1459  for (unsigned int i=0; i<len; i++)
1460  {
1461  libmesh_assert(in.get());
1462  libmesh_assert (in->good());
1463  double re, im;
1464  *in >> re >> im;
1465  val[i] = std::complex<double>(re,im);
1466  }
1467 
1468  return;
1469  }
1470 
1471  case WRITE:
1472  {
1473  libmesh_assert(out.get());
1474  libmesh_assert (out->good());
1475 
1476  // Save stream flags
1477  std::ios_base::fmtflags out_flags = out->flags();
1478 
1479  // We will use scientific notation sufficient to exactly
1480  // represent our floating point precision in the following
1481  // output. The desired precision and format will
1482  // automatically determine the width.
1483  *out << std::scientific
1484  << std::setprecision(std::numeric_limits<double>::max_digits10);
1485 
1486  if (line_break == libMesh::invalid_uint)
1487  for (unsigned int i=0; i<len; i++)
1488  {
1489  libmesh_assert(out.get());
1490  libmesh_assert (out->good());
1491  *out << val[i].real() << ' ';
1492  *out << val[i].imag() << ' ';
1493  }
1494  else
1495  {
1496  const unsigned imax = std::min(line_break, len);
1497  unsigned int cnt=0;
1498  while (cnt < len)
1499  {
1500  for (unsigned int i=0; i<imax; i++)
1501  {
1502  libmesh_assert(out.get());
1503  libmesh_assert (out->good());
1504  *out << val[cnt].real() << ' ';
1505  *out << val[cnt].imag();
1506  cnt++;
1507 
1508  // Write a space unless this is the last character on the current line.
1509  if (i+1 != imax)
1510  *out << " ";
1511  }
1512  libmesh_assert(out.get());
1513  libmesh_assert (out->good());
1514  *out << '\n';
1515  }
1516  }
1517 
1518  // Restore stream flags
1519  out->flags(out_flags);
1520 
1521  return;
1522  }
1523 
1524  default:
1525  libmesh_error_msg("Invalid mode = " << mode);
1526  }
1527 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

◆ data_stream() [6/7]

template<>
void libMesh::Xdr::data_stream ( std::complex< long double > *  val,
const unsigned int  len,
const unsigned int  line_break 
)

Definition at line 1530 of file xdr_cxx.C.

1531 {
1532  switch (mode)
1533  {
1534  case ENCODE:
1535  case DECODE:
1536  {
1537 #ifdef LIBMESH_HAVE_XDR
1538 
1539  libmesh_assert (this->is_open());
1540 
1541  // FIXME[JWP]: How to implement this for long double? Mac OS
1542  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1543  // Linux... for now, reading/writing XDR files with long
1544  // doubles drops back to double precision, but you can still
1545  // write long double ASCII files of course.
1546 
1547  if (len > 0)
1548  {
1549  std::vector<double> io_buffer (2*len);
1550 
1551  // Fill io_buffer if we are writing.
1552  if (mode == ENCODE)
1553  for (unsigned int i=0, cnt=0; i<len; i++)
1554  {
1555  io_buffer[cnt++] = val[i].real();
1556  io_buffer[cnt++] = val[i].imag();
1557  }
1558 
1559  xdr_vector(xdrs.get(),
1560  reinterpret_cast<char *>(io_buffer.data()),
1561  2*len,
1562  sizeof(double),
1563  (xdrproc_t) xdr_double);
1564 
1565  // Fill val array if we are reading.
1566  if (mode == DECODE)
1567  for (unsigned int i=0, cnt=0; i<len; i++)
1568  {
1569  double re = io_buffer[cnt++];
1570  double im = io_buffer[cnt++];
1571  val[i] = std::complex<long double>(re, im);
1572  }
1573  }
1574 #else
1575 
1576  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1577  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1578  << "The XDR interface is not available in this installation");
1579 
1580 #endif
1581  return;
1582  }
1583 
1584  case READ:
1585  {
1586  libmesh_assert(in.get());
1587  libmesh_assert (in->good());
1588 
1589  for (unsigned int i=0; i<len; i++)
1590  {
1591  libmesh_assert(in.get());
1592  libmesh_assert (in->good());
1593  long double re, im;
1594  *in >> re >> im;
1595  val[i] = std::complex<long double>(re,im);
1596  }
1597 
1598  return;
1599  }
1600 
1601  case WRITE:
1602  {
1603  libmesh_assert(out.get());
1604  libmesh_assert (out->good());
1605 
1606 
1607  // Save stream flags
1608  std::ios_base::fmtflags out_flags = out->flags();
1609 
1610  // We will use scientific notation with a precision of
1611  // 'max_digits10' digits in the following output. The desired
1612  // precision and format will automatically determine the
1613  // width. Note: digit10 is the number of digits (in decimal
1614  // base) that can be represented without change. Equivalent
1615  // to FLT_DIG, DBL_DIG or LDBL_DIG for floating types.
1616  *out << std::scientific
1617  << std::setprecision(std::numeric_limits<long double>::max_digits10);
1618 
1619  if (line_break == libMesh::invalid_uint)
1620  for (unsigned int i=0; i<len; i++)
1621  {
1622  libmesh_assert(out.get());
1623  libmesh_assert (out->good());
1624  *out << val[i].real() << ' ' << val[i].imag() << ' ';
1625  }
1626  else
1627  {
1628  const unsigned imax = std::min(line_break, len);
1629  unsigned int cnt=0;
1630  while (cnt < len)
1631  {
1632  for (unsigned int i=0; i<imax; i++)
1633  {
1634  libmesh_assert(out.get());
1635  libmesh_assert (out->good());
1636  *out << val[cnt].real() << ' ' << val[cnt].imag();
1637  cnt++;
1638 
1639  // Write a space unless this is the last character on the current line.
1640  if (i+1 != imax)
1641  *out << " ";
1642  }
1643  libmesh_assert(out.get());
1644  libmesh_assert (out->good());
1645  *out << '\n';
1646  }
1647  }
1648 
1649  // Restore stream flags
1650  out->flags(out_flags);
1651 
1652  return;
1653  }
1654 
1655  default:
1656  libmesh_error_msg("Invalid mode = " << mode);
1657  }
1658 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

◆ data_stream() [7/7]

template<typename T >
void libMesh::Xdr::data_stream ( T *  val,
const unsigned int  len,
const unsigned int  line_break = libMesh::invalid_uint 
)

Inputs or outputs a raw data stream.

Definition at line 831 of file xdr_cxx.C.

832 {
833  switch (mode)
834  {
835  case ENCODE:
836  {
837 #ifdef LIBMESH_HAVE_XDR
838 
839  libmesh_assert (this->is_open());
840 
841  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
842 
843  xdr_vector(xdrs.get(),
844  (char *) val,
845  len,
846  size_of_type,
847  xdr_translator<T>());
848 #else
849  libmesh_error_msg("ERROR: Functionality is not available.\n" \
850  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
851  << "The XDR interface is not available in this installation");
852 
853 #endif
854  return;
855  }
856 
857  case DECODE:
858  {
859 #ifdef LIBMESH_HAVE_XDR
860 
861  libmesh_assert (this->is_open());
862 
863  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
864 
865  if (len > 0)
866  xdr_vector(xdrs.get(),
867  (char *) val,
868  len,
869  size_of_type,
870  xdr_translator<T>());
871 #else
872  libmesh_error_msg("ERROR: Functionality is not available.\n" \
873  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
874  << "The XDR interface is not available in this installation");
875 
876 #endif
877  return;
878  }
879 
880  case READ:
881  {
882  libmesh_assert(in.get());
883  libmesh_assert (in->good());
884 
885  for (unsigned int i=0; i<len; i++)
886  {
887  libmesh_assert(in.get());
888  libmesh_assert (in->good());
889  *in >> val[i];
890  }
891 
892  return;
893  }
894 
895  case WRITE:
896  {
897  libmesh_assert(out.get());
898  libmesh_assert (out->good());
899 
900  // We will use scientific notation sufficient to exactly
901  // represent our floating point precision in the following
902  // output. The desired precision and format will
903  // automatically determine the width.
904  *out << std::scientific
905  << std::setprecision(std::numeric_limits<T>::max_digits10);
906 
907  if (line_break == libMesh::invalid_uint)
908  for (unsigned int i=0; i<len; i++)
909  {
910  libmesh_assert(out.get());
911  libmesh_assert (out->good());
912  *out << val[i] << " ";
913  }
914  else
915  {
916  const unsigned imax = std::min(line_break, len);
917  unsigned int cnt=0;
918  while (cnt < len)
919  {
920  for (unsigned int i=0; i<imax; i++)
921  {
922  libmesh_assert(out.get());
923  libmesh_assert (out->good());
924  *out << val[cnt++];
925 
926  // Write a space unless this is the last character on the current line.
927  if (i+1 != imax)
928  *out << " ";
929  }
930  libmesh_assert(out.get());
931  libmesh_assert (out->good());
932  *out << '\n';
933  }
934  }
935 
936  return;
937  }
938 
939  default:
940  libmesh_error_msg("Invalid mode = " << mode);
941  }
942 }

References libMesh::DECODE, libMesh::ENCODE, in, libMesh::invalid_uint, is_open(), libMesh::libmesh_assert(), mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::CheckpointIO::write_connectivity(), libMesh::CheckpointIO::write_nodes(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

◆ do_read() [1/5]

template<typename T >
void libMesh::Xdr::do_read ( std::complex< T > &  a)
private

Definition at line 667 of file xdr_cxx.C.

668 {
669  T r, i;
670  *in >> r >> i;
671  a = std::complex<T>(r,i);
672  in->getline(comm, comm_len);
673 }

References comm, comm_len, and in.

◆ do_read() [2/5]

template<>
void libMesh::Xdr::do_read ( std::string &  a)
private

Definition at line 676 of file xdr_cxx.C.

677 {
678  in->getline(comm, comm_len);
679 
680  a = "";
681 
682  for (unsigned int c=0, sl=std::strlen(comm); c!=sl; c++)
683  {
684  if (comm[c] == '\t')
685  break;
686  a.push_back(comm[c]);
687  }
688 }

References comm, comm_len, and in.

◆ do_read() [3/5]

template<typename T >
void libMesh::Xdr::do_read ( std::vector< std::complex< T >> &  a)
private

Definition at line 707 of file xdr_cxx.C.

708 {
709  unsigned int length=0;
710  data(length, "# vector length x 2 (complex)");
711  a.resize(length);
712 
713  for (std::complex<T> & a_i : a)
714  {
715  T r, im;
716  libmesh_assert(in.get());
717  libmesh_assert (in->good());
718  *in >> r >> im;
719  a_i = std::complex<T>(r,im);
720  }
721  in->getline(comm, comm_len);
722 }

References comm, comm_len, data(), in, and libMesh::libmesh_assert().

◆ do_read() [4/5]

template<typename T >
void libMesh::Xdr::do_read ( std::vector< T > &  a)
private

Definition at line 691 of file xdr_cxx.C.

692 {
693  unsigned int length=0;
694  data(length, "# vector length");
695  a.resize(length);
696 
697  for (T & a_i : a)
698  {
699  libmesh_assert(in.get());
700  libmesh_assert (in->good());
701  *in >> a_i;
702  }
703  in->getline(comm, comm_len);
704 }

References comm, comm_len, data(), in, and libMesh::libmesh_assert().

◆ do_read() [5/5]

template<typename T >
void libMesh::Xdr::do_read ( T &  a)
private

Helper method for reading different data types.

Definition at line 660 of file xdr_cxx.C.

661 {
662  *in >> a;
663  in->getline(comm, comm_len);
664 }

References comm, comm_len, and in.

Referenced by data().

◆ do_write() [1/4]

template<typename T >
void libMesh::Xdr::do_write ( std::complex< T > &  a)
private

Definition at line 728 of file xdr_cxx.C.

729 {
730  *out << a.real() << "\t " << a.imag();
731 }

References out.

◆ do_write() [2/4]

template<typename T >
void libMesh::Xdr::do_write ( std::vector< std::complex< T >> &  a)
private

Definition at line 749 of file xdr_cxx.C.

750 {
751  std::size_t length=a.size();
752  data(length, "# vector length x 2 (complex)");
753 
754  for (std::complex<T> & a_i : a)
755  {
756  libmesh_assert(out.get());
757  libmesh_assert (out->good());
758  this->do_write(a_i);
759  *out << "\t ";
760  }
761 }

References data(), do_write(), libMesh::libmesh_assert(), and out.

◆ do_write() [3/4]

template<typename T >
void libMesh::Xdr::do_write ( std::vector< T > &  a)
private

Definition at line 734 of file xdr_cxx.C.

735 {
736  std::size_t length = a.size();
737  data(length, "# vector length");
738 
739  for (T & a_i : a)
740  {
741  libmesh_assert(out.get());
742  libmesh_assert (out->good());
743  this->do_write(a_i);
744  *out << "\t ";
745  }
746 }

References data(), do_write(), libMesh::libmesh_assert(), and out.

◆ do_write() [4/4]

template<typename T >
void libMesh::Xdr::do_write ( T &  a)
private

Helper method for writing different data types.

Definition at line 725 of file xdr_cxx.C.

725 { *out << a; }

References out.

Referenced by data(), and do_write().

◆ is_eof()

bool libMesh::Xdr::is_eof ( )
Returns
true if the Xdr file being read is at End-Of-File.
Note
This is not a const method - the only portable way to test for an impending EOF is to peek at the next byte of the file first, which may set the eof flag on the istream.

Definition at line 391 of file xdr_cxx.C.

392 {
393  switch (mode)
394  {
395  case ENCODE:
396  case DECODE:
397  {
398 #ifdef LIBMESH_HAVE_XDR
400 
401  // Are we already at eof?
402  if (feof(fp))
403  return true;
404 
405  // Or about to reach eof?
406  int next = fgetc(fp);
407  if (next == EOF)
408  {
409  // We should *only* be at EOF, not otherwise broken
410  libmesh_assert(feof(fp));
411  libmesh_assert(!ferror(fp));
412 
413  // Reset the EOF indicator
414  clearerr(fp);
415  libmesh_assert(!ferror(fp));
416 
417  // We saw EOF
418  return true;
419  }
420 
421  // We didn't see EOF; restore whatever we did see.
422  ungetc(next, fp);
423  break;
424 #else
425 
426  libmesh_error_msg("ERROR: Functionality is not available.\n" \
427  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
428  << "The XDR interface is not available in this installation");
429 
430  return false;
431 
432 #endif
433 
434  }
435  case READ:
436  {
437  libmesh_assert(in.get());
438 
439  // Are we already at eof?
440  if (in->eof())
441  return true;
442 
443  // Or about to reach eof?
444  int next = in->peek();
445  if (next == EOF)
446  {
447  // We should *only* be at EOF, not otherwise broken
448  libmesh_assert(in->eof());
449  libmesh_assert(!in->fail());
450 
451  // Reset the EOF indicator
452  in->clear();
453  libmesh_assert(in->good());
454 
455  // We saw EOF
456  return true;
457  }
458  break;
459  }
460  default:
461  libmesh_error();
462  }
463 
464  return false;
465 }

References libMesh::DECODE, libMesh::ENCODE, fp, in, libMesh::libmesh_assert(), mode, libMesh::MeshTools::Subdivision::next, and libMesh::READ.

◆ is_open()

bool libMesh::Xdr::is_open ( ) const
Returns
true if the Xdr file is open, false if it is closed.

Definition at line 341 of file xdr_cxx.C.

342 {
343  switch (mode)
344  {
345  case ENCODE:
346  case DECODE:
347  {
348 #ifdef LIBMESH_HAVE_XDR
349 
350  if (fp)
351  if (xdrs)
352  return true;
353 
354  return false;
355 
356 #else
357 
358  libmesh_error_msg("ERROR: Functionality is not available.\n" \
359  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
360  << "The XDR interface is not available in this installation");
361 
362  return false;
363 
364 #endif
365 
366  }
367 
368  case READ:
369  {
370  if (in.get() != nullptr)
371  return in->good();
372  return false;
373  }
374 
375  case WRITE:
376  {
377  if (out.get() != nullptr)
378  return out->good();
379  return false;
380  }
381 
382  default:
383  libmesh_error_msg("Invalid mode = " << mode);
384  }
385 
386  return false;
387 }

References libMesh::DECODE, libMesh::ENCODE, fp, in, mode, out, libMesh::READ, libMesh::WRITE, and xdrs.

Referenced by data(), data_stream(), and libMesh::System::read_parallel_data().

◆ open()

void libMesh::Xdr::open ( const std::string &  name)

Opens the file.

Definition at line 162 of file xdr_cxx.C.

163 {
164  file_name = name;
165 
166  if (name == "")
167  return;
168 
169  switch (mode)
170  {
171  case ENCODE:
172  case DECODE:
173  {
174 #ifdef LIBMESH_HAVE_XDR
175 
176  fp = fopen(name.c_str(), (mode == ENCODE) ? "w" : "r");
177  if (!fp)
178  libmesh_file_error(name.c_str());
179  xdrs = libmesh_make_unique<XDR>();
180  xdrstdio_create (xdrs.get(), fp, (mode == ENCODE) ? XDR_ENCODE : XDR_DECODE);
181 #else
182 
183  libmesh_error_msg("ERROR: Functionality is not available.\n" \
184  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
185  << "The XDR interface is not available in this installation");
186 
187 #endif
188  return;
189 
190  }
191 
192  case READ:
193  {
194  gzipped_file = (name.size() - name.rfind(".gz") == 3);
195  bzipped_file = (name.size() - name.rfind(".bz2") == 4);
196  xzipped_file = (name.size() - name.rfind(".xz") == 3);
197 
198  if (gzipped_file)
199  {
200 #ifdef LIBMESH_HAVE_GZSTREAM
201  igzstream * inf = new igzstream;
202  libmesh_assert(inf);
203  in.reset(inf);
204  inf->open(name.c_str(), std::ios::in);
205 #else
206  libmesh_error_msg("ERROR: need gzstream to handle .gz files!!!");
207 #endif
208  }
209  else
210  {
211  std::ifstream * inf = new std::ifstream;
212  libmesh_assert(inf);
213  in.reset(inf);
214 
215  std::string new_name = unzip_file(name);
216 
217  inf->open(new_name.c_str(), std::ios::in);
218  }
219 
220  libmesh_assert(in.get());
221 
222  if (!in->good())
223  libmesh_file_error(name);
224  return;
225  }
226 
227  case WRITE:
228  {
229  gzipped_file = (name.size() - name.rfind(".gz") == 3);
230  bzipped_file = (name.size() - name.rfind(".bz2") == 4);
231  xzipped_file = (name.size() - name.rfind(".xz") == 3);
232 
233  if (gzipped_file)
234  {
235 #ifdef LIBMESH_HAVE_GZSTREAM
236  ogzstream * outf = new ogzstream;
237  libmesh_assert(outf);
238  out.reset(outf);
239  outf->open(name.c_str(), std::ios::out);
240 #else
241  libmesh_error_msg("ERROR: need gzstream to handle .gz files!!!");
242 #endif
243  }
244  else
245  {
246  std::ofstream * outf = new std::ofstream;
247  libmesh_assert(outf);
248  out.reset(outf);
249 
250  std::string new_name = name;
251 
252  if (bzipped_file)
253  new_name.erase(new_name.end() - 4, new_name.end());
254 
255  if (xzipped_file)
256  new_name.erase(new_name.end() - 3, new_name.end());
257 
258  outf->open(new_name.c_str(), std::ios::out);
259  }
260 
261  libmesh_assert(out.get());
262  libmesh_assert (out->good());
263  return;
264  }
265 
266  default:
267  libmesh_error_msg("Invalid mode = " << mode);
268  }
269 }

References bzipped_file, libMesh::DECODE, libMesh::ENCODE, file_name, fp, gzipped_file, in, libMesh::libmesh_assert(), mode, libMesh::Quality::name(), libMesh::out, out, libMesh::READ, libMesh::WRITE, xdrs, and xzipped_file.

Referenced by Xdr().

◆ operator<<()

template<typename T >
Xdr& libMesh::Xdr::operator<< ( T &  a)
inline

Same, but provides an ostream like interface.

Definition at line 136 of file xdr_cxx.h.

136 { libmesh_assert (writing()); data(a); return *this; }

References data(), libMesh::libmesh_assert(), and writing().

◆ operator>>()

template<typename T >
Xdr& libMesh::Xdr::operator>> ( T &  a)
inline

Same, but provides an istream like interface.

Definition at line 142 of file xdr_cxx.h.

142 { libmesh_assert (reading()); data(a); return *this; }

References data(), libMesh::libmesh_assert(), and reading().

◆ reading()

bool libMesh::Xdr::reading ( ) const
inline

◆ set_version()

void libMesh::Xdr::set_version ( int  ver)
inline

Sets the version of the file that is being read.

Definition at line 158 of file xdr_cxx.h.

158 { version_number = ver; }

References version_number.

Referenced by libMesh::EquationSystems::_read_impl(), and libMesh::EquationSystems::write().

◆ version()

int libMesh::Xdr::version ( ) const
inline

Gets the version of the file that is being read.

Definition at line 163 of file xdr_cxx.h.

163 { return version_number; }

References version_number.

Referenced by libMesh::System::read_header(), and libMesh::System::read_serialized_vector().

◆ writing()

bool libMesh::Xdr::writing ( ) const
inline

Member Data Documentation

◆ bzipped_file

bool libMesh::Xdr::bzipped_file
private

Definition at line 241 of file xdr_cxx.h.

Referenced by close(), and open().

◆ comm

char libMesh::Xdr::comm[xdr_MAX_STRING_LENGTH]
private

Definition at line 236 of file xdr_cxx.h.

Referenced by comment(), and do_read().

◆ comm_len

const int libMesh::Xdr::comm_len
private

A buffer to put comment strings into.

Definition at line 235 of file xdr_cxx.h.

Referenced by comment(), and do_read().

◆ file_name

std::string libMesh::Xdr::file_name
private

The file name.

Definition at line 205 of file xdr_cxx.h.

Referenced by close(), and open().

◆ fp

FILE* libMesh::Xdr::fp
private

File pointer.

Definition at line 218 of file xdr_cxx.h.

Referenced by close(), is_eof(), is_open(), and open().

◆ gzipped_file

bool libMesh::Xdr::gzipped_file
private

Are we reading/writing zipped files?

Definition at line 241 of file xdr_cxx.h.

Referenced by open().

◆ in

std::unique_ptr<std::istream> libMesh::Xdr::in
private

The input file stream.

Definition at line 225 of file xdr_cxx.h.

Referenced by close(), comment(), data(), data_stream(), do_read(), is_eof(), is_open(), and open().

◆ mode

const XdrMODE libMesh::Xdr::mode
private

The mode used for accessing the file.

Definition at line 200 of file xdr_cxx.h.

Referenced by access_mode(), close(), comment(), data(), data_stream(), is_eof(), is_open(), open(), reading(), and writing().

◆ out

std::unique_ptr<std::ostream> libMesh::Xdr::out
private

The output file stream.

Definition at line 230 of file xdr_cxx.h.

Referenced by close(), comment(), data(), data_stream(), do_write(), is_open(), and open().

◆ version_number

int libMesh::Xdr::version_number
private

Version of the file being read.

Definition at line 246 of file xdr_cxx.h.

Referenced by set_version(), and version().

◆ xdrs

std::unique_ptr<XDR> libMesh::Xdr::xdrs
private

Pointer to the standard XDR struct.

See the standard header file rpc/rpc.h for more information.

Definition at line 213 of file xdr_cxx.h.

Referenced by close(), data(), data_stream(), is_open(), and open().

◆ xzipped_file

bool libMesh::Xdr::xzipped_file
private

Definition at line 241 of file xdr_cxx.h.

Referenced by close(), and open().


The documentation for this class was generated from the following files:
libMesh::MeshTools::Subdivision::next
static const unsigned int next[3]
A lookup table for the increment modulo 3 operation, for iterating through the three nodes per elemen...
Definition: mesh_subdivision_support.h:102
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::Xdr::gzipped_file
bool gzipped_file
Are we reading/writing zipped files?
Definition: xdr_cxx.h:241
libMesh::Xdr::file_name
std::string file_name
The file name.
Definition: xdr_cxx.h:205
libMesh::Xdr::comm_len
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:235
libMesh::WRITE
Definition: enum_xdr_mode.h:40
libMesh::Xdr::version_number
int version_number
Version of the file being read.
Definition: xdr_cxx.h:246
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::Xdr::do_write
void do_write(T &a)
Helper method for writing different data types.
Definition: xdr_cxx.C:725
libMesh::Xdr::writing
bool writing() const
Definition: xdr_cxx.h:116
libMesh::Xdr::reading
bool reading() const
Definition: xdr_cxx.h:110
libMesh::Xdr::data
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:766
libMesh::DECODE
Definition: enum_xdr_mode.h:39
libMesh::Xdr::mode
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:200
libMesh::Xdr::do_read
void do_read(T &a)
Helper method for reading different data types.
Definition: xdr_cxx.C:660
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::Xdr::open
void open(const std::string &name)
Opens the file.
Definition: xdr_cxx.C:162
xdr_MAX_STRING_LENGTH
const unsigned int xdr_MAX_STRING_LENGTH
Definition: xdr_cxx.h:43
libMesh::ENCODE
Definition: enum_xdr_mode.h:38
libMesh::Xdr::close
void close()
Closes the file if it is open.
Definition: xdr_cxx.C:273
libMesh::Xdr::xzipped_file
bool xzipped_file
Definition: xdr_cxx.h:241
libMesh::Xdr::is_open
bool is_open() const
Definition: xdr_cxx.C:341
libMesh::Xdr::out
std::unique_ptr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:230
libMesh::Xdr::fp
FILE * fp
File pointer.
Definition: xdr_cxx.h:218
libMesh::Xdr::bzipped_file
bool bzipped_file
Definition: xdr_cxx.h:241
libMesh::Xdr::in
std::unique_ptr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:225
libMesh::Xdr::xdrs
std::unique_ptr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:213
libMesh::out
OStreamProxy out
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::Xdr::comm
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:236