polserver/pol-core/clib/iohelp.cpp
turleypol dbb25bdb62
Include and buildsystem cleanup (#45)
Include cleanup
Reworked buildsystem (Linux only)
Removed dynamic libs, Linux now again uses static linking (like windows)
2018-01-29 21:55:48 +01:00

55 lines
1.1 KiB
C++

/** @file
*
* @par History
*/
#include "iohelp.h"
#include <stdexcept>
// note this is only useful if ofs.exceptions( std::ios_base::failbit | std::ios_base::badbit ) is
// called
namespace Pol
{
namespace Clib
{
void open_file( std::fstream& ofs, std::string& filename, std::ios::openmode mode )
{
try
{
ofs.open( filename.c_str(), mode );
}
catch ( std::exception& ex )
{
std::string message = "Error opening file " + filename + ": " + ex.what();
throw std::runtime_error( message );
}
}
void open_file( std::ofstream& ofs, std::string& filename, std::ios::openmode mode )
{
try
{
ofs.open( filename.c_str(), mode );
}
catch ( std::exception& ex )
{
std::string message = "Error opening file " + filename + ": " + ex.what();
throw std::runtime_error( message );
}
}
void open_file( std::ifstream& ifs, std::string& filename, std::ios::openmode mode )
{
try
{
ifs.open( filename.c_str(), mode );
}
catch ( std::exception& ex )
{
std::string message = "Error opening file " + filename + ": " + ex.what();
throw std::runtime_error( message );
}
}
}
}