ostream_field.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 ostream
00017 //! @{
00018 
00019 
00020 //! Print the contents of a field to the specified stream
00021 //! Assumes type T1 can be printed, i.e. T1 has std::ostream& operator<< (std::ostream&, const T1&) 
00022 
00023 template<typename T1>
00024 inline
00025 std::ostream&
00026 operator<< (std::ostream& o, const field<T1>& X)
00027   {
00028   arma_extra_debug_sigprint();
00029   
00030   const ios::fmtflags orig_flags = o.flags();
00031   
00032   for(u32 col=0; col<X.n_cols; ++col)
00033     {
00034     o << "[field column " << col << ']' << '\n'; 
00035     for(u32 row=0; row<X.n_rows; ++row)
00036       {
00037       o << X.at(row,col) << '\n';
00038       }
00039     
00040     o << '\n';
00041     }
00042   
00043   o.flush();
00044   o.flags(orig_flags);
00045   
00046   return o;
00047   }
00048 
00049 
00050 
00051 //! Print the contents of a subfield to the specified stream
00052 //! Assumes type T1 can be printed, i.e. T1 has std::ostream& operator<< (std::ostream&, const T1&) 
00053 
00054 template<typename T1>
00055 inline
00056 std::ostream&
00057 operator<< (std::ostream& o, const subview_field<T1>& X)
00058   {
00059   arma_extra_debug_sigprint();
00060   
00061   const ios::fmtflags orig_flags = o.flags();
00062   
00063   for(u32 col=0; col<X.n_cols; ++col)
00064     {
00065     for(u32 row=0; row<X.n_rows; ++row)
00066       {
00067       o << X.at(row,col) << '\n';
00068       }
00069     
00070     o << '\n';
00071     }
00072   
00073   o.flush();
00074   o.flags(orig_flags);
00075   
00076   return o;
00077   }
00078 
00079 
00080 
00081 //! @}