1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 08:55:37 +00:00
LatAnalyze/lib/Io/Io.hpp

101 lines
3.4 KiB
C++
Raw Normal View History

2015-10-01 00:13:34 +01:00
/*
* Io.hpp, part of LatAnalyze 3
*
2020-01-13 09:57:06 +00:00
* Copyright (C) 2013 - 2020 Antonin Portelli
2015-10-01 00:13:34 +01:00
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_Io_hpp_
#define Latan_Io_hpp_
#include <LatAnalyze/Global.hpp>
#include <LatAnalyze/Io/File.hpp>
2015-10-01 00:13:34 +01:00
BEGIN_LATAN_NAMESPACE
/******************************************************************************
* Static IO functions *
******************************************************************************/
class Io
{
public:
template <typename IoT, typename FileType>
static IoT load(const std::string &fileName, const std::string &name = "");
template <typename IoT>
static IoT load(const std::string &fileName, const std::string &name = "");
template <typename IoT, typename FileType>
static void save(const IoT &data, const std::string &fileName,
const unsigned int mode = File::Mode::write,
const std::string &name = "");
template <typename IoT>
static void save(const IoT &data, const std::string &fileName,
const unsigned int mode = File::Mode::write,
const std::string &name = "");
template <typename FileType>
static std::string getFirstName(const std::string &fileName);
static std::string getFirstName(const std::string &fileName);
2015-11-04 17:30:52 +00:00
static std::unique_ptr<File> open(const std::string &fileName,
2015-11-18 19:46:52 +00:00
const unsigned int mode = File::Mode::read);
2015-10-01 00:13:34 +01:00
};
// template implementation /////////////////////////////////////////////////////
template <typename IoT, typename FileType>
IoT Io::load(const std::string &fileName, const std::string &name)
{
FileType file(fileName, File::Mode::read);
return file.template read<IoT>(name);
}
template <typename IoT>
IoT Io::load(const std::string &fileName, const std::string &name)
{
2015-11-18 19:46:52 +00:00
std::unique_ptr<File> file = open(fileName);
return file->read<IoT>(name);
2015-10-01 00:13:34 +01:00
}
template <typename IoT, typename FileType>
void Io::save(const IoT &data, const std::string &fileName,
const unsigned int mode, const std::string &name)
{
2015-11-18 19:46:52 +00:00
FileType file(fileName, mode);
2015-10-01 00:13:34 +01:00
std::string realName = (name.empty()) ? fileName : name;
file.save(data, realName);
}
template <typename IoT>
void Io::save(const IoT &data, const std::string &fileName,
const unsigned int mode, const std::string &name)
{
2015-11-18 19:46:52 +00:00
std::unique_ptr<File> file = open(fileName, mode);
std::string realName = (name.empty()) ? fileName : name;
file->save(data, realName);
2015-10-01 00:13:34 +01:00
}
template <typename FileType>
std::string Io::getFirstName(const std::string &fileName)
{
FileType file(fileName, File::Mode::read);
return file.getFirstName();
}
END_LATAN_NAMESPACE
#endif // Latan_Io_hpp_