outputMatlab.hh

Go to the documentation of this file.
1 
6 #ifndef ToolboxOutputMatlab_h
7 #define ToolboxOutputMatlab_h
8 
9 #include <iomanip>
10 #include "basics/outputMatlab.hh"
11 #include "array.hh"
12 #include "stiffArray.hh"
13 #include "sequence.hh"
14 
15 #define OutputMatlabArray_D 0
16 #define OutputMatlabStiffArray_D 0
17 #define OutputMatlabSequence_D 0
18 
19 namespace concepts {
20 
21  // ************************************************ OutputMatlab<Array<F> > **
22 
29  template<typename F>
30  class OutputMatlab<Array<F> > : public virtual OutputOperator {
31  public:
32  OutputMatlab(const Array<F>& val, const bool transposed = false)
33  : val_(val), transposed_(transposed) {}
34  protected:
36  virtual std::ostream& info(std::ostream& os) const;
37  private:
38  const Array<F>& val_;
39  const bool transposed_;
40  };
41 
43  template<typename F>
44  std::ostream& OutputMatlab<Array<F> >::info(std::ostream& os) const {
45  std::stringstream s;
46  s.setf(os.flags());
47  s.precision(os.precision());
48  s << "[";
49  const F* d = (const F*)val_;
51  "transposed = " << std::boolalpha << transposed_);
53  for (uint i = val_.size(); i--;)
54  s << OutputMatlab<F>(*d++)
55  << ((i == 0) ? "" : (transposed_ ? " " : "; "));
56  s << ']';
57  DEBUGL(OutputMatlabArray_D, "s = " << s.str());
58  return os << s.str();
59  }
60 
61  // *************************************** OutputMatlab<StiffArray<dim,F> > **
62 
70  template<uint dim, typename F>
71  class OutputMatlab<StiffArray<dim,F> > : public virtual OutputOperator {
72  public:
73  OutputMatlab(const StiffArray<dim,F>& val, const bool transposed = false)
74  : val_(val), transposed_(transposed) {}
75  protected:
77  virtual std::ostream& info(std::ostream& os) const;
78  private:
80  const bool transposed_;
81  };
82 
84  template<uint dim, typename F>
85  std::ostream& OutputMatlab<StiffArray<dim,F> >::info(std::ostream& os) const
86  {
87  std::stringstream s;
88  s.setf(os.flags());
89  s.precision(os.precision());
90  s << "[";
91  const F* d = (const F*)val_;
93  "transposed = " << std::boolalpha << transposed_);
95  for (uint i = dim; i--;)
96  s << OutputMatlab<F>(*d++)
97  << ((i == 0) ? "" : (transposed_ ? " " : "; "));
98  s << ']';
99  DEBUGL(OutputMatlabStiffArray_D, "s = " << s.str());
100  return os << s.str();
101  }
102 
103  // ******************************************** OutputMatlab<Sequence<F> > **
104 
111  template<typename F>
112  class OutputMatlab<Sequence<F> > : public virtual OutputOperator {
113  public:
114  OutputMatlab(const Sequence<F>& seq, const bool transposed = false)
115  : seq_(seq), transposed_(transposed) {}
116  protected:
118  virtual std::ostream& info(std::ostream& os) const;
119  private:
121  const bool transposed_;
122  };
123 
125  template<typename F>
126  std::ostream& OutputMatlab<Sequence<F> >::info(std::ostream& os) const {
127  std::stringstream s;
128  s.setf(os.flags());
129  s.precision(os.precision());
130  s << concepts::typeOf(*this) << "[";
132  "transposed = " << std::boolalpha << transposed_);
134  for (uint i = 0; i < seq_.size(); ++i)
135  s << OutputMatlab<F>(seq_[i])
136  << ((i == seq_.size()-1) ? "" : (transposed_ ? " " : "; "));
137  s << ']';
138  DEBUGL(OutputMatlabSequence_D, "s = " << s.str());
139  return os << s.str();
140  }
141 
142 } // namespace concepts
143 
144 #endif // ToolboxOutputMatlab_h
OutputMatlab(const Sequence< F > &seq, const bool transposed=false)
#define OutputMatlabSequence_D
Definition: outputMatlab.hh:17
#define OutputMatlabStiffArray_D
Definition: outputMatlab.hh:16
Class for output of objects to matlab.
Definition: outputMatlab.hh:88
An array of objects of fix length, defined by template parameter dim.
Definition: stiffArray.hh:29
#define DEBUGL(doit, msg)
An array of objects.
Definition: bilinearForm.hh:23
std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition: outputMatlab.hh:93
Sequence with operations, output operator, and method of the particular element types.
Definition: sequence.hh:39
OutputMatlab(const Array< F > &val, const bool transposed=false)
Definition: outputMatlab.hh:32
OutputMatlab(const StiffArray< dim, F > &val, const bool transposed=false)
Definition: outputMatlab.hh:73
std::string typeOf(const T &t)
Return the typeid name of a class object.
Definition: output.hh:43
Class providing an output operator.
#define OutputMatlabArray_D
Definition: outputMatlab.hh:15
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich