diskio_proto.hpp

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