2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FBaseIntMatrix.h
19 * @brief This is the header file for the %IntMatrix class.
21 * This header file contains the declarations of the %IntMatrix class.
25 #ifndef _FBASE_INT_MATRIX_H_
26 #define _FBASE_INT_MATRIX_H_
29 #include <FBaseTypes.h>
30 #include <FBaseObject.h>
32 namespace Tizen { namespace Base
36 * @brief This class encapsulates a two-dimensional matrix.
40 * The %IntMatrix class provides a @c int precision, two-dimensional matrix.
43 class _OSP_EXPORT_ IntMatrix
44 : public Tizen::Base::Object
48 * Copying of objects using this copy constructor is allowed.
52 * @param[in] rhs An instance of %IntMatrix to copy
54 IntMatrix(const IntMatrix& rhs);
57 * Constructs a row by column null matrix in which all the elements are zero.
61 * @param[in] rowCount The number of rows in the current instance
62 * @param[in] columnCount The number of columns in the current instance
64 IntMatrix(int rowCount, int columnCount);
67 * Constructs a row by column matrix initialized to the values in the specified array.
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 The one-dimensional array @n
74 * 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
78 IntMatrix(int rowCount, int columnCount, const int* pArray, bool rowMajor = true);
81 * Constructs a row by column matrix initialized to the values in the specified array.
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[] The two-dimensional array @n
88 * The array must be at least row * column in length.
90 IntMatrix(int rowCount, int columnCount, const int* pArray[]);
93 * This destructor overrides Tizen::Base::Object::~Object().
97 virtual ~IntMatrix(void);
100 * Checks whether the current instance and the specified instance of %IntMatrix are equal.
104 * @return @c true if all the matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
106 * @param[in] rhs An instance of %IntMatrix
108 bool operator ==(const IntMatrix& rhs) const;
111 * Checks whether the current instance and the specified instance of %IntMatrix are not equal.
115 * @return @c true if all the matrix members of the current instance are not equal to the corresponding matrix members in the specified instance, @n
117 * @param[in] rhs An instance of %IntMatrix
119 bool operator !=(const IntMatrix& rhs) const;
122 * Copying of objects using this copy assignment operator is allowed.
126 * @return A reference to this instance
127 * @param[in] rhs An instance of %IntMatrix
128 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
129 * @remarks If either the row or the column count of the current instance is not same as that of the specified instance,
130 * this method returns the reference to this instance without assigning.
132 IntMatrix& operator =(const IntMatrix& rhs);
135 * Checks whether the current instance of %IntMatrix equals the specified instance of %IntMatrix.
139 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
141 * @param[in] obj An instance of %IntMatrix
143 * - This method overrides Tizen::Base::Object::Equals().
144 * - This method uses the values of the Matrix components to compare the two instances.
146 virtual bool Equals(const Tizen::Base::Object& obj) const;
149 * Gets the hash value of the current instance of %IntMatrix.
153 * @return The hash value of the current instance
154 * @remarks Two equal instances must return the same hash value. @n
155 * For better performance, the used hash function must generate a random distribution for all the inputs.
157 virtual int GetHashCode(void) const;
160 * Adds the value of the specified instance to the current instance of %IntMatrix.
164 * @return An error code
165 * @param[in] matrix An instance of %IntMatrix
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
169 result Add(const IntMatrix& matrix);
172 * Adds the value to each matrix member of the current instance of %IntMatrix.
176 * @param[in] value The @c int value to add
178 void AddToEachElement(int value);
181 * Gets the number of columns in the current instance of %IntMatrix.
185 * @return The number of columns in the current instance
187 int GetColumnCount(void) const;
190 * Gets a new array that includes the values of the specified column in the current instance of %IntMatrix.
194 * @return A pointer to the @c int array
195 * @param[in] columnIndex The target column number in the current instance
196 * @exception E_INVALID_ARG The specified @c columnIndex is larger than the column count of the current instance.
198 int* GetColumnN(int columnIndex) const;
201 * Gets the determinant of the current instance of %IntMatrix.
205 * @return The determinant value of the current instance
206 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
207 * @remarks If the current instance is not a square matrix, it returns zero.
209 int GetDeterminant(void) const;
212 * Gets the value at the specified row and column of the current instance of %IntMatrix.
216 * @return The value at the specified row and column of the current instance
217 * @param[in] rowIndex The target row number in the current instance
218 * @param[in] columnIndex The target column number in the current instance
219 * @exception E_INVALID_ARG The specified @c columnIndex or the specified @c rowIndex is larger than that of the current instance.
221 int GetElement(int rowIndex, int columnIndex) const;
224 * Gets the inverse matrix of the current instance of %IntMatrix.
228 * @return A pointer to the instance of %IntMatrix containing the resulting value of the operation
229 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
231 IntMatrix* GetInverseN(void) const;
234 * Gets the number of rows in the current instance of %IntMatrix.
238 * @return The number of rows in the current instance
240 int GetRowCount(void) const;
243 * Gets a new array that includes the values of the specified row in the current instance of %IntMatrix.
247 * @return A pointer to the @c int array
248 * @param[in] rowIndex The target row number in the current instance
249 * @exception E_INVALID_ARG The specified @c rowIndex is larger than the row count of the current instance.
251 int* GetRowN(int rowIndex) const;
254 * Gets the trace of the current instance of %IntMatrix.
258 * @return An error code
259 * @param[out] value The @c int value
260 * @exception E_SUCCESS The method is successful.
261 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
263 result GetTrace(int& value) const;
266 * Gets the transpose matrix of the current instance of %IntMatrix.
270 * @return A pointer to the %IntMatrix instance that contains the resulting value of the operation
271 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
273 IntMatrix* GetTransposeN(void) const;
276 * Checks whether the current instance is an identity matrix.
280 * @return @c true if the matrix is an identity matrix, @n
283 bool IsIdentity(void) const;
286 * Checks whether the current matrix is invertible.
290 * @return @c true if the matrix is invertible, @n
293 bool IsInvertible(void) const;
296 * Multiplies the value of the specified instance with the current instance of %IntMatrix.
300 * @return An error code
301 * @param[in] matrix An instance of %IntMatrix
302 * @exception E_SUCCESS The method is successful.
303 * @exception E_INVALID_ARG The column count of the current instance is not same as the row count of the specified instance.
305 result Multiply(const IntMatrix& matrix);
308 * Multiplies the value to each matrix member of the current instance of %IntMatrix.
312 * @param[in] value The @c int value to multiply
314 void Multiply(int value);
317 * Negates the matrix members of the current instance of %IntMatrix.
324 * Sets the value of the current instance of %IntMatrix to its identity.
328 * @return An error code
329 * @exception E_SUCCESS The method is successful.
330 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
332 result SetAsIdentity(void);
335 * Sets the value of the current instance of %IntMatrix to its inverse.
339 * @return An error code
340 * @exception E_SUCCESS The method is successful.
341 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
346 * Sets the value of the current instance of %IntMatrix to its transpose.
350 * @return An error code
351 * @exception E_SUCCESS The method is successful.
352 * @exception E_INVALID_OPERATION The current instance is not a square matrix.
354 result Transpose(void);
357 * Sets the values of the specified array to the specified column of the current instance of %IntMatrix.
361 * @return An error code
362 * @param[in] columnIndex The target column number in the current instance
363 * @param[in] pArray The array which includes the values @n
364 * The array must be at least row in length.
365 * @exception E_SUCCESS The method is successful.
366 * @exception E_INVALID_ARG Either of the following conditions has occurred:
367 * - The specified @c pArray is @c null.
368 * - The specified @c columnIndex is larger than the column count of the current instance.
370 result SetColumn(int columnIndex, const int* pArray);
373 * Sets the values of the specified array to the specified row of the current instance of %IntMatrix.
377 * @return An error code
378 * @param[in] rowIndex The target row number in the current instance
379 * @param[in] pArray The array which includes the values @n
380 * The array must be at least column in length.
381 * @exception E_SUCCESS The method is successful.
382 * @exception E_INVALID_ARG Either of the following conditions has occurred:
383 * - The specified @c pArray is @c null.
384 * - The specified @c rowIndex is larger than the row count of the current instance.
386 result SetRow(int rowIndex, const int* pArray);
389 * Sets the value to the specified row and column of the current instance of %IntMatrix.
393 * @return An error code
394 * @param[in] rowIndex The target row number in the current instance
395 * @param[in] columnIndex The target column number in the current instance
396 * @param[in] value The @c int value
397 * @exception E_SUCCESS The method is successful.
398 * @exception E_INVALID_ARG Either of the following conditions has occurred:
399 * - The specified @c pArray is @c null.
400 * - The specified @c rowIndex is larger than the row count of the current instance.
401 * - The specified @c columnIndex is larger than the column count of the current instance.
403 result SetElement(int rowIndex, int columnIndex, int value);
406 * Sets the values to the current instance of %IntMatrix in either the row-major or column-major order.
410 * @return An error code
411 * @param[in] pArray The one-dimensional array @n
412 * The array must be at least row * column in length.
413 * @param[in] rowMajor Set to @c true to copy the array in row-major order, @n
414 * else @c false to copy in column-major order
415 * @exception E_SUCCESS The method is successful.
416 * @exception E_INVALID_ARG The specified @c pArray is @c null.
418 result SetValue(const int* pArray, bool rowMajor = true);
421 * Sets the matrix members of the current instance of %IntMatrix to zero.
425 void SetAsNull(void);
428 * Subtracts the value of the specified instance from the current instance of %IntMatrix.
432 * @return An error code
433 * @param[in] matrix An instance of %IntMatrix
434 * @exception E_SUCCESS The method is successful.
435 * @exception E_INVALID_ARG Either the row or the column count of the current instance is not same as that of the specified instance.
437 result Subtract(const IntMatrix& matrix);
440 * Subtracts the value from each matrix member of the current instance of %IntMatrix.
444 * @param[in] value The @c int value to subtract
446 void SubtractToEachElement(int value);
450 * This default constructor is intentionally declared as private so that only the platform can create an instance.
456 bool AllocateCapacity(int rowCount, int columnCount);
457 void GetMinor(int** pSrc, int** pDest, int rowIndex, int columnIndex, int order) const;
458 int CalculateDeterminant(int** pMatrix, int order) const;
460 friend class _IntMatrixImpl;
461 class _IntMatrixImpl* __pImpl;
471 #endif //_FBASE_INT_MATRIX_H_