Facebook
From Funky Crocodile, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 69
  1. vector<Matrix> LoadMatrixes(string FileName)
  2. {
  3.         int counter = 0;
  4.  
  5.         ifstream f(FileName);
  6.         string line, temp;
  7.         regex squareBracketsRegex("\\[([^\\]\\[]+)\\]");
  8.         regex matrixRegex("(\\d+.\\d+)+");
  9.         while (getline(f, line))
  10.         {
  11.                 if (line[0] == 'M' || line[0] == '-')
  12.                 {
  13.                         //end of matrix
  14.                         cout << "----------------" << endl;
  15.  
  16.                         //regex search and append to vector of matrix
  17.                         // "\[([^\]\[]+)\]"  -> [...]
  18.                         // "(\d+.\d+)+"
  19.  
  20.                         if (temp.length() > 0)
  21.                         {
  22.                                 for (smatch m; regex_search(temp, m, squareBracketsRegex); temp = m.suffix())
  23.                                 {
  24.                                         //cout << m[1] << endl;
  25.  
  26.                                         //Find each number
  27.                                         string row = m[1].str();
  28.                                         for (smatch n; regex_search(row, n, matrixRegex); row = n.suffix())
  29.                                         {
  30.                                                 cout << n[1] << ", ";
  31.                                         }
  32.                                         cout << endl;
  33.                                 }
  34.  
  35.                                 //clear temp
  36.                                 temp = "";
  37.                         }
  38.                 }
  39.                 else
  40.                 {
  41.                         //Add line for regex
  42.                         temp += line;
  43.                 }
  44.  
  45.                 //Debug line
  46.                 if (bDebug)
  47.                 {
  48.                         cout << "| " << counter << " | ";
  49.                         if (counter % 8 == 0 && counter != 0)
  50.                         {
  51.                                 cout << endl;
  52.                         }
  53.                         counter++;
  54.                 }
  55.         }
  56.         return matrixes;
  57. }