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@supagro.inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_CORE_MATRIXVALUE_HPP__
41 #define __OPENFLUID_CORE_MATRIXVALUE_HPP__
42 
45 #include <openfluid/dllexport.hpp>
46 
47 
48 namespace openfluid { namespace core {
49 
50 /**
51  MatrixValue is a container for a 2D matrix of signed double precision floating point values.\n
52 
53 \see Value
54 \see Matrix
55 
56 \n
57 
58 <I>Example : declaration</I>
59 @code
60  // declaration of a MatrixValue, empty by default
61  openfluid::core::MatrixValue Val1;
62 
63  // declaration of a MatrixValue, of 3 columns by 7 rows, with values initialized to 0.0
64  openfluid::core::MatrixValue Val2(3,7);
65 
66  // declaration of a MatrixValue, of 3 columns by 7 rows, with values initialized to 1.99
67  openfluid::core::MatrixValue Val3(3,7,1.99);
68 @endcode
69 
70 
71 <I>Example : getting the contained values</I>
72 @code
73  double Tmp1;
74 
75  Tmp1 = Val1.get(2,3);
76 @endcode
77 
78 
79 <I>Example : getting all values as a c-style array of double, rows-first indexed</I>
80 @code
81  double DblArrayVal[];
82 
83  DblArrayVal = Val1.getData();
84 @endcode
85 
86 
87 <I>Example : setting the contained values</I>
88 @code
89  // using the set method
90  Val1.set(0,0,101.99);
91 @endcode
92 
93 
94 <I>Example : conversion from string</I>
95 @code
96  openfluid::core::StringValue StringVal;
97  openfluid::core::MatrixValue Val2;
98 
99  // to MatrixValue, using two string values separators
100  StringVal.set("[[3,5,2.8,6,17.999923],[1,1,1,1,1],[2.11,2.12,2.13,2.14,2.15]]");
101  StringVal.toMatrixValue(Val2);
102 
103  // to MatrixValue, using a single string values separator and row length
104  StringVal.set("[3,5,2.8,6,17.999923,1,1,1,1,1,2.11,2.12,2.13,2.14,2.15]");
105  StringVal.toMatrixValue(5,Val2);
106 @endcode
107 
108 
109 <I>Example : conversion to string</I>
110 @code
111  std::string StdStrVal = Val1.toString();
112 @endcode
113 */
114 class OPENFLUID_API MatrixValue : public CompoundValue, public Matrix<double>
115 {
116 
117  public:
118 
119  /**
120  Default constructor
121  */
123  { }
124 
125  /**
126  Copy constructor
127  */
129  Matrix<double>(static_cast<const Matrix<double>& >(Val))
130  { }
131 
132  /**
133  Constructor, creates a Matrix containing ColsNbr x RowsNbr elements
134  */
135  MatrixValue(unsigned long ColsNbr,unsigned long RowsNbr) : CompoundValue(), Matrix<double>(ColsNbr,RowsNbr)
136  { }
137 
138  /**
139  Constructor, creates a Matrix containing ColsNbr x RowsNbr elements, initialized with value InitValue
140  */
141  MatrixValue(unsigned long ColsNbr, unsigned long RowsNbr, double InitValue) :
142  CompoundValue(), Matrix<double>(ColsNbr,RowsNbr,InitValue)
143  { }
144 
145  virtual ~MatrixValue()
146  { }
147 
148  Value& operator =(const Value& Other);
149 
150  inline Type getType() const
151  { return Value::MATRIX; };
152 
153  Value* clone() const
154  { return new MatrixValue(*this); }
155 
156  void writeToStream(std::ostream& OutStm) const;
157 
158  void writeQuotedToStream(std::ostream& OutStm) const
159  { writeToStream(OutStm); }
160 
161 };
162 
163 
164 } } // namespaces
165 
166 
167 
168 #endif /* __OPENFLUID_CORE_MATRIXVALUE_HPP__ */
Definition: Value.hpp:64
Definition: Matrix.hpp:56
Definition: CompoundValue.hpp:50
Type getType() const
Definition: MatrixValue.hpp:150
void writeQuotedToStream(std::ostream &OutStm) const
Definition: MatrixValue.hpp:158
MatrixValue(const MatrixValue &Val)
Definition: MatrixValue.hpp:128
Definition: Value.hpp:68
Type
Definition: Value.hpp:68
MatrixValue(unsigned long ColsNbr, unsigned long RowsNbr)
Definition: MatrixValue.hpp:135
Definition: ApplicationException.hpp:47
#define OPENFLUID_API
Definition: dllexport.hpp:87
MatrixValue(unsigned long ColsNbr, unsigned long RowsNbr, double InitValue)
Definition: MatrixValue.hpp:141
Value * clone() const
Definition: MatrixValue.hpp:153
virtual ~MatrixValue()
Definition: MatrixValue.hpp:145
Definition: MatrixValue.hpp:114
MatrixValue()
Definition: MatrixValue.hpp:122