Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

toolbox/outputMatlab.hh
Go to the documentation of this file.
00001 /* matlab output function
00002  */
00003 
00004 #ifndef ToolboxOutputMatlab_h
00005 #define ToolboxOutputMatlab_h
00006 
00007 #include <iomanip>
00008 #include "basics/outputMatlab.hh"
00009 #include "array.hh"
00010 #include "stiffArray.hh"
00011 
00012 #define OutputMatlabArray_D 0
00013 #define OutputMatlabStiffArray_D 0
00014 
00015 namespace concepts {
00016 
00017   // ********************************************************** OutputMatlab **
00018 
00025   template<typename F>
00026   class OutputMatlab<Array<F> > : public OutputOperator {
00027   public:
00028     OutputMatlab(const Array<F>& val, const bool transposed = false) 
00029       : val_(val), transposed_(transposed) {}
00030   protected:
00032     virtual std::ostream& info(std::ostream& os) const;
00033   private:
00034     const Array<F>& val_;
00035     const bool transposed_;
00036   };
00037 
00039   template<typename F>
00040   std::ostream& OutputMatlab<Array<F> >::info(std::ostream& os) const {
00041     std::stringstream s;
00042     s.setf(os.flags());
00043     s.precision(os.precision());
00044     s << "[";
00045     const F* d = (const F*)val_;
00046     DEBUGL(OutputMatlabArray_D, 
00047      "transposed = " << std::boolalpha << transposed_);
00048     DEBUGL(OutputMatlabArray_D, val_);
00049     for (uint i = val_.size(); i--;)
00050       s << OutputMatlab<F>(*d++) 
00051   << ((i == 0) ? "" : (transposed_ ? " " : "; "));
00052     s << ']';
00053     DEBUGL(OutputMatlabArray_D, "s = " << s.str());
00054     return os << s.str();
00055   }
00056 
00064   template<uint dim, typename F>
00065   class OutputMatlab<StiffArray<dim,F> > : public OutputOperator {
00066   public:
00067     OutputMatlab(const StiffArray<dim,F>& val, const bool transposed = false) 
00068       : val_(val), transposed_(transposed) {}
00069   protected:
00071     virtual std::ostream& info(std::ostream& os) const;
00072   private:
00073     const StiffArray<dim,F>& val_;
00074     const bool transposed_;
00075   };
00076 
00078   template<uint dim, typename F>
00079   std::ostream& OutputMatlab<StiffArray<dim,F> >::info(std::ostream& os) const
00080   {
00081     std::stringstream s;
00082     s.setf(os.flags());
00083     s.precision(os.precision());
00084     s << "[";
00085     const F* d = (const F*)val_;
00086     DEBUGL(OutputMatlabStiffArray_D, 
00087      "transposed = " << std::boolalpha << transposed_);
00088     DEBUGL(OutputMatlabStiffArray_D, val_);
00089     for (uint i = dim; i--;)
00090       s << OutputMatlab<F>(*d++) 
00091   << ((i == 0) ? "" : (transposed_ ? " " : "; "));
00092     s << ']';
00093     DEBUGL(OutputMatlabStiffArray_D, "s = " << s.str());
00094     return os << s.str();
00095   }
00096 
00097 } // namespace concepts
00098 
00099 #endif // ToolboxOutputMatlab_h

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)