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