1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

function to read file lists and progress bar class

This commit is contained in:
Antonin Portelli 2014-06-04 14:43:36 +02:00
parent ba25380269
commit b17e2c0c3c
3 changed files with 65 additions and 13 deletions

View File

@ -78,20 +78,9 @@ void Dataset<T>::load(const std::string &listFileName,
const std::string &dataName)
{
FileType file;
std::ifstream listFile;
char dataFileNameBuf[MAX_PATH_LENGTH];
std::vector<std::string> dataFileName;
listFile.open(listFileName, std::ios::in);
while (!listFile.eof())
{
listFile.getline(dataFileNameBuf, MAX_PATH_LENGTH);
if (!std::string(dataFileNameBuf).empty())
{
dataFileName.push_back(dataFileNameBuf);
}
}
listFile.close();
dataFileName = readManifest(listFileName);
this->resize(dataFileName.size());
for (Index i = 0; i < static_cast<Index>(dataFileName.size()); ++i)
{

View File

@ -31,3 +31,22 @@ const string Env::msgPrefix = "[" + strFrom(PACKAGE_NAME) + " v"
void Env::function(void)
{}
ostream & Latan::operator<<(ostream &out, const ProgressBar &&bar)
{
const Index nTick = bar.nCol_*bar.current_/bar.total_;
out << "[";
for (Index i = 0; i < nTick; ++i)
{
out << "=";
}
for (Index i = nTick; i < bar.nCol_; ++i)
{
out << " ";
}
out << "] " << bar.current_ << "/" << bar.total_;
out.flush();
return out;
}

View File

@ -25,6 +25,8 @@
#include <LatAnalyze/Eigen/Dense>
#include <complex>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <sstream>
@ -240,6 +242,48 @@ inline IVec strTo<IVec>(const std::string &str)
return res;
}
// Manifest file reader ////////////////////////////////////////////////////////
inline std::vector<std::string> readManifest(const std::string manFileName)
{
std::vector<std::string> list;
std::ifstream manFile;
char buf[MAX_PATH_LENGTH];
manFile.open(manFileName);
while (!manFile.eof())
{
manFile.getline(buf, MAX_PATH_LENGTH);
if (!std::string(buf).empty())
{
list.push_back(buf);
}
}
manFile.close();
return list;
}
// Progress bar class //////////////////////////////////////////////////////////
class ProgressBar
{
public:
// constructor
template <typename A, typename B>
ProgressBar(const A current, const B total, const Index nCol = 60);
// IO
friend std::ostream & operator<<(std::ostream &out,
const ProgressBar &&bar);
private:
Index current_, total_, nCol_;
};
template <typename A, typename B>
ProgressBar::ProgressBar(const A current, const B total, const Index nCol)
: current_(static_cast<Index>(current))
, total_(static_cast<Index>(total))
, nCol_(nCol)
{}
END_NAMESPACE
#include <LatAnalyze/Exceptions.hpp>