X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Ftable-view%2Farray-2d.h;h=3128d6e25d3a1376471ae02c8d0174bb7fc3b123;hp=076ee2436a3763aad61b70c07d21e0a87d094369;hb=HEAD;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/internal/controls/table-view/array-2d.h b/dali-toolkit/internal/controls/table-view/array-2d.h index 076ee24..3128d6e 100644 --- a/dali-toolkit/internal/controls/table-view/array-2d.h +++ b/dali-toolkit/internal/controls/table-view/array-2d.h @@ -1,29 +1,29 @@ #pragma once -#ifndef __DALI_ARRAY2D_H__ -#define __DALI_ARRAY2D_H__ +#ifndef DALI_ARRAY2D_H +#define DALI_ARRAY2D_H -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ -// INTERNAL INCLUDES +// EXTERNAL INCLUDES #include namespace Dali { - /** * Helper wrapper for two dimensional array using std::vector * Usage: @@ -33,40 +33,42 @@ namespace Dali * intArray.Resize( 4, 4 ); * */ -template< typename T > +template class Array2d { public: - /** * Default constructor. Creates a 0x0 array */ Array2d() - : mArray( 0, std::vector< T >( 0 ) ) - { } + : mArray(0, std::vector(0)) + { + } /** * Constructs an array with given dimensions * @param [in] rows for array * @param [in] columns for array */ - Array2d( unsigned int rows, unsigned int columns ) - : mArray( rows, std::vector< T >( columns ) ) - { } + Array2d(unsigned int rows, unsigned int columns) + : mArray(rows, std::vector(columns)) + { + } /** * Destructor */ ~Array2d() - { } // Nothing to do, vector cleans up itself + { + } // Nothing to do, vector cleans up itself /** * Copy constructor * @param array to copy from */ - Array2d( const Array2d& array ) + Array2d(const Array2d& array) { - if( this != &array ) + if(this != &array) { mArray = array.mArray; } @@ -77,13 +79,13 @@ public: * @param array to copy from * @return reference to self for chaining */ - Array2d& operator=( const Array2d& array ) + Array2d& operator=(const Array2d& array) { - if( this != &array ) + if(this != &array) { mArray = array.mArray; } - return *this; + return *this; } /** @@ -99,10 +101,10 @@ public: */ unsigned int GetColumns() { - if( mArray.size() > 0 ) + if(mArray.size() > 0) { // all columns are equal length - return mArray[ 0 ].size(); + return mArray[0].size(); } return 0; } @@ -111,28 +113,28 @@ public: * @param [in] index of the row * @return reference to the row vector for given index */ - std::vector< T >& operator[]( unsigned int index ) + std::vector& operator[](unsigned int index) { - return mArray[ index ]; + return mArray[index]; } /** * @param [in] index of the row * @return const reference to the row vector for given index */ - const std::vector< T >& operator[]( unsigned int index ) const + const std::vector& operator[](unsigned int index) const { - return mArray[ index ]; + return mArray[index]; } /** * Insert a new row to given index * @param [in] rowIndex of the new row */ - void InsertRow( unsigned int rowIndex ) + void InsertRow(unsigned int rowIndex) { // insert default initialized row of elements - mArray.insert( mArray.begin() + rowIndex, std::vector< T >( GetColumns() ) ); + mArray.insert(mArray.begin() + rowIndex, std::vector(GetColumns())); } /** @@ -140,10 +142,10 @@ public: * Removed elements are deleted * @param [in] rowIndex of the row to delete */ - void DeleteRow( unsigned int rowIndex ) + void DeleteRow(unsigned int rowIndex) { // erase the row - mArray.erase( mArray.begin() + rowIndex ); + mArray.erase(mArray.begin() + rowIndex); } /** @@ -151,26 +153,26 @@ public: * @param [in] rowIndex of the row to delete * @param [out] removed elements */ - void DeleteRow( unsigned int rowIndex, std::vector< T >& removed ) + void DeleteRow(unsigned int rowIndex, std::vector& removed) { // copy the row elements - removed.insert( removed.end(), mArray[ rowIndex ].begin(), mArray[ rowIndex ].end() ); + removed.insert(removed.end(), mArray[rowIndex].begin(), mArray[rowIndex].end()); // erase the row - mArray.erase( mArray.begin() + rowIndex ); + mArray.erase(mArray.begin() + rowIndex); } /** * Insert a new column to given index * @param [in] columnIndex of the new column */ - void InsertColumn( unsigned int columnIndex ) + void InsertColumn(unsigned int columnIndex) { // go through all rows const unsigned int rows = GetRows(); - for( unsigned int i = 0; i < rows; ++i ) + for(unsigned int i = 0; i < rows; ++i) { // insert default initialized element - mArray[ i ].insert( mArray[ i ].begin() + columnIndex, T() ); + mArray[i].insert(mArray[i].begin() + columnIndex, T()); } } @@ -179,14 +181,14 @@ public: * Removed elements are deleted * @param [in] columnIndex of the column to delete */ - void DeleteColumn( unsigned int columnIndex ) + void DeleteColumn(unsigned int columnIndex) { // go through all rows const unsigned int rows = GetRows(); - for( unsigned int i = 0; i < rows; ++i ) + for(unsigned int i = 0; i < rows; ++i) { // erase the column - mArray[ i ].erase( mArray[ i ].begin() + columnIndex ); + mArray[i].erase(mArray[i].begin() + columnIndex); } } @@ -195,16 +197,16 @@ public: * @param [in] columnIndex of the column to delete * @param [out] removed elements */ - void DeleteColumn( unsigned int columnIndex, std::vector< T >& removed ) + void DeleteColumn(unsigned int columnIndex, std::vector& removed) { // go through all rows const unsigned int rows = GetRows(); - for( unsigned int i = 0; i < rows; ++i ) + for(unsigned int i = 0; i < rows; ++i) { // copy the column element of this row - removed.push_back( mArray[ i ][ columnIndex ] ); + removed.push_back(mArray[i][columnIndex]); // erase the column - mArray[ i ].erase( mArray[ i ].begin() + columnIndex ); + mArray[i].erase(mArray[i].begin() + columnIndex); } } @@ -214,14 +216,14 @@ public: * @param [in] rows for array * @param [in] columns for array */ - void Resize( unsigned int rows, unsigned int columns ) + void Resize(unsigned int rows, unsigned int columns) { // resize rows first, may increase or decrease size - mArray.resize( rows ); - for( unsigned int i = 0; i < rows; ++i ) + mArray.resize(rows); + for(unsigned int i = 0; i < rows; ++i) { // resize each column, may increase or decrease size - mArray[ i ].resize( columns ); + mArray[i].resize(columns); } } @@ -232,43 +234,41 @@ public: * @param [in] columns for array * @param [out] removed elements in case array is smaller in either dimension */ - void Resize( unsigned int rows, unsigned int columns, std::vector< T >& removed ) + void Resize(unsigned int rows, unsigned int columns, std::vector& removed) { // remember old counts - const unsigned int oldRows = GetRows(); + const unsigned int oldRows = GetRows(); const unsigned int oldColumns = GetColumns(); // are rows being removed ? - if( rows < oldRows ) + if(rows < oldRows) { // gather the elements of removed rows - for( unsigned int i = rows; i < oldRows; ++i ) + for(unsigned int i = rows; i < oldRows; ++i) { // copy the row elements, the whole row is gone - removed.insert( removed.end(), mArray[ i ].begin(), mArray[ i ].end() ); + removed.insert(removed.end(), mArray[i].begin(), mArray[i].end()); } } // resize the rows, may increase or decrease size - mArray.resize( rows ); + mArray.resize(rows); // process columns, need to do all rows as also columns for new row need resizing - for( unsigned int i = 0; i < rows; ++i ) + for(unsigned int i = 0; i < rows; ++i) { // if this is an old row and columns are being removed - if( ( i < oldRows )&&( columns < oldColumns ) ) + if((i < oldRows) && (columns < oldColumns)) { // copy the columns, the end of row from columns is gone - removed.insert( removed.end(), mArray[ i ].begin() + columns, mArray[ i ].end() ); + removed.insert(removed.end(), mArray[i].begin() + columns, mArray[i].end()); } // resize the column, may increase of decrease size - mArray[ i ].resize( columns ); + mArray[i].resize(columns); } } private: - - std::vector< std::vector< T > > mArray; - + std::vector > mArray; }; } // namespace Dali -#endif // __DALI_ARRAY2D_H__ +#endif // DALI_ARRAY2D_H