diskio_proto.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // - Ian Cullinan (ian dot cullinan at nicta dot com dot au)
00007 // 
00008 // This file is part of the Armadillo C++ library.
00009 // It is provided without any warranty of fitness
00010 // for any purpose. You can redistribute this file
00011 // and/or modify it under the terms of the GNU
00012 // Lesser General Public License (LGPL) as published
00013 // by the Free Software Foundation, either version 3
00014 // of the License or (at your option) any later version.
00015 // (see http://www.opensource.org/licenses for more info)
00016 
00017 
00018 //! \addtogroup diskio
00019 //! @{
00020 
00021 
00022 //! class for saving and loading matrices and fields
00023 class diskio
00024   {
00025   public:
00026   
00027   template<typename eT>
00028   struct is_supported_type
00029     {
00030     static const bool value = 
00031       (
00032       false
00033       || is_u8<eT>::value
00034       || is_s8<eT>::value
00035       || is_u16<eT>::value
00036       || is_s16<eT>::value
00037       || is_u32<eT>::value
00038       || is_s32<eT>::value
00039       || is_float<eT>::value
00040       || is_double<eT>::value
00041       || is_complex_float<eT>::value
00042       || is_complex_double<eT>::value
00043       );
00044     };
00045   
00046   
00047   template<typename eT> inline static std::string gen_txt_header(const Mat<eT>& x);
00048   template<typename eT> inline static std::string gen_bin_header(const Mat<eT>& x);
00049 
00050   template<typename eT> inline static std::string gen_txt_header(const Cube<eT>& x);
00051   template<typename eT> inline static std::string gen_bin_header(const Cube<eT>& x);
00052 
00053   
00054   inline static char conv_to_hex_char(const u8 x);
00055   inline static void conv_to_hex(char* out, const u8 x);
00056 
00057   inline static std::string gen_tmp_name(const std::string& x);
00058   
00059   inline static bool safe_rename(const std::string& old_name, const std::string& new_name);
00060   
00061   
00062   //
00063   // matrix saving
00064   
00065   template<typename eT> inline static bool save_raw_ascii  (const Mat<eT>&                x, const std::string& final_name);
00066   template<typename eT> inline static bool save_arma_ascii (const Mat<eT>&                x, const std::string& final_name);
00067   template<typename eT> inline static bool save_arma_binary(const Mat<eT>&                x, const std::string& final_name);
00068   template<typename eT> inline static bool save_pgm_binary (const Mat<eT>&                x, const std::string& final_name);
00069   template<typename  T> inline static bool save_pgm_binary (const Mat< std::complex<T> >& x, const std::string& final_name);
00070   
00071   template<typename eT> inline static bool save_raw_ascii  (const Mat<eT>&                x, std::ostream& f);
00072   template<typename eT> inline static bool save_arma_ascii (const Mat<eT>&                x, std::ostream& f);
00073   template<typename eT> inline static bool save_arma_binary(const Mat<eT>&                x, std::ostream& f);
00074   template<typename eT> inline static bool save_pgm_binary (const Mat<eT>&                x, std::ostream& f);
00075   template<typename  T> inline static bool save_pgm_binary (const Mat< std::complex<T> >& x, std::ostream& f);
00076   
00077   
00078   //
00079   // matrix loading
00080   
00081   template<typename eT> inline static bool load_raw_ascii  (Mat<eT>&                x, const std::string& name, std::string& err_msg);
00082   template<typename eT> inline static bool load_arma_ascii (Mat<eT>&                x, const std::string& name, std::string& err_msg);
00083   template<typename eT> inline static bool load_arma_binary(Mat<eT>&                x, const std::string& name, std::string& err_msg);
00084   template<typename eT> inline static bool load_pgm_binary (Mat<eT>&                x, const std::string& name, std::string& err_msg);
00085   template<typename  T> inline static bool load_pgm_binary (Mat< std::complex<T> >& x, const std::string& name, std::string& err_msg);
00086   template<typename eT> inline static bool load_auto_detect(Mat<eT>&                x, const std::string& name, std::string& err_msg);
00087   
00088   template<typename eT> inline static bool load_raw_ascii  (Mat<eT>&                x, std::istream& f,  std::string& err_msg);
00089   template<typename eT> inline static bool load_arma_ascii (Mat<eT>&                x, std::istream& f,  std::string& err_msg);
00090   template<typename eT> inline static bool load_arma_binary(Mat<eT>&                x, std::istream& f,  std::string& err_msg);
00091   template<typename eT> inline static bool load_pgm_binary (Mat<eT>&                x, std::istream& is, std::string& err_msg);
00092   template<typename  T> inline static bool load_pgm_binary (Mat< std::complex<T> >& x, std::istream& is, std::string& err_msg);
00093   template<typename eT> inline static bool load_auto_detect(Mat<eT>&                x, std::istream& f,  std::string& err_msg);
00094   
00095   inline static void pnm_skip_comments(std::istream& f);
00096   
00097   
00098   //
00099   // cube saving
00100   
00101   template<typename eT> inline static bool save_raw_ascii  (const Cube<eT>& x, const std::string& name);
00102   template<typename eT> inline static bool save_arma_ascii (const Cube<eT>& x, const std::string& name);
00103   template<typename eT> inline static bool save_arma_binary(const Cube<eT>& x, const std::string& name);
00104   
00105   template<typename eT> inline static bool save_raw_ascii  (const Cube<eT>& x, std::ostream& f);
00106   template<typename eT> inline static bool save_arma_ascii (const Cube<eT>& x, std::ostream& f);
00107   template<typename eT> inline static bool save_arma_binary(const Cube<eT>& x, std::ostream& f);
00108   
00109   
00110   //
00111   // cube loading
00112   
00113   template<typename eT> inline static bool load_raw_ascii  (Cube<eT>& x, const std::string& name, std::string& err_msg);
00114   template<typename eT> inline static bool load_arma_ascii (Cube<eT>& x, const std::string& name, std::string& err_msg);
00115   template<typename eT> inline static bool load_arma_binary(Cube<eT>& x, const std::string& name, std::string& err_msg);
00116   template<typename eT> inline static bool load_auto_detect(Cube<eT>& x, const std::string& name, std::string& err_msg);
00117   
00118   template<typename eT> inline static bool load_raw_ascii  (Cube<eT>& x, std::istream& f, std::string& err_msg);
00119   template<typename eT> inline static bool load_arma_ascii (Cube<eT>& x, std::istream& f, std::string& err_msg);
00120   template<typename eT> inline static bool load_arma_binary(Cube<eT>& x, std::istream& f, std::string& err_msg);
00121   template<typename eT> inline static bool load_auto_detect(Cube<eT>& x, std::istream& f, std::string& err_msg);
00122   
00123   
00124   //
00125   // field saving and loading
00126   
00127   template<typename T1> inline static bool save_arma_binary(const field<T1>& x, const std::string&  name);
00128   template<typename T1> inline static bool save_arma_binary(const field<T1>& x,       std::ostream& f);
00129   
00130   template<typename T1> inline static bool load_arma_binary(      field<T1>& x, const std::string&  name, std::string& err_msg);
00131   template<typename T1> inline static bool load_arma_binary(      field<T1>& x,       std::istream& f,    std::string& err_msg);
00132   
00133   template<typename T1> inline static bool load_auto_detect(      field<T1>& x, const std::string&  name, std::string& err_msg);
00134   template<typename T1> inline static bool load_auto_detect(      field<T1>& x,       std::istream& f,    std::string& err_msg);
00135   
00136   inline static bool save_std_string(const field<std::string>& x, const std::string&  name);
00137   inline static bool save_std_string(const field<std::string>& x,       std::ostream& f);
00138   
00139   inline static bool load_std_string(      field<std::string>& x, const std::string&  name, std::string& err_msg);
00140   inline static bool load_std_string(      field<std::string>& x,       std::istream& f,    std::string& err_msg);
00141   
00142 
00143 
00144   //
00145   // handling of PPM images by cubes
00146 
00147   template<typename T1> inline static bool save_ppm_binary(const Cube<T1>& x, const std::string&  final_name);
00148   template<typename T1> inline static bool save_ppm_binary(const Cube<T1>& x,       std::ostream& f);
00149   
00150   template<typename T1> inline static bool load_ppm_binary(      Cube<T1>& x, const std::string&  final_name, std::string& err_msg);
00151   template<typename T1> inline static bool load_ppm_binary(      Cube<T1>& x,       std::istream& f,          std::string& err_msg);
00152 
00153 
00154   //
00155   // handling of PPM images by fields
00156 
00157   template<typename T1> inline static bool save_ppm_binary(const field<T1>& x, const std::string&  final_name);
00158   template<typename T1> inline static bool save_ppm_binary(const field<T1>& x,       std::ostream& f);
00159   
00160   template<typename T1> inline static bool load_ppm_binary(      field<T1>& x, const std::string&  final_name, std::string& err_msg);
00161   template<typename T1> inline static bool load_ppm_binary(      field<T1>& x,       std::istream& f,          std::string& err_msg);
00162   
00163 
00164 
00165   };
00166 
00167 
00168 
00169 //! @}