2018-04-08 15:21:54 +00:00
|
|
|
//
|
2018-06-07 05:25:25 +00:00
|
|
|
// arma-flow/reader.cpp
|
2018-04-08 15:21:54 +00:00
|
|
|
//
|
|
|
|
// @author CismonX
|
|
|
|
//
|
|
|
|
|
2018-04-05 11:01:10 +00:00
|
|
|
#include <experimental/filesystem>
|
|
|
|
|
2018-04-08 15:21:54 +00:00
|
|
|
#include "reader.hpp"
|
2018-04-05 11:01:10 +00:00
|
|
|
|
|
|
|
namespace flow
|
|
|
|
{
|
2018-04-08 15:21:54 +00:00
|
|
|
bool reader::from_csv_file(const std::string& path, bool remove_first_line)
|
2018-04-05 11:01:10 +00:00
|
|
|
{
|
|
|
|
std::ifstream ifstream;
|
|
|
|
ifstream.exceptions(std::ifstream::failbit);
|
|
|
|
namespace fs = std::experimental::filesystem;
|
|
|
|
try {
|
2018-04-08 15:21:54 +00:00
|
|
|
ifstream.open(
|
|
|
|
#ifdef _WIN32
|
|
|
|
path[1] == ':'
|
|
|
|
#else
|
|
|
|
path[0] == '/'
|
|
|
|
#endif // _WIN32
|
|
|
|
? path : fs::current_path().string() + '/' + path);
|
2018-12-13 12:33:02 +00:00
|
|
|
if (remove_first_line) {
|
2018-04-05 11:01:10 +00:00
|
|
|
ifstream.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
2018-12-13 12:33:02 +00:00
|
|
|
}
|
2018-04-09 06:15:16 +00:00
|
|
|
return do_read(ifstream);
|
2018-04-05 11:01:10 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception&) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 14:57:08 +00:00
|
|
|
const arma::mat& reader::get_mat() const
|
2018-04-05 11:01:10 +00:00
|
|
|
{
|
|
|
|
return mat_;
|
|
|
|
}
|
|
|
|
}
|