// const char *zero_string = " ",
// const double denominator = 1.) const;
+ /**
+ * Write the data of this object
+ * in binary mode to a file.
+ *
+ * Note that this binary format
+ * is platform dependent.
+ */
+ void block_write (std::ostream &out) const;
+
+ /**
+ * Read data that has previously
+ * been written by
+ * @p{block_write}.
+ *
+ * The object is resized on this
+ * operation, and all previous
+ * contents are lost.
+ *
+ * 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 (std::istream &in);
+
+
/**
* Determine an estimate for the
* memory consumption (in bytes)
<< ") cannot be allocated.");
private:
/**
- * Find an entry. Return a
+ * Find an entry and return a
+ * const pointer. Return a
* zero-pointer if the entry does
* not exist.
*/
const Entry* locate (const unsigned int row,
const unsigned int col) const;
+ /**
+ * Find an entry and return a
+ * writable pointer. Return a
+ * zero-pointer if the entry does
+ * not exist.
+ */
+ Entry* locate (const unsigned int row,
+ const unsigned int col);
+
/**
* Find an entry or generate it.
*/
template <typename number>
inline
-const typename SparseMatrixEZ<number>::Entry*
+typename SparseMatrixEZ<number>::Entry*
SparseMatrixEZ<number>::locate (const unsigned int row,
- const unsigned int col) const
+ const unsigned int col)
{
Assert (row<m(), ExcIndexRange(row,0,m()));
Assert (col<n(), ExcIndexRange(col,0,n()));
const unsigned int end = r.start + r.length;
for (unsigned int i=r.start;i<end;++i)
{
- const Entry * const entry = &data[i];
+ Entry * const entry = &data[i];
if (entry->column == col)
return entry;
if (entry->column == Entry::invalid)
+template <typename number>
+inline
+const typename SparseMatrixEZ<number>::Entry*
+SparseMatrixEZ<number>::locate (const unsigned int row,
+ const unsigned int col) const
+{
+ SparseMatrixEZ<number>* t = const_cast<SparseMatrixEZ<number>*> (this);
+ return t->locate(row,col);
+}
+
+
template <typename number>
inline
typename SparseMatrixEZ<number>::Entry*
}
+template <typename number>
+void
+SparseMatrixEZ<number>::block_write (std::ostream &out) const
+{
+ AssertThrow (out, ExcIO());
+
+ // first the simple objects,
+ // bracketed in [...]
+ out << '[' << row_info.size() << "]["
+ << n_columns << "]["
+ << data.size() << "]["
+ << increment << "][";
+ // then write out real data
+ typename std::vector<RowInfo>::const_iterator r = row_info.begin();
+ const typename std::vector<RowInfo>::const_iterator re = row_info.end();
+
+ while (r != re)
+ {
+ out.write(reinterpret_cast<const char*>(&*r),
+ sizeof(RowInfo));
+ ++r;
+ }
+
+ out << "][";
+
+ typename std::vector<Entry>::const_iterator d = data.begin();
+ const typename std::vector<Entry>::const_iterator de = data.end();
+
+ while (d != de)
+ {
+ out.write(reinterpret_cast<const char*>(&*d),
+ sizeof(Entry));
+ ++d;
+ }
+
+ out << ']';
+
+ AssertThrow (out, ExcIO());
+}
+
+
+#define CHECKFOR(in,a,c) {in >> c; AssertThrow(c == a, ExcIO());}
+
+template <typename number>
+void
+SparseMatrixEZ<number>::block_read (std::istream &in)
+{
+ AssertThrow (in, ExcIO());
+
+ char c;
+ int n;
+ // first read in simple data
+ CHECKFOR(in,'[',c);
+ in >> n;
+ row_info.resize(n);
+
+ CHECKFOR(in,']',c);
+ CHECKFOR(in,'[',c);
+ in >> n_columns;
+
+ CHECKFOR(in,']',c);
+ CHECKFOR(in,'[',c);
+ in >> n;
+ data.resize(n);
+
+ CHECKFOR(in,']',c);
+ CHECKFOR(in,'[',c);
+ in >> increment;
+
+ CHECKFOR(in,']',c);
+ CHECKFOR(in,'[',c);
+
+ // then read data
+ for (unsigned int i=0;i<row_info.size();++i)
+ in.read(reinterpret_cast<char*>(&row_info[i]),
+ sizeof(RowInfo));
+
+ CHECKFOR(in,']',c);
+ CHECKFOR(in,'[',c);
+
+ for (unsigned int i=0;i<data.size();++i)
+ in.read(reinterpret_cast<char*>(&data[i]),
+ sizeof(Entry));
+
+ CHECKFOR(in,']',c);
+}
+
#endif // __deal2__sparse_matrix_ez_templates_h