Advertisement
Guest User

Untitled

a guest
May 27th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include<sstream>
  3. #include "../stringstreamenumerator.hpp"
  4.  
  5. using namespace std;
  6.  
  7. class MatrixSorFolytEnum: public Enumerator<pair<int3,pair<int,int>>>
  8. {
  9.     public:
  10.         ifstream _f;
  11.         bool _end;
  12.         pair<int3,pair<int,int>> _df;
  13.  
  14.         enum Exceptions { OPEN_ERROR };
  15.         MatrixSorFolytEnum(string filename){
  16.             _f.open(filename.c_str());
  17.             if(_f.fail()) throw OPEN_ERROR;
  18.             _end = false;
  19.         }
  20.         ~MatrixSorFolytEnum() {
  21.             _f.close();
  22.         }
  23.  
  24.         int i,j;
  25.         StringStreamEnumerator<int3> *en;
  26.  
  27.         void first() {
  28.             i=1;j=1;
  29.             string line;
  30.             getline(_f,line,'\n');
  31.             stringstream stream(line);
  32.             en = new StringStreamEnumerator<int3>(stream);
  33.             en->first();
  34.             //cout << en->current().getNum() << endl;
  35.         }
  36.  
  37.         void next() {
  38.             en->next();
  39.             if (!en->end()) {
  40.                 j++;
  41.  
  42.             } else {
  43.                 j=1;
  44.                 i++;
  45.                 string line;
  46.                 getline(_f,line,'\n');
  47.                 stringstream stream(line);
  48.                 en = new StringStreamEnumerator<int3>(stream);
  49.                 en->first();
  50.             }
  51.         }
  52.         bool end() const{
  53.             return ( _f.eof() && en->end());
  54.         }
  55.         pair<int3,pair<int,int>> current() const {
  56.             pair<int3,pair<int,int>> sajt;
  57.             sajt.first=en->current();
  58.             sajt.second.first=i;
  59.             sajt.second.second=j;
  60.             return sajt;
  61.         }
  62.     private:
  63. };
  64.  
  65. #endif // MATRIXSORFOLYTENUM_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement