Go to the documentation of this file.00001 #ifndef GUARD_surveypxbimagereader_h
00002 #define GUARD_surveypxbimagereader_h
00003
00004 #include <sstream>
00005 #include <vector>
00006 #include <fstream>
00007 #include <string>
00008
00010 template <class T> class SurveyPxbImageReader
00011 {
00012 public:
00013 typedef std::vector<T> measurements_t;
00014
00015
00017 SurveyPxbImageReader() {};
00019 SurveyPxbImageReader(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800)
00020 {
00021 read(infile, measurements, reserve);
00022 };
00023
00025 SurveyPxbImageReader(std::string filename, measurements_t &measurements, SurveyPxbImage::count_t reserve = 800)
00026 {
00027 std::ifstream infile(filename.c_str());
00028 if (!infile)
00029 {
00030 std::cerr << "Cannot open file " << filename
00031 << " - operation aborted." << std::endl;
00032 }
00033 read(infile, measurements, reserve);
00034 };
00035
00042 SurveyPxbImage::count_t read(std::ifstream &infile, measurements_t &measurements, SurveyPxbImage::count_t reserve = 830)
00043 {
00044
00045
00046 measurements.clear();
00047 measurements.reserve(reserve);
00048
00049
00050 std::string aLine;
00051
00052
00053 while (std::getline(infile,aLine))
00054 {
00055
00056 std::string stripped = "";
00057 std::string::iterator iter = std::find(aLine.begin(), aLine.end(), '#');
00058 std::copy(aLine.begin(), iter, std::back_inserter(stripped));
00059
00060 std::istringstream iss(stripped, std::istringstream::in);
00061 T curMeas(iss);
00062 if (curMeas.isValid())
00063 {
00064 measurements.push_back(curMeas);
00065 }
00066 }
00067
00068 return measurements.size();
00069 }
00070
00071 protected:
00072
00073 };
00074
00075 #endif
00076