/* * Io.hpp, part of LatAnalyze 3 * * Copyright (C) 2013 - 2015 Antonin Portelli * * LatAnalyze 3 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LatAnalyze 3 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LatAnalyze 3. If not, see . */ #ifndef Latan_Io_hpp_ #define Latan_Io_hpp_ #include #include #include BEGIN_LATAN_NAMESPACE /****************************************************************************** * Static IO functions * ******************************************************************************/ class Io { public: template static IoT load(const std::string &fileName, const std::string &name = ""); template static IoT load(const std::string &fileName, const std::string &name = ""); template static void save(const IoT &data, const std::string &fileName, const unsigned int mode = File::Mode::write, const std::string &name = ""); template static void save(const IoT &data, const std::string &fileName, const unsigned int mode = File::Mode::write, const std::string &name = ""); template static std::string getFirstName(const std::string &fileName); static std::string getFirstName(const std::string &fileName); }; // template implementation ///////////////////////////////////////////////////// template IoT Io::load(const std::string &fileName, const std::string &name) { FileType file(fileName, File::Mode::read); return file.template read(name); } template IoT Io::load(const std::string &fileName, const std::string &name) { std::string ext = extension(fileName); if (ext == "h5") { return load(fileName, name); } else if ((ext == "dat")||(ext == "sample")||(ext == "seed")) { return load(fileName, name); } else { LATAN_ERROR(Io, "unknown file extension '" + ext + "'"); } } template void Io::save(const IoT &data, const std::string &fileName, const unsigned int mode, const std::string &name) { FileType file(fileName, mode); std::string realName = (name.empty()) ? fileName : name; file.save(data, realName); } template 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(data, fileName, mode, name); } else if ((ext == "dat")||(ext == "sample")||(ext == "seed")) { save(data, fileName, mode, name); } else { LATAN_ERROR(Io, "unknown file extension '" + ext + "'"); } } template std::string Io::getFirstName(const std::string &fileName) { FileType file(fileName, File::Mode::read); return file.getFirstName(); } END_LATAN_NAMESPACE #endif // Latan_Io_hpp_