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