This repository has been archived on 2018-12-13. You can view files and clone it, but cannot push or open issues or pull requests.
arma-flow/src/reader.cpp

41 lines
908 B
C++
Raw Permalink Normal View History

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
//
#include "reader.hpp"
2018-04-05 11:01:10 +00:00
#include <experimental/filesystem>
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
}
return do_read(ifstream);
2018-04-05 11:01:10 +00:00
}
catch (const std::exception&) {
return false;
}
}
const arma::mat& reader::get_mat() const
2018-04-05 11:01:10 +00:00
{
return mat_;
}
}