Enable build with iniparser v 3.1
[platform/framework/native/appfw.git] / inc / FBaseIntMatrix.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /*
18  * @file        FBaseIntMatrix.h
19  * @brief       This is the header file for the %IntMatrix class.
20  *
21  * This header file contains the declarations of the %IntMatrix class.
22  *
23  */
24
25 #ifndef _FBASE_INT_MATRIX_H_
26 #define _FBASE_INT_MATRIX_H_
27
28 #include <FBase.h>
29 #include <FBaseTypes.h>
30 #include <FBaseObject.h>
31
32 namespace Tizen { namespace Base
33 {
34 /*
35  * @class       IntMatrix
36  * @brief       This class encapsulates a two-dimensional matrix.
37  *
38  * @since 2.0
39  *
40  * The %IntMatrix class provides a int precision, two-dimensional matrix class.
41  *
42  */
43 class _OSP_EXPORT_ IntMatrix
44         : public Tizen::Base::Object
45 {
46 public:
47         /*
48          * Copying of objects using this copy constructor is allowed.
49          *
50          * @since 2.0
51          *
52          * @param[in]   rhs     An instance of %IntMatrix
53          */
54         IntMatrix(const IntMatrix& rhs);
55
56         /*
57          * Constructs a row by column null matrix in which all elements are zero.
58          *
59          * @since 2.0
60          *
61          * @param[in]   rowCount        The number of rows in the current instance
62          * @param[in]   columnCount     The number of columns in the current instance
63          */
64         IntMatrix(int rowCount, int columnCount);
65
66         /*
67          * Constructs a row by column matrix initialized to the values in the specified array.
68          *
69          * @since 2.0
70          *
71          * @param[in]   rowCount        The number of rows in the current instance
72          * @param[in]   columnCount     The number of columns in the current instance
73          * @param[in]   pArray          A one-dimensional array @n The array must be at least row * column in length.
74          * @param[in]   rowMajor        Set to @c true to copy the array in row-major order, @n
75          *                                                      else @c copy in column-major order
76          */
77         IntMatrix(int rowCount, int columnCount, const int* pArray, bool rowMajor = true);
78
79         /*
80          * Constructs a row by column matrix initialized to the values in the specified array.
81          *
82          * @since 2.0
83          *
84          * @param[in]   rowCount        The number of rows in the current instance
85          * @param[in]   columnCount     The number of columns in the current instance
86          * @param[in]   pArray[]        A two-dimensional array @n The array must be at least row * column in length.
87          */
88         IntMatrix(int rowCount, int columnCount, const int* pArray[]);
89
90         /*
91          * This destructor overrides Tizen::Base::Object::~Object().
92          *
93          * @since 2.0
94          */
95         virtual ~IntMatrix(void);
96
97         /*
98          * Checks whether the current instance and the specified instance of %IntMatrix are equal.
99          *
100          * @since 2.0
101          *
102          * @return      @c true if all matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
103          *                      else @c false
104          * @param[in]   rhs     An instance of %IntMatrix
105          */
106         bool operator ==(const IntMatrix& rhs) const;
107
108         /*
109          * Checks whether the current instance and the specified instance of %IntMatrix are not equal.
110          *
111          * @since 2.0
112          *
113          * @return      @c true if all matrix members of the current instance are not equal to the corresponding matrix members in the specified instance, @n
114          *                      else @c false
115          * @param[in]   rhs     An instance of %IntMatrix
116          */
117         bool operator !=(const IntMatrix& rhs) const;
118
119         /*
120          * Copying of objects using this copy assignment operator is allowed.
121          *
122          * @since 2.0
123          *
124          * @return      The reference to this instance
125          * @param[in]   rhs     An instance of %IntMatrix
126          * @exception   E_INVALID_ARG   Either row or column count of the current instance is not same with that of the specified instance.
127          * @remarks     If either row or column count of the current instance is not same with that of the specified instance,
128          *                      return the reference to this instance without assigning.
129          */
130         IntMatrix& operator =(const IntMatrix& rhs);
131
132         /*
133          * Checks whether the current instance of %IntMatrix equals the specified instance of %IntMatrix.
134          *
135          * @since 2.0
136          *
137          * @return      @c true if the values of the current instance are equal to the value of the specified instance, @n
138          *                      else @c false
139          * @param[in]   obj     An instance of %IntMatrix
140          * @remarks     This method overrides Tizen::Base::Object::Equals(). This method uses the values of the Matrix components to compare the two instances.
141          */
142         virtual bool Equals(const Tizen::Base::Object& obj) const;
143
144         /*
145          * Gets the hash value of the current instance of %IntMatrix.
146          *
147          * @since 2.0
148          *
149          * @return      The hash value of the current instance
150          * @remarks     Two equal instances must return the same hash value. For better performance,
151          *                      the used hash function must generate a random distribution for all inputs.
152          */
153         virtual int GetHashCode(void) const;
154
155         /*
156          * Adds the value of the specified instance to the current instance of %IntMatrix.
157          *
158          * @since 2.0
159          *
160          * @return              An error code
161          * @param[in]   matrix                  An instance of %IntMatrix
162          * @exception   E_SUCCESS               The method is successful.
163          * @exception   E_INVALID_ARG   Either row or column count of the current instance is not same with that of the specified instance.
164          */
165         result Add(const IntMatrix& matrix);
166
167         /*
168          * Adds the value to each matrix members of current instance of %IntMatrix.
169          *
170          * @since 2.0
171          *
172          * @param[in]   value   A @c int value to add
173          */
174         void AddToEachElement(int value);
175
176         /*
177          * Gets the number of column in the current instance of %IntMatrix.
178          *
179          * @since 2.0
180          *
181          * @return      The number of column in the current instance
182          */
183         int GetColumnCount(void) const;
184
185         /*
186          * Gets a new array that includes the values of the specified column in the current instance of %IntMatrix.
187          *
188          * @since 2.0
189          *
190          * @return      A pointer to @c int array
191          * @param[in]   columnIndex             The target column number in the current instance
192          * @exception   E_INVALID_ARG   The @c columnIndex is larger than the column count of the current instance.
193          */
194         int* GetColumnN(int columnIndex) const;
195
196         /*
197          * Gets the determinant of the current instance of %IntMatrix.
198          *
199          * @since 2.0
200          *
201          * @return      The determinant value of the current instance
202          * @exception   E_INVALID_OPERATION             The current instance is not a square matrix.
203          * @remarks     If the current instance is not a square matrix, return zero.
204          */
205         int GetDeterminant(void) const;
206
207         /*
208          * Gets the value at the specified row and column of the current instance of %IntMatrix.
209          *
210          * @since 2.0
211          *
212          * @return      The value at the specified row and column of the current instance
213          * @param[in]   rowIndex        The target row number in the current instance
214          * @param[in]   columnIndex     The target column number in the current instance
215          * @exception   E_INVALID_ARG   The @c columnIndex or @c rowIndex is larger than that of the current instance.
216          */
217         int GetElement(int rowIndex, int columnIndex) const;
218
219         /*
220          * Gets the inverse matrix of the current instance of %IntMatrix.
221          *
222          * @since 2.0
223          *
224          * @return              A pointer to the instance of %IntMatrix containing the resulting value of the operation
225          * @exception   E_INVALID_OPERATION             The current instance is not a square matrix.
226          */
227         IntMatrix* GetInverseN(void) const;
228
229         /*
230          * Gets the number of row in the current instance of %IntMatrix.
231          *
232          * @since 2.0
233          *
234          * @return      The number of row in the current instance
235          */
236         int GetRowCount(void) const;
237
238         /*
239          * Gets a new array that includes the values of the specified row in the current instance of %IntMatrix.
240          *
241          * @since 2.0
242          *
243          * @return      A pointer to @c int array
244          * @param[in]   rowIndex                The target row number in the current instance
245          * @exception   E_INVALID_ARG   The @c rowIndex is larger than the row count of the current instance.
246          */
247         int* GetRowN(int rowIndex) const;
248
249         /*
250          * Gets the trace of the current instance of %IntMatrix.
251          *
252          * @since 2.0
253          *
254          * @return              An error code
255          * @param[out]  value   A @c int value
256          * @exception   E_SUCCESS                       The method is successful.
257          * @exception   E_INVALID_OPERATION     The current instance is not a square matrix.
258          */
259         result GetTrace(int& value) const;
260
261         /*
262          * Gets the transpose matrix of the current instance of %IntMatrix.
263          *
264          * @since 2.0
265          *
266          * @return              A pointer to the instance of %IntMatrix containing the resulting value of the operation
267          * @exception   E_INVALID_OPERATION             The current instance is not a square matrix.
268          */
269         IntMatrix* GetTransposeN(void) const;
270
271         /*
272          * Checks whether the current instance is an identity matrix.
273          *
274          * @since 2.0
275          *
276          * @return      @c true if the matrix is an identity matrix, @n
277          *                      else @c false
278          */
279         bool IsIdentity(void) const;
280
281         /*
282          * Checks whether the current matrix is invertible.
283          *
284          * @since 2.0
285          *
286          * @return      @c true if the matrix is invertible, @n
287          *                      else @c false
288          */
289         bool IsInvertible(void) const;
290
291         /*
292          * Multiplies the value of the specified instance with the current instance of %IntMatrix.
293          *
294          * @since 2.0
295          *
296          * @return              An error code
297          * @param[in]   matrix                  An instance of %IntMatrix
298          * @exception   E_SUCCESS               The method is successful.
299          * @exception   E_INVALID_ARG   The column count of the current instance is not same with the row count of the specified instance.
300          */
301         result Multiply(const IntMatrix& matrix);
302
303         /*
304          * Multiplies the value to each matrix members of current instance of %IntMatrix.
305          *
306          * @since 2.0
307          *
308          * @param[in]   value   A @c int value to multiply
309          */
310         void Multiply(int value);
311
312         /*
313          * Negates the matrix members of current instance of %IntMatrix.
314          *
315          * @since 2.0
316          */
317         void Negate(void);
318
319         /*
320          * Sets the value of the current instance of %IntMatrix to its identity.
321          *
322          * @since 2.0
323          *
324          * @return              An error code
325          * @exception   E_SUCCESS                       The method is successful.
326          * @exception   E_INVALID_OPERATION     The current instance is not a square matrix.
327          */
328         result SetAsIdentity(void);
329
330         /*
331          * Sets the value of the current instance of %IntMatrix to its inverse.
332          *
333          * @since 2.0
334          *
335          * @return              An error code
336          * @exception   E_SUCCESS                       The method is successful.
337          * @exception   E_INVALID_OPERATION     The current instance is not a square matrix.
338          */
339         result Invert(void);
340
341         /*
342          * Sets the value of the current instance of %IntMatrix to its transpose.
343          *
344          * @since 2.0
345          *
346          * @return              An error code
347          * @exception   E_SUCCESS                       The method is successful.
348          * @exception   E_INVALID_OPERATION     The current instance is not a square matrix.
349          */
350         result Transpose(void);
351
352         /*
353          * Sets the values of the specified array to the specified column of the current instance of %IntMatrix.
354          *
355          * @since 2.0
356          *
357          * @return              An error code
358          * @param[in]   columnIndex             The target column number in the current instance
359          * @param[in]   pArray                  An array which includes the values @n The array must be at least row in length.
360          * @exception   E_SUCCESS               The method is successful.
361          * @exception   E_INVALID_ARG   The @c pArray is @c null, or the @c columnIndex is larger than the column count of the current instance.
362          */
363         result SetColumn(int columnIndex, const int* pArray);
364
365         /*
366          * Sets the values of the specified array to the specified row of the current instance of %IntMatrix.
367          *
368          * @since 2.0
369          *
370          * @return              An error code
371          * @param[in]   rowIndex                The target row number in the current instance
372          * @param[in]   pArray                  An array which includes the values @n The array must be at least column in length.
373          * @exception   E_SUCCESS               The method is successful.
374          * @exception   E_INVALID_ARG   The @c pArray is @c null, or the @c rowIndex is larger than the row count of the current instance.
375          */
376         result SetRow(int rowIndex, const int* pArray);
377
378         /*
379          * Sets the value to the specified row and column of the current instance of %IntMatrix.
380          *
381          * @since 2.0
382          *
383          * @return              An error code
384          * @param[in]   rowIndex        The target row number in the current instance
385          * @param[in]   columnIndex     The target column number in the current instance
386          * @param[in]   value                   A @c int value
387          * @exception   E_SUCCESS               The method is successful.
388          * @exception   E_INVALID_ARG   The pArray is @c null, or the @c rowIndex is larger than the row count of the current instance,
389          *                              or the @c columnIndex is larger than the column count of the current instance.
390          */
391         result SetElement(int rowIndex, int columnIndex, int value);
392
393         /*
394          * Sets the values to the current instance of %IntMatrix in either the row-major or column-major order.
395          *
396          * @since 2.0
397          *
398          * @return              An error code
399          * @param[in]   pArray  A one-dimensional array @n The array must be at least row * column in length.
400          * @param[in]   rowMajor        Set to @c true to copy the array in row-major order, @n
401          *                                                      else @c false to copy in column-major order
402          * @exception   E_SUCCESS               The method is successful.
403          * @exception   E_INVALID_ARG   The pArray is @c null.
404          */
405         result SetValue(const int* pArray, bool rowMajor = true);
406
407         /*
408          * Sets the matrix members of current instance of %IntMatrix to zero.
409          *
410          * @since 2.0
411          */
412         void SetAsNull(void);
413
414         /*
415          * Subtracts the value of the specified instance from the current instance of %IntMatrix.
416          *
417          * @since 2.0
418          *
419          * @return              An error code
420          * @param[in]   matrix  An instance of %IntMatrix
421          * @exception   E_SUCCESS               The method is successful.
422          * @exception   E_INVALID_ARG   Either row or column count of the current instance is not same with that of the specified instance.
423          */
424         result Subtract(const IntMatrix& matrix);
425
426         /*
427          * Subtracts the value from each matrix members of current instance of %IntMatrix.
428          *
429          * @since 2.0
430          *
431          * @param[in]   value   A @c int value to subtract
432          */
433         void SubtractToEachElement(int value);
434
435 private:
436         /*
437          * This default constructor is intentionally declared as private so that only the platform can create an instance.
438          *
439          * @since 2.0
440          */
441         IntMatrix(void);
442
443         bool AllocateCapacity(int rowCount, int columnCount);
444         void GetMinor(int** pSrc, int** pDest, int rowIndex, int columnIndex, int order) const;
445         int CalculateDeterminant(int** pMatrix, int order) const;
446
447         friend class _IntMatrixImpl;
448         class _IntMatrixImpl* __pImpl;
449
450         int** __pMatrix;
451         int __row;
452         int __column;
453
454 }; // IntMatrix
455
456 }} // Tizen::Base
457
458 #endif //_FBASE_INT_MATRIX_H_