.. _program_listing_file__tmp_ws_src_proxsuite_include_proxsuite_serialization_archive.hpp: Program Listing for File archive.hpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/proxsuite/include/proxsuite/serialization/archive.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // // Copyright (c) 2022 INRIA // #ifndef PROXSUITE_SERIALIZATION_ARCHIVE_HPP #define PROXSUITE_SERIALIZATION_ARCHIVE_HPP #include #include #include #include #include #include namespace proxsuite { namespace serialization { template inline void loadFromStringStream(T& object, std::istringstream& is) { cereal::JSONInputArchive ia(is); ia(object); } template inline void saveToStringStream(const T& object, std::stringstream& ss) { cereal::JSONOutputArchive oa(ss); oa(object); } template inline void loadFromString(T& object, const std::string& str) { std::istringstream is(str); loadFromStringStream(object, is); } template inline std::string saveToString(const T& object) { std::stringstream ss; saveToStringStream(object, ss); return ss.str(); } template inline void loadFromBinary(T& object, const std::string& filename) { std::ifstream ifs(filename.c_str(), std::ios::binary); if (ifs) { cereal::BinaryInputArchive ia(ifs); ia(object); } else { const std::string exception_message(filename + " does not seem to be a valid file."); throw std::invalid_argument(exception_message); } } template void saveToBinary(const T& object, const std::string& filename) { std::ofstream ofs(filename.c_str(), std::ios::binary); if (ofs) { cereal::BinaryOutputArchive oa(ofs); oa(object); } else { const std::string exception_message(filename + " does not seem to be a valid file."); throw std::invalid_argument(exception_message); } } template inline void loadFromJSON(T& object, const std::string& filename) { std::ifstream ifs(filename.c_str()); if (ifs) { cereal::JSONInputArchive ia(ifs); ia(object); } else { const std::string exception_message(filename + " does not seem to be a valid file."); throw std::invalid_argument(exception_message); } } template void saveToJSON(const T& object, const std::string& filename) { std::ofstream ofs(filename.c_str()); if (ofs) { cereal::JSONOutputArchive oa(ofs); oa(object); } else { const std::string exception_message(filename + " does not seem to be a valid file."); throw std::invalid_argument(exception_message); } } template inline void loadFromXML(T& object, const std::string& filename) { std::ifstream ifs(filename.c_str()); if (ifs) { cereal::XMLInputArchive ia(ifs); ia(object); } else { const std::string exception_message(filename + " does not seem to be a valid file."); throw std::invalid_argument(exception_message); } } template void saveToXML(const T& object, const std::string& filename) { std::ofstream ofs(filename.c_str()); if (ofs) { cereal::XMLOutputArchive oa(ofs); oa(object); } else { const std::string exception_message(filename + " does not seem to be a valid file."); throw std::invalid_argument(exception_message); } } } } #endif /* end of include guard PROXSUITE_SERIALIZATION_ARCHIVE_HPP */