Mercurial Hosting > traffic-intelligence
comparison c/utils.cpp @ 1002:6c5ce3ec497e
improved handling of path for feature based tracking
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 01 Jun 2018 17:19:24 -0400 |
parents | bee0e7407af7 |
children |
comparison
equal
deleted
inserted
replaced
1001:cc7c6b821ae6 | 1002:6c5ce3ec497e |
---|---|
1 #include "utils.hpp" | 1 #include "utils.hpp" |
2 | 2 |
3 #include <boost/foreach.hpp> | 3 #include <boost/foreach.hpp> |
4 #include <boost/filesystem.hpp> | |
4 | 5 |
5 #include <iostream> | 6 #include <iostream> |
6 #include <fstream> | 7 #include <fstream> |
8 | |
9 namespace fs = boost::filesystem; // soon std | |
7 | 10 |
8 using namespace std; | 11 using namespace std; |
9 | 12 |
10 std::vector<std::vector<float> > loadNumbers(const string& filename, const string& separator /* = " " */) { | 13 std::vector<std::vector<float> > loadNumbers(const string& filename, const string& separator /* = " " */) { |
11 ifstream in(filename.c_str()); | 14 ifstream in(filename.c_str()); |
23 result.push_back(numbers); | 26 result.push_back(numbers); |
24 } | 27 } |
25 } | 28 } |
26 | 29 |
27 return result; | 30 return result; |
31 } | |
32 | |
33 std::string getRelativeFilename(const std::string& parentDirname, const std::string& filename) { | |
34 fs::path parentPath(parentDirname); | |
35 fs::path filePath(filename); | |
36 if (filePath.is_absolute()) | |
37 return filename; | |
38 else | |
39 return (parentPath/filePath).string(); | |
28 } | 40 } |
29 | 41 |
30 int toInt(const std::string& s) { int i; fromString(i, s); return i;} //atoi | 42 int toInt(const std::string& s) { int i; fromString(i, s); return i;} //atoi |
31 | 43 |
32 float toFloat(const std::string& s) { float x; fromString(x, s); return x;}// lexical_cast<float>(s) | 44 float toFloat(const std::string& s) { float x; fromString(x, s); return x;}// lexical_cast<float>(s) |