]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add raw read/write functionality.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 28 Feb 1999 19:29:15 +0000 (19:29 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 28 Feb 1999 19:29:15 +0000 (19:29 +0000)
git-svn-id: https://svn.dealii.org/trunk@929 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/vector.h
deal.II/lac/include/lac/vector.templates.h

index 7ae125e0f5f09027433f54cb34ea3b82a592b721..65b5ece2a50b9bcb46c17a62785bec5502634e1f 100644 (file)
@@ -381,6 +381,33 @@ class Vector {
                                      * 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);
                                     //@}
 
                                     /**
index b05f8cf91f4624bba43aa8769c83ac01447976f3..7a8205afb894815074eb2814b0c5e4126fc17602 100644 (file)
@@ -554,3 +554,41 @@ void Vector<Number>::print (ostream &out) const {
 
 
 
+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());
+};
+

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.