2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FBaseIntMatrix.h
20 * @brief This is the header file for the %IntMatrix class.
22 * This header file contains the declarations of the %IntMatrix class.
26 #ifndef _FBASE_INT_MATRIX_H_
27 #define _FBASE_INT_MATRIX_H_
30 #include <FBaseTypes.h>
31 #include <FBaseObject.h>
33 namespace Tizen { namespace Base
37 * @brief This class encapsulates a two-dimensional matrix.
41 * The %IntMatrix class provides a int precision, two-dimensional matrix class.
44 class _OSP_EXPORT_ IntMatrix
45 : public Tizen::Base::Object
49 * Copying of objects using this copy constructor is allowed.
53 * @param[in] rhs An instance of %IntMatrix
55 IntMatrix(const IntMatrix& rhs);
58 * Constructs a row by column null matrix in which all elements are zero.
62 * @param[in] rowCount The number of rows in the current instance
63 * @param[in] columnCount The number of columns in the current instance
65 IntMatrix(int rowCount, int columnCount);
68 * Constructs a row by column matrix initialized to the values in the specified array.
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
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[] A two-dimensional array @n The array must be at least row * column in length.
89 IntMatrix(int rowCount, int columnCount, const int* pArray[]);
92 * This destructor overrides Tizen::Base::Object::~Object().
96 virtual ~IntMatrix(void);
99 * Checks whether the current instance and the specified instance of %IntMatrix are equal.
103 * @return @c true if all matrix members of the current instance are equal to the corresponding matrix members in the specified instance, @n
105 * @param[in] rhs An instance of %IntMatrix
107 bool operator ==(const IntMatrix& rhs) const;
110 * Checks whether the current instance and the specified instance of %IntMatrix are not equal.
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
116 * @param[in] rhs An instance of %IntMatrix
118 bool operator !=(const IntMatrix& rhs) const;
121 * Copying of objects using this copy assignment operator is allowed.
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.
131 IntMatrix& operator =(const IntMatrix& rhs);
134 * Checks whether the current instance of %IntMatrix equals the specified instance of %IntMatrix.
138 * @return @c true if the values of the current instance are equal to the value of the specified instance, @n
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.
143 virtual bool Equals(const Tizen::Base::Object& obj) const;
146 * Gets the hash value of the current instance of %IntMatrix.
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.
154 virtual int GetHashCode(void) const;
157 * Adds the value of the specified instance to the current instance of %IntMatrix.
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.
166 result Add(const IntMatrix& matrix);
169 * Adds the value to each matrix members of current instance of %IntMatrix.
173 * @param[in] value A @c int value to add
175 void AddToEachElement(int value);
178 * Gets the number of column in the current instance of %IntMatrix.
182 * @return The number of column in the current instance
184 int GetColumnCount(void) const;
187 * Gets a new array that includes the values of the specified column in the current instance of %IntMatrix.
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.
195 int* GetColumnN(int columnIndex) const;
198 * Gets the determinant of the current instance of %IntMatrix.
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.
206 int GetDeterminant(void) const;
209 * Gets the value at the specified row and column of the current instance of %IntMatrix.
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.
218 int GetElement(int rowIndex, int columnIndex) const;
221 * Gets the inverse matrix of the current instance of %IntMatrix.
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.
228 IntMatrix* GetInverseN(void) const;
231 * Gets the number of row in the current instance of %IntMatrix.
235 * @return The number of row in the current instance
237 int GetRowCount(void) const;
240 * Gets a new array that includes the values of the specified row in the current instance of %IntMatrix.
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.
248 int* GetRowN(int rowIndex) const;
251 * Gets the trace of the current instance of %IntMatrix.
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.
260 result GetTrace(int& value) const;
263 * Gets the transpose matrix of the current instance of %IntMatrix.
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.
270 IntMatrix* GetTransposeN(void) const;
273 * Checks whether the current instance is an identity matrix.
277 * @return @c true if the matrix is an identity matrix, @n
280 bool IsIdentity(void) const;
283 * Checks whether the current matrix is invertible.
287 * @return @c true if the matrix is invertible, @n
290 bool IsInvertible(void) const;
293 * Multiplies the value of the specified instance with the current instance of %IntMatrix.
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.
302 result Multiply(const IntMatrix& matrix);
305 * Multiplies the value to each matrix members of current instance of %IntMatrix.
309 * @param[in] value A @c int value to multiply
311 void Multiply(int value);
314 * Negates the matrix members of current instance of %IntMatrix.
321 * Sets the value of the current instance of %IntMatrix to its identity.
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.
329 result SetAsIdentity(void);
332 * Sets the value of the current instance of %IntMatrix to its inverse.
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.
343 * Sets the value of the current instance of %IntMatrix to its transpose.
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.
351 result Transpose(void);
354 * Sets the values of the specified array to the specified column of the current instance of %IntMatrix.
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.
364 result SetColumn(int columnIndex, const int* pArray);
367 * Sets the values of the specified array to the specified row of the current instance of %IntMatrix.
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.
377 result SetRow(int rowIndex, const int* pArray);
380 * Sets the value to the specified row and column of the current instance of %IntMatrix.
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.
392 result SetElement(int rowIndex, int columnIndex, int value);
395 * Sets the values to the current instance of %IntMatrix in either the row-major or column-major order.
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.
406 result SetValue(const int* pArray, bool rowMajor = true);
409 * Sets the matrix members of current instance of %IntMatrix to zero.
413 void SetAsNull(void);
416 * Subtracts the value of the specified instance from the current instance of %IntMatrix.
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.
425 result Subtract(const IntMatrix& matrix);
428 * Subtracts the value from each matrix members of current instance of %IntMatrix.
432 * @param[in] value A @c int value to subtract
434 void SubtractToEachElement(int value);
438 * This default constructor is intentionally declared as private so that only the platform can create an instance.
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;
448 friend class _IntMatrixImpl;
449 class _IntMatrixImpl* __pImpl;
459 #endif //_FBASE_INT_MATRIX_H_