00001 /*************************************************************************** 00002 mtxdataiterator.h - description 00003 ------------------- 00004 begin : Thu Dec 4 2003 00005 copyright : (C) 2003 by Roman Geus 00006 email : roman.geus@psi.ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef MTXDATAITERATOR_H 00019 #define MTXDATAITERATOR_H 00020 00021 #include <iostream> 00022 00038 using namespace std; 00039 00040 class MtxDataIterator 00041 { 00042 public: // Public structs and enums 00044 struct Triplet { int row; int col; double val; }; 00046 enum MatrixType { sparse, dense }; 00047 enum StorageScheme { symmetric, general, skew, hermitian }; 00048 enum ElementType { complex, real, pattern, integer }; 00049 public: // Public methods 00058 MtxDataIterator(istream& istr, bool iterate_mirror); 00059 virtual ~MtxDataIterator(); 00061 virtual const int& get_rows() const; 00063 virtual const int& get_cols() const; 00067 virtual const int& get_nnz() const; 00069 Triplet& operator*() 00070 { return _triplet; } 00072 MtxDataIterator& operator++(); 00074 bool eof() const 00075 { return _nnz_read > _nnz; } 00077 virtual const MatrixType& get_matrix_type() const 00078 { return _matrix_type; } 00080 virtual const StorageScheme& get_storage_scheme() const 00081 { return _storage_scheme; } 00083 virtual const ElementType& get_element_type() const 00084 { return _element_type; } 00085 protected: // Protected methods 00087 void read_header(); 00089 void read_next_triplet(); 00090 protected: // Protected attributes 00092 int _cols; 00094 int _rows; 00096 int _nnz; 00098 istream* _istr; 00100 Triplet _triplet; 00102 int _nnz_read; 00104 MatrixType _matrix_type; 00106 StorageScheme _storage_scheme; 00108 ElementType _element_type; 00110 bool _iterate_mirror; 00112 bool _last_mirrored; 00113 }; 00114 00115 #endif