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:
parent
69cd14bf9b
commit
ae62a3225d
18
lib/Io.cpp
18
lib/Io.cpp
@ -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 + "'");
|
||||
}
|
||||
}
|
||||
|
@ -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 /////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user