MatrixValue.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file MatrixValue.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_CORE_MATRIXVALUE_HPP__
41 #define __OPENFLUID_CORE_MATRIXVALUE_HPP__
42 
43 
46 #include <openfluid/dllexport.hpp>
47 
48 
49 namespace openfluid { namespace core {
50 
51 /**
52  MatrixValue is a container for a 2D matrix of signed double precision floating point values.\n
53 
54 \see Value
55 \see Matrix
56 
57 \n
58 
59 <I>Example : declaration</I>
60 @code
61  // declaration of a MatrixValue, empty by default
62  openfluid::core::MatrixValue Val1;
63 
64  // declaration of a MatrixValue, of 3 columns by 7 rows, with values initialized to 0.0
65  openfluid::core::MatrixValue Val2(3,7);
66 
67  // declaration of a MatrixValue, of 3 columns by 7 rows, with values initialized to 1.99
68  openfluid::core::MatrixValue Val3(3,7,1.99);
69 @endcode
70 
71 
72 <I>Example : getting the contained values</I>
73 @code
74  double Tmp1;
75 
76  Tmp1 = Val1.get(2,3);
77 @endcode
78 
79 
80 <I>Example : getting all values as a c-style array of double, rows-first indexed</I>
81 @code
82  double DblArrayVal[];
83 
84  DblArrayVal = Val1.getData();
85 @endcode
86 
87 
88 <I>Example : setting the contained values</I>
89 @code
90  // using the set method
91  Val1.set(0,0,101.99);
92 @endcode
93 
94 
95 <I>Example : conversion from string</I>
96 @code
97  openfluid::core::StringValue StringVal;
98  openfluid::core::MatrixValue Val2;
99 
100  // to MatrixValue, using two string values separators
101  StringVal.set("[[3,5,2.8,6,17.999923],[1,1,1,1,1],[2.11,2.12,2.13,2.14,2.15]]");
102  StringVal.toMatrixValue(Val2);
103 
104  // to MatrixValue, using a single string values separator and row length
105  StringVal.set("[3,5,2.8,6,17.999923,1,1,1,1,1,2.11,2.12,2.13,2.14,2.15]");
106  StringVal.toMatrixValue(5,Val2);
107 @endcode
108 
109 
110 <I>Example : conversion to string</I>
111 @code
112  std::string StdStrVal = Val1.toString();
113 @endcode
114 */
115 class OPENFLUID_API MatrixValue : public CompoundValue, public Matrix<double>
116 {
117 
118  public:
119 
120  /**
121  Default constructor
122  */
124  { }
125 
126  /**
127  Copy constructor
128  */
130  Matrix<double>(static_cast<const Matrix<double>& >(Val))
131  { }
132 
133  /**
134  Constructor, creates a Matrix containing ColsNbr x RowsNbr elements
135  */
136  MatrixValue(unsigned long ColsNbr,unsigned long RowsNbr) : CompoundValue(), Matrix<double>(ColsNbr,RowsNbr)
137  {
138 
139  }
140 
141  /**
142  Constructor, creates a Matrix containing ColsNbr x RowsNbr elements, initialized with value InitValue
143  */
144  MatrixValue(unsigned long ColsNbr, unsigned long RowsNbr, double InitValue) :
145  CompoundValue(), Matrix<double>(ColsNbr,RowsNbr,InitValue)
146  {
147 
148  }
149 
150  virtual ~MatrixValue()
151  {
152 
153  }
154 
155  Value& operator =(const Value& Other);
156 
157  inline Type getType() const
158  {
159  return Value::MATRIX;
160  };
161 
162  Value* clone() const
163  {
164  return new MatrixValue(*this);
165  }
166 
167  void writeToStream(std::ostream& OutStm) const;
168 
169  void writeQuotedToStream(std::ostream& OutStm) const
170  {
171  writeToStream(OutStm);
172  }
173 
174 };
175 
176 
177 } } // namespaces
178 
179 
180 #endif /* __OPENFLUID_CORE_MATRIXVALUE_HPP__ */
Definition: CompoundValue.hpp:51
Definition: Value.hpp:64
void writeQuotedToStream(std::ostream &OutStm) const
Definition: MatrixValue.hpp:169
Type
Definition: Value.hpp:68
MatrixValue(unsigned long ColsNbr, unsigned long RowsNbr, double InitValue)
Definition: MatrixValue.hpp:144
Definition: Matrix.hpp:55
MatrixValue(const MatrixValue &Val)
Definition: MatrixValue.hpp:129
Type getType() const
Definition: MatrixValue.hpp:157
MatrixValue()
Definition: MatrixValue.hpp:123
Definition: ApplicationException.hpp:47
Value * clone() const
Definition: MatrixValue.hpp:162
virtual ~MatrixValue()
Definition: MatrixValue.hpp:150
Definition: Value.hpp:68
#define OPENFLUID_API
Definition: dllexport.hpp:86
MatrixValue(unsigned long ColsNbr, unsigned long RowsNbr)
Definition: MatrixValue.hpp:136
Definition: MatrixValue.hpp:115