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

IO: code improvement

This commit is contained in:
Antonin Portelli 2015-11-18 19:46:52 +00:00
parent 4f2e87cf4f
commit a4999a53fd
2 changed files with 12 additions and 44 deletions

View File

@ -25,20 +25,9 @@ using namespace Latan;
string Io::getFirstName(const string &fileName)
{
string ext = extension(fileName);
if (ext == "h5")
{
return getFirstName<Hdf5File>(fileName);
}
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
{
return getFirstName<AsciiFile>(fileName);
}
else
{
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
}
std::unique_ptr<File> file = open(fileName);
return file->getFirstName();
}
unique_ptr<File> Io::open(const std::string &fileName, const unsigned int mode)

View File

@ -48,7 +48,7 @@ public:
static std::string getFirstName(const std::string &fileName);
static std::string getFirstName(const std::string &fileName);
static std::unique_ptr<File> open(const std::string &fileName,
const unsigned int mode = File::Mode::write);
const unsigned int mode = File::Mode::read);
};
// template implementation /////////////////////////////////////////////////////
@ -63,27 +63,16 @@ IoT Io::load(const std::string &fileName, const std::string &name)
template <typename IoT>
IoT Io::load(const std::string &fileName, const std::string &name)
{
std::string ext = extension(fileName);
if (ext == "h5")
{
return load<IoT, Hdf5File>(fileName, name);
}
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
{
return load<IoT, AsciiFile>(fileName, name);
}
else
{
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
}
std::unique_ptr<File> file = open(fileName);
return file->read<IoT>(name);
}
template <typename IoT, typename FileType>
void Io::save(const IoT &data, const std::string &fileName,
const unsigned int mode, const std::string &name)
{
FileType file(fileName, mode);
FileType file(fileName, mode);
std::string realName = (name.empty()) ? fileName : name;
file.save(data, realName);
@ -93,20 +82,10 @@ template <typename IoT>
void Io::save(const IoT &data, const std::string &fileName,
const unsigned int mode, const std::string &name)
{
std::string ext = extension(fileName);
if (ext == "h5")
{
save<IoT, Hdf5File>(data, fileName, mode, name);
}
else if ((ext == "dat")||(ext == "sample")||(ext == "seed"))
{
save<IoT, AsciiFile>(data, fileName, mode, name);
}
else
{
LATAN_ERROR(Io, "unknown file extension '" + ext + "'");
}
std::unique_ptr<File> file = open(fileName, mode);
std::string realName = (name.empty()) ? fileName : name;
file->save(data, realName);
}
template <typename FileType>