* Print to given stream, one element per line.
*/
void print (ostream &) const;
+
+ /**
+ * Write the vector en bloc to a file. This
+ * is done in a binary mode, so the output
+ * is neither readable by humans nor
+ * (probably) by other computers using
+ * a different operating system of number
+ * format.
+ */
+ void block_write (ostream &out) const;
+
+ /**
+ * Read a vector en block from a file. This
+ * is done using the inverse operations to
+ * the above function, so it is reasonably
+ * fast because the bitstream is not
+ * interpreted.
+ *
+ * The vector is resized if necessary.
+ *
+ * A primitive form of error checking is
+ * performed which will recognize the
+ * bluntest attempts to interpret some
+ * data as a vector stored bitwise to a
+ * file, but not more.
+ */
+ void block_read (istream &in);
//@}
/**
+template <typename Number>
+void Vector<Number>::block_write (ostream &out) const {
+ AssertThrow (out, ExcIO());
+
+ out << size() << endl << '[';
+ out.write (reinterpret_cast<const char*>(begin()),
+ reinterpret_cast<const char*>(end())
+ - reinterpret_cast<const char*>(begin()));
+ out << ']';
+
+ AssertThrow (out, ExcIO());
+};
+
+
+
+template <typename Number>
+void Vector<Number>::block_read (istream &in) {
+ AssertThrow (in, ExcIO());
+
+ unsigned int sz;
+ in >> sz;
+ // fast initialization, since the
+ // data elements are overwritten anyway
+ reinit (sz, true);
+
+ char c;
+ in >> c;
+ AssertThrow (c=='[', ExcIO());
+
+ in.read (reinterpret_cast<void*>(begin()),
+ reinterpret_cast<const char*>(end())
+ - reinterpret_cast<const char*>(begin()));
+
+ in >> c;
+ AssertThrow (c==']', ExcIO());
+ AssertThrow (in, ExcIO());
+};
+