// SPDX-License-Identifier: Apache-2.0 // // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) // Copyright 2008-2016 National ICT Australia (NICTA) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ------------------------------------------------------------------------ //! \addtogroup diskio //! @{ //! class for saving and loading matrices and fields - INTERNAL USE ONLY! class diskio { public: arma_deprecated inline static file_type guess_file_type(std::istream& f); private: template friend class Mat; template friend class Cube; template friend class SpMat; template friend class field; friend class Mat_aux; friend class Cube_aux; friend class SpMat_aux; friend class field_aux; template arma_cold inline static std::string gen_txt_header(const Mat&); template arma_cold inline static std::string gen_bin_header(const Mat&); template arma_cold inline static std::string gen_bin_header(const SpMat&); template arma_cold inline static std::string gen_txt_header(const Cube&); template arma_cold inline static std::string gen_bin_header(const Cube&); arma_cold inline static file_type guess_file_type_internal(std::istream& f); arma_cold inline static std::string gen_tmp_name(const std::string& x); arma_cold inline static bool safe_rename(const std::string& old_name, const std::string& new_name); arma_cold inline static bool is_readable(const std::string& name); arma_cold inline static void sanitise_token(std::string& token); template inline static bool convert_token(eT& val, const std::string& token); template inline static bool convert_token(std::complex& val, const std::string& token); template inline static bool convert_token_strict(eT& val, const std::string& token); template inline static std::streamsize prepare_stream(std::ostream& f); // // matrix saving template inline static bool save_raw_ascii (const Mat& x, const std::string& final_name); template inline static bool save_raw_binary (const Mat& x, const std::string& final_name); template inline static bool save_arma_ascii (const Mat& x, const std::string& final_name); template inline static bool save_csv_ascii (const Mat& x, const std::string& final_name, const field& header, const bool with_header, const char separator); template inline static bool save_coord_ascii(const Mat& x, const std::string& final_name); template inline static bool save_arma_binary(const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat< std::complex >& x, const std::string& final_name); template inline static bool save_hdf5_binary(const Mat& x, const hdf5_name& spec, std::string& err_msg); template inline static bool save_raw_ascii (const Mat& x, std::ostream& f); template inline static bool save_raw_binary (const Mat& x, std::ostream& f); template inline static bool save_arma_ascii (const Mat& x, std::ostream& f); template inline static bool save_csv_ascii (const Mat& x, std::ostream& f, const char separator); template inline static bool save_csv_ascii (const Mat< std::complex >& x, std::ostream& f, const char separator); template inline static bool save_coord_ascii(const Mat& x, std::ostream& f); template inline static bool save_coord_ascii(const Mat< std::complex >& x, std::ostream& f); template inline static bool save_arma_binary(const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat< std::complex >& x, std::ostream& f); // // matrix loading template inline static bool load_raw_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, const std::string& name, std::string& err_msg, field& header, const bool with_header, const char separator, const bool strict); template inline static bool load_coord_ascii(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Mat& x, const hdf5_name& spec, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, std::istream& f, std::string& err_msg, const char separator, const bool strict); template inline static bool load_csv_ascii (Mat< std::complex >& x, std::istream& f, std::string& err_msg, const char separator, const bool strict); template inline static bool load_coord_ascii(Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_coord_ascii(Mat< std::complex >& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, std::istream& is, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, std::istream& is, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, std::istream& f, std::string& err_msg); inline static void pnm_skip_comments(std::istream& f); // // sparse matrix saving template inline static bool save_csv_ascii (const SpMat& x, const std::string& final_name, const field& header, const bool with_header, const char separator); template inline static bool save_coord_ascii(const SpMat& x, const std::string& final_name); template inline static bool save_arma_binary(const SpMat& x, const std::string& final_name); template inline static bool save_csv_ascii (const SpMat& x, std::ostream& f, const char separator); template inline static bool save_csv_ascii (const SpMat< std::complex >& x, std::ostream& f, const char separator); template inline static bool save_coord_ascii(const SpMat& x, std::ostream& f); template inline static bool save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f); template inline static bool save_arma_binary(const SpMat& x, std::ostream& f); // // sparse matrix loading template inline static bool load_csv_ascii (SpMat& x, const std::string& name, std::string& err_msg, field& header, const bool with_header, const char separator); template inline static bool load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_csv_ascii (SpMat& x, std::istream& f, std::string& err_msg, const char separator); template inline static bool load_csv_ascii (SpMat< std::complex >& x, std::istream& f, std::string& err_msg, const char separator); template inline static bool load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg); template inline static bool load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg); // // cube saving template inline static bool save_raw_ascii (const Cube& x, const std::string& name); template inline static bool save_raw_binary (const Cube& x, const std::string& name); template inline static bool save_arma_ascii (const Cube& x, const std::string& name); template inline static bool save_arma_binary(const Cube& x, const std::string& name); template inline static bool save_hdf5_binary(const Cube& x, const hdf5_name& spec, std::string& err_msg); template inline static bool save_raw_ascii (const Cube& x, std::ostream& f); template inline static bool save_raw_binary (const Cube& x, std::ostream& f); template inline static bool save_arma_ascii (const Cube& x, std::ostream& f); template inline static bool save_arma_binary(const Cube& x, std::ostream& f); // // cube loading template inline static bool load_raw_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Cube& x, const hdf5_name& spec, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, std::istream& f, std::string& err_msg); // // field saving and loading template inline static bool save_arma_binary(const field& x, const std::string& name); template inline static bool save_arma_binary(const field& x, std::ostream& f); template inline static bool load_arma_binary( field& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary( field& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect( field& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect( field& x, std::istream& f, std::string& err_msg); inline static bool save_std_string(const field& x, const std::string& name); inline static bool save_std_string(const field& x, std::ostream& f); inline static bool load_std_string( field& x, const std::string& name, std::string& err_msg); inline static bool load_std_string( field& x, std::istream& f, std::string& err_msg); // // handling of PPM images by cubes template inline static bool save_ppm_binary(const Cube& x, const std::string& final_name); template inline static bool save_ppm_binary(const Cube& x, std::ostream& f); template inline static bool load_ppm_binary( Cube& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( Cube& x, std::istream& f, std::string& err_msg); // // handling of PPM images by fields template inline static bool save_ppm_binary(const field& x, const std::string& final_name); template inline static bool save_ppm_binary(const field& x, std::ostream& f); template inline static bool load_ppm_binary( field& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( field& x, std::istream& f, std::string& err_msg); }; //! @}