max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // Copyright (C) 2009-2010 Ian Cullinan max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup diskio max@0: //! @{ max@0: max@0: max@0: //! class for saving and loading matrices and fields max@0: class diskio max@0: { max@0: public: max@0: max@0: template inline static std::string gen_txt_header(const Mat& x); max@0: template inline static std::string gen_bin_header(const Mat& x); max@0: max@0: template inline static std::string gen_txt_header(const Cube& x); max@0: template inline static std::string gen_bin_header(const Cube& x); max@0: max@0: inline static file_type guess_file_type(std::istream& f); max@0: max@0: inline static char conv_to_hex_char(const u8 x); max@0: inline static void conv_to_hex(char* out, const u8 x); max@0: max@0: inline static std::string gen_tmp_name(const std::string& x); max@0: max@0: inline static bool safe_rename(const std::string& old_name, const std::string& new_name); max@0: max@0: max@0: // max@0: // matrix saving max@0: max@0: template inline static bool save_raw_ascii (const Mat& x, const std::string& final_name); max@0: template inline static bool save_raw_binary (const Mat& x, const std::string& final_name); max@0: template inline static bool save_arma_ascii (const Mat& x, const std::string& final_name); max@0: template inline static bool save_csv_ascii (const Mat& x, const std::string& final_name); max@0: template inline static bool save_arma_binary(const Mat& x, const std::string& final_name); max@0: template inline static bool save_pgm_binary (const Mat& x, const std::string& final_name); max@0: template inline static bool save_pgm_binary (const Mat< std::complex >& x, const std::string& final_name); max@0: max@0: template inline static bool save_raw_ascii (const Mat& x, std::ostream& f); max@0: template inline static bool save_raw_binary (const Mat& x, std::ostream& f); max@0: template inline static bool save_arma_ascii (const Mat& x, std::ostream& f); max@0: template inline static bool save_csv_ascii (const Mat& x, std::ostream& f); max@0: template inline static bool save_arma_binary(const Mat& x, std::ostream& f); max@0: template inline static bool save_pgm_binary (const Mat& x, std::ostream& f); max@0: template inline static bool save_pgm_binary (const Mat< std::complex >& x, std::ostream& f); max@0: max@0: max@0: // max@0: // matrix loading max@0: max@0: template inline static bool load_raw_ascii (Mat& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_raw_binary (Mat& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_arma_ascii (Mat& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_csv_ascii (Mat& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_arma_binary(Mat& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_pgm_binary (Mat& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_pgm_binary (Mat< std::complex >& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_auto_detect(Mat& x, const std::string& name, std::string& err_msg); max@0: max@0: template inline static bool load_raw_ascii (Mat& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_raw_binary (Mat& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_arma_ascii (Mat& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_csv_ascii (Mat& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_arma_binary(Mat& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_pgm_binary (Mat& x, std::istream& is, std::string& err_msg); max@0: template inline static bool load_pgm_binary (Mat< std::complex >& x, std::istream& is, std::string& err_msg); max@0: template inline static bool load_auto_detect(Mat& x, std::istream& f, std::string& err_msg); max@0: max@0: inline static void pnm_skip_comments(std::istream& f); max@0: max@0: max@0: // max@0: // cube saving max@0: max@0: template inline static bool save_raw_ascii (const Cube& x, const std::string& name); max@0: template inline static bool save_raw_binary (const Cube& x, const std::string& name); max@0: template inline static bool save_arma_ascii (const Cube& x, const std::string& name); max@0: template inline static bool save_arma_binary(const Cube& x, const std::string& name); max@0: max@0: template inline static bool save_raw_ascii (const Cube& x, std::ostream& f); max@0: template inline static bool save_raw_binary (const Cube& x, std::ostream& f); max@0: template inline static bool save_arma_ascii (const Cube& x, std::ostream& f); max@0: template inline static bool save_arma_binary(const Cube& x, std::ostream& f); max@0: max@0: max@0: // max@0: // cube loading max@0: max@0: template inline static bool load_raw_ascii (Cube& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_raw_binary (Cube& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_arma_ascii (Cube& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_arma_binary(Cube& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_auto_detect(Cube& x, const std::string& name, std::string& err_msg); max@0: max@0: template inline static bool load_raw_ascii (Cube& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_raw_binary (Cube& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_arma_ascii (Cube& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_arma_binary(Cube& x, std::istream& f, std::string& err_msg); max@0: template inline static bool load_auto_detect(Cube& x, std::istream& f, std::string& err_msg); max@0: max@0: max@0: // max@0: // field saving and loading max@0: max@0: template inline static bool save_arma_binary(const field& x, const std::string& name); max@0: template inline static bool save_arma_binary(const field& x, std::ostream& f); max@0: max@0: template inline static bool load_arma_binary( field& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_arma_binary( field& x, std::istream& f, std::string& err_msg); max@0: max@0: template inline static bool load_auto_detect( field& x, const std::string& name, std::string& err_msg); max@0: template inline static bool load_auto_detect( field& x, std::istream& f, std::string& err_msg); max@0: max@0: inline static bool save_std_string(const field& x, const std::string& name); max@0: inline static bool save_std_string(const field& x, std::ostream& f); max@0: max@0: inline static bool load_std_string( field& x, const std::string& name, std::string& err_msg); max@0: inline static bool load_std_string( field& x, std::istream& f, std::string& err_msg); max@0: max@0: max@0: max@0: // max@0: // handling of PPM images by cubes max@0: max@0: template inline static bool save_ppm_binary(const Cube& x, const std::string& final_name); max@0: template inline static bool save_ppm_binary(const Cube& x, std::ostream& f); max@0: max@0: template inline static bool load_ppm_binary( Cube& x, const std::string& final_name, std::string& err_msg); max@0: template inline static bool load_ppm_binary( Cube& x, std::istream& f, std::string& err_msg); max@0: max@0: max@0: // max@0: // handling of PPM images by fields max@0: max@0: template inline static bool save_ppm_binary(const field& x, const std::string& final_name); max@0: template inline static bool save_ppm_binary(const field& x, std::ostream& f); max@0: max@0: template inline static bool load_ppm_binary( field& x, const std::string& final_name, std::string& err_msg); max@0: template inline static bool load_ppm_binary( field& x, std::istream& f, std::string& err_msg); max@0: max@0: max@0: max@0: }; max@0: max@0: max@0: max@0: //! @}