file2Line.h

Go to the documentation of this file.
00001 #ifndef FILE_2_LINE_H
00002 #define FILE_2_LINE_H
00003 
00013 #include "typeUtils.h"
00014 #include <fstream>
00015 #include <iterator>
00016 
00017 
00018 namespace VXV {
00025   template<class T> void File2Line(std::vector<std::vector<T> >& v,
00026                                    const char* fname) {
00027     std::ifstream from(fname);
00028 
00029     std::vector<T> line;
00030     int pre_x = 0, pre_y = 0;
00031     for (std::istream_iterator<int> it(from);
00032          it != std::istream_iterator<int>();) {
00033       int x = *it++;
00034       if (it == std::istream_iterator<int>()) {
00035         break;
00036       }
00037       int y = *it++;
00038       if (line.empty() || ((pre_x != x) || (pre_y != y))) {
00039         line.push_back(T(x, y));
00040       } else if (line.size() > 1) {
00041         v.push_back(line);
00042         line.clear();
00043       }
00044       pre_x = x;
00045       pre_y = y;
00046     }
00047   };
00048 }
00049 
00050 #endif /* !FILE_2_LINE_H */
00051 

Generated on Mon Apr 13 22:52:05 2009 by  doxygen 1.5.7.1