pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
plonk_NumericalArray2D.h
00001 /*
00002  -------------------------------------------------------------------------------
00003  This file is part of the Plink, Plonk, Plank libraries
00004   by Martin Robinson
00005  
00006  http://code.google.com/p/pl-nk/
00007  
00008  Copyright University of the West of England, Bristol 2011-14
00009  All rights reserved.
00010  
00011  Redistribution and use in source and binary forms, with or without
00012  modification, are permitted provided that the following conditions are met:
00013  
00014  * Redistributions of source code must retain the above copyright
00015    notice, this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright
00017    notice, this list of conditions and the following disclaimer in the
00018    documentation and/or other materials provided with the distribution.
00019  * Neither the name of University of the West of England, Bristol nor 
00020    the names of its contributors may be used to endorse or promote products
00021    derived from this software without specific prior written permission.
00022  
00023  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026  DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 
00027  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00028  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00029  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00030  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00031  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00032  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00033  
00034  This software makes use of third party libraries. For more information see:
00035  doc/license.txt included in the distribution.
00036  -------------------------------------------------------------------------------
00037  */
00038 
00039 #ifndef PLONK_NUMERICALARRAY2D_H
00040 #define PLONK_NUMERICALARRAY2D_H
00041 
00042 #include "../core/plonk_CoreForwardDeclarations.h"
00043 #include "plonk_ContainerForwardDeclarations.h"
00044 #include "plonk_DynamicContainer.h"
00045 
00047 template<class NumericalType, class RowType>
00048 class NumericalArray2D : public ObjectArray2DBase<NumericalType, RowType>
00049 {
00050 public:    
00051     typedef ObjectArrayInternal<RowType>                Internal; 
00052     typedef ObjectArray2DBase<NumericalType, RowType>   Base;    
00053     typedef WeakPointerContainer<NumericalArray2D>      Weak;
00054     
00055     typedef ObjectArray<NumericalType>                  ObjectArrayType;
00056     typedef ObjectArray<ObjectArrayType>                ObjectArray2DType;
00057     typedef typename Base::InitialObject                InitialObject;
00058     
00059         NumericalArray2D (const int rows = 0) throw()
00060         :       Base (rows < 0 ? 0 : rows, false) 
00061         {
00062         }
00063     
00064     explicit NumericalArray2D (Internal* internal) throw() 
00065         :       Base (internal)
00066         {
00067         }
00068         
00070     NumericalArray2D (NumericalArray2D const& copy) throw()
00071     :   Base (static_cast<Base const&> (copy))
00072     {
00073     }
00074     
00075     NumericalArray2D (Dynamic const& other) throw()
00076     :   Base (other.as<NumericalArray2D>().getInternal())
00077     {
00078     }    
00079     
00081     NumericalArray2D& operator= (NumericalArray2D const& other) throw()
00082         {
00083                 if (this != &other)
00084             this->setInternal (other.getInternal());//this->setInternal (other.containerCopy().getInternal());
00085         
00086         return *this;
00087         }
00088         
00089         NumericalArray2D (const int rows, const int columns, const bool zeroData = false) throw()
00090         :       Base (rows < 0 ? 0 : rows, false) 
00091         {
00092                 if (columns > 0 && rows > 0)
00093                         for (int i = 0; i < rows; ++i)
00094                                 this->put (i, RowType (NumericalArraySpec (columns, zeroData)));
00095         }
00096         
00097         NumericalArray2D (ObjectArray2DType const& other) throw()
00098         :       Base (other.size())
00099         {
00100                 const int rows = this->size();
00101         
00102                 for (int row = 0; row < rows; ++row)
00103                         this->put (row, static_cast<RowType const&> (other[row]));
00104         }
00105 
00106         NumericalArray2D (RowType const& single) throw()
00107         :       Base (single)
00108         {
00109         }
00110         
00111         NumericalArray2D (InitialObject const &i00,
00112                                           InitialObject const &i01,
00113                                           InitialObject const &i02,// = InitialObject(),
00114                                           InitialObject const &i03 = InitialObject()) throw()
00115         :       Base (i00, i01, i02, i03) 
00116         {
00117         }
00118 
00119         NumericalArray2D (InitialObject const &i00,
00120                                           InitialObject const &i01,
00121                                           InitialObject const &i02,
00122                                           InitialObject const &i03,
00123                                           InitialObject const &i04,
00124                                           InitialObject const &i05 = InitialObject(),
00125                                           InitialObject const &i06 = InitialObject(),
00126                                           InitialObject const &i07 = InitialObject()) throw()
00127         :       Base (i00, i01, i02, i03, i04, i05, i06, i07) 
00128         {
00129         }
00130 
00131         NumericalArray2D (InitialObject const &i00,
00132                                           InitialObject const &i01,
00133                                           InitialObject const &i02,
00134                                           InitialObject const &i03,
00135                                           InitialObject const &i04,
00136                                           InitialObject const &i05,
00137                                           InitialObject const &i06,
00138                                           InitialObject const &i07,
00139                                           InitialObject const &i08,
00140                                           InitialObject const &i09 = InitialObject(),
00141                                           InitialObject const &i10 = InitialObject(),
00142                                           InitialObject const &i11 = InitialObject(),
00143                                           InitialObject const &i12 = InitialObject(),
00144                                           InitialObject const &i13 = InitialObject(),
00145                                           InitialObject const &i14 = InitialObject(),
00146                                           InitialObject const &i15 = InitialObject()) throw()
00147         :       Base (i00, i01, i02, i03, i04, i05, i06, i07,
00148                           i08, i09, i10, i11, i12, i13, i14, i15)
00149         {
00150         }
00151 
00152         NumericalArray2D (InitialObject const &i00,
00153                                           InitialObject const &i01,
00154                                           InitialObject const &i02,
00155                                           InitialObject const &i03,
00156                                           InitialObject const &i04,
00157                                           InitialObject const &i05,
00158                                           InitialObject const &i06,
00159                                           InitialObject const &i07,
00160                                           InitialObject const &i08,
00161                                           InitialObject const &i09,
00162                                           InitialObject const &i10,
00163                                           InitialObject const &i11,
00164                                           InitialObject const &i12,
00165                                           InitialObject const &i13,
00166                                           InitialObject const &i14,
00167                                           InitialObject const &i15,
00168                                           InitialObject const &i16,
00169                                           InitialObject const &i17 = InitialObject(),
00170                                           InitialObject const &i18 = InitialObject(),
00171                                           InitialObject const &i19 = InitialObject(),
00172                                           InitialObject const &i20 = InitialObject(),
00173                                           InitialObject const &i21 = InitialObject(),
00174                                           InitialObject const &i22 = InitialObject(),
00175                                           InitialObject const &i23 = InitialObject(),
00176                                           InitialObject const &i24 = InitialObject(),
00177                                           InitialObject const &i25 = InitialObject(),
00178                                           InitialObject const &i26 = InitialObject(),
00179                                           InitialObject const &i27 = InitialObject(),
00180                                           InitialObject const &i28 = InitialObject(),
00181                                           InitialObject const &i29 = InitialObject(),
00182                                           InitialObject const &i30 = InitialObject(),
00183                                           InitialObject const &i31 = InitialObject()) throw()
00184         :       Base (i00, i01, i02, i03, i04, i05, i06, i07,
00185                           i08, i09, i10, i11, i12, i13, i14, i15, 
00186               i16, i17, i18, i19, i20, i21, i22, i23,
00187                           i24, i25, i26, i27, i28, i29, i30, i31)
00188         {
00189         }
00190 
00191         ObjectArrayAssignmentDefinition(NumericalArray2D, RowType);
00192 
00193         
00194         NumericalArray2D (NumericalArray2D const& array0, 
00195                                           NumericalArray2D const& array1) throw()
00196         :       Base (array0, array1)
00197         {
00198         }
00199 
00200         void print (const char *prefix = 0, const bool rowsOnOneLine = false) const throw()
00201         {
00202 #if !PLONK_ANDROID
00203                 if (rowsOnOneLine)
00204                 {
00205                         for (int row = 0; row < this->size(); ++row)
00206                         {
00207                                 if (prefix) std::cout << prefix;
00208                                 
00209                                 std::cout << "[" << row << "]: ";
00210                                                                 
00211                                 this->at(row).print(0, true);
00212                         }
00213                 }
00214                 else
00215                 {
00216                         for (int row = 0; row < this->size(); ++row)
00217                         {
00218                                 const NumericalArray<NumericalType>& rowArray = this->at (row);
00219                                 
00220                                 for (int column = 0; column < rowArray.size(); column++)
00221                                 {
00222                                         if (prefix) std::cout << prefix;
00223                                         
00224                                         std::cout << "[" << row << "][" << column << "] = " << rowArray[column] << std::endl;
00225                                 }               
00226                         }
00227                 }
00228 #endif
00229         }
00230         
00231     PLONK_OBJECTARROWOPERATOR(NumericalArray2D);
00232 
00233 };
00234 
00235 
00236 #endif // PLONK_NUMERICALARRAY2D_H
 All Classes Functions Typedefs Enumerations Enumerator Properties