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 int precision, two-dimensional matrix class.
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
54 IntMatrix(const IntMatrix& rhs);
57 * Constructs a row by column null matrix in which all 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 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
77 IntMatrix(int rowCount, int columnCount, const int* pArray, bool rowMajor = true);
80 * Constructs a row by column matrix initialized to the values in the specified array.
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.
88 IntMatrix(int rowCount, int columnCount, const int* pArray[]);
91 * This destructor overrides Tizen::Base::Object::~Object().
95 virtual ~IntMatrix(void);
98 * Checks whether the current instance and the specified instance of %IntMatrix are equal.
102 * @return @c true if all matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
104 * @param[in] rhs An instance of %IntMatrix
106 bool operator ==(const IntMatrix& rhs) const;
109 * Checks whether the current instance and the specified instance of %IntMatrix are not equal.
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
115 * @param[in] rhs An instance of %IntMatrix
117 bool operator !=(const IntMatrix& rhs) const;
120 * Copying of objects using this copy assignment operator is allowed.
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.
130 IntMatrix& operator =(const IntMatrix& rhs);
133 * Checks whether the current instance of %IntMatrix equals the specified instance of %IntMatrix.
137 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
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.
142 virtual bool Equals(const Tizen::Base::Object& obj) const;
145 * Gets the hash value of the current instance of %IntMatrix.
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.
153 virtual int GetHashCode(void) const;
156 * Adds the value of the specified instance to the current instance of %IntMatrix.
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.
165 result Add(const IntMatrix& matrix);
168 * Adds the value to each matrix members of current instance of %IntMatrix.
172 * @param[in] value A @c int value to add
174 void AddToEachElement(int value);
177 * Gets the number of column in the current instance of %IntMatrix.
181 * @return The number of column in the current instance
183 int GetColumnCount(void) const;
186 * Gets a new array that includes the values of the specified column in the current instance of %IntMatrix.
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.
194 int* GetColumnN(int columnIndex) const;
197 * Gets the determinant of the current instance of %IntMatrix.
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.
205 int GetDeterminant(void) const;
208 * Gets the value at the specified row and column of the current instance of %IntMatrix.
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.
217 int GetElement(int rowIndex, int columnIndex) const;
220 * Gets the inverse matrix of the current instance of %IntMatrix.
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.
227 IntMatrix* GetInverseN(void) const;
230 * Gets the number of row in the current instance of %IntMatrix.
234 * @return The number of row in the current instance
236 int GetRowCount(void) const;
239 * Gets a new array that includes the values of the specified row in the current instance of %IntMatrix.
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.
247 int* GetRowN(int rowIndex) const;
250 * Gets the trace of the current instance of %IntMatrix.
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.
259 result GetTrace(int& value) const;
262 * Gets the transpose matrix of the current instance of %IntMatrix.
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.
269 IntMatrix* GetTransposeN(void) const;
272 * Checks whether the current instance is an identity matrix.
276 * @return @c true if the matrix is an identity matrix, @n
279 bool IsIdentity(void) const;
282 * Checks whether the current matrix is invertible.
286 * @return @c true if the matrix is invertible, @n
289 bool IsInvertible(void) const;
292 * Multiplies the value of the specified instance with the current instance of %IntMatrix.
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.
301 result Multiply(const IntMatrix& matrix);
304 * Multiplies the value to each matrix members of current instance of %IntMatrix.
308 * @param[in] value A @c int value to multiply
310 void Multiply(int value);
313 * Negates the matrix members of current instance of %IntMatrix.
320 * Sets the value of the current instance of %IntMatrix to its identity.
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.
328 result SetAsIdentity(void);
331 * Sets the value of the current instance of %IntMatrix to its inverse.
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.
342 * Sets the value of the current instance of %IntMatrix to its transpose.
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.
350 result Transpose(void);
353 * Sets the values of the specified array to the specified column of the current instance of %IntMatrix.
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.
363 result SetColumn(int columnIndex, const int* pArray);
366 * Sets the values of the specified array to the specified row of the current instance of %IntMatrix.
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.
376 result SetRow(int rowIndex, const int* pArray);
379 * Sets the value to the specified row and column of the current instance of %IntMatrix.
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.
391 result SetElement(int rowIndex, int columnIndex, int value);
394 * Sets the values to the current instance of %IntMatrix in either the row-major or column-major order.
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.
405 result SetValue(const int* pArray, bool rowMajor = true);
408 * Sets the matrix members of current instance of %IntMatrix to zero.
412 void SetAsNull(void);
415 * Subtracts the value of the specified instance from the current instance of %IntMatrix.
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.
424 result Subtract(const IntMatrix& matrix);
427 * Subtracts the value from each matrix members of current instance of %IntMatrix.
431 * @param[in] value A @c int value to subtract
433 void SubtractToEachElement(int value);
437 * This default constructor is intentionally declared as private so that only the platform can create an instance.
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;
447 friend class _IntMatrixImpl;
448 class _IntMatrixImpl* __pImpl;
458 #endif //_FBASE_INT_MATRIX_H_