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

IO: polymorphic file opening

This commit is contained in:
Antonin Portelli 2015-11-04 17:30:52 +00:00
parent 69cd14bf9b
commit ae62a3225d
2 changed files with 20 additions and 0 deletions

View File

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

View File

@ -47,6 +47,8 @@ public:
template <typename FileType>
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);
};
// template implementation /////////////////////////////////////////////////////