-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataReader.hpp
59 lines (54 loc) · 1.19 KB
/
DataReader.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* @Descripttion:
* @version:
* @Author: springhser
* @Date: 2021-05-25 20:48:06
* @LastEditors: springhser
* @LastEditTime: 2021-05-26 21:36:29
*/
#ifndef DATA_READER_HPP
#define DATA_READER_HPP
#include <iostream>
#include <iomanip> // for setw() and ws
#include <string>
#include <fstream>
#include <cstdlib>
#include<vector>
#include "Point.hpp"
#include "Utils/HelpTool.hpp"
/**
* @brief read tsp data from file
* @param ff file handle
* @param point_list the result
* @return true:success, false:failed
*/
class DataReader
{
public:
static bool addContents(std::ifstream& ff, Points& point_list)
{
try
{
int x_coord;
int y_coord;
int citi_no;
int num_of_cities;
ff >> num_of_cities;
for(int i = 0; i<num_of_cities; i++)
{
ff >> citi_no; // useless
ff >> x_coord;
ff >> y_coord;
Point2D p(x_coord, y_coord);
point_list.push_back(p);
}
}
catch(...)
{
PRINTN("read file error");
return false;
}
return true;
}
};
#endif