Flipper.cpp
Go to the documentation of this file.
00001 /*
00002  *      This file is part of qpOASES.
00003  *
00004  *      qpOASES -- An Implementation of the Online Active Set Strategy.
00005  *      Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
00006  *      Christian Kirches et al. All rights reserved.
00007  *
00008  *      qpOASES is free software; you can redistribute it and/or
00009  *      modify it under the terms of the GNU Lesser General Public
00010  *      License as published by the Free Software Foundation; either
00011  *      version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *      qpOASES is distributed in the hope that it will be useful,
00014  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  *      See the GNU Lesser General Public License for more details.
00017  *
00018  *      You should have received a copy of the GNU Lesser General Public
00019  *      License along with qpOASES; if not, write to the Free Software
00020  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 
00036 #include <qpOASES/Flipper.hpp>
00037 
00038 
00039 BEGIN_NAMESPACE_QPOASES
00040 
00041 
00042 /*****************************************************************************
00043  *  P U B L I C                                                              *
00044  *****************************************************************************/
00045 
00046 
00047 /*
00048  *      F l i p p e r
00049  */
00050 Flipper::Flipper( )
00051 {
00052         R = 0;
00053         Q = 0;
00054         T = 0;
00055         
00056         init( );
00057 }
00058 
00059 
00060 /*
00061  *      F l i p p e r
00062  */
00063 Flipper::Flipper(       int _nV,
00064                                         int _nC
00065                                         )
00066 {
00067         R = 0;
00068         Q = 0;
00069         T = 0;
00070         
00071         init( _nV,_nC );
00072 }
00073 
00074 
00075 /*
00076  *      F l i p p e r
00077  */
00078 Flipper::Flipper( const Flipper& rhs )
00079 {
00080         R = 0;
00081         Q = 0;
00082         T = 0;
00083 
00084         copy( rhs );
00085 }
00086 
00087 
00088 /*
00089  *      ~ F l i p p e r
00090  */
00091 Flipper::~Flipper( )
00092 {
00093         clear( );
00094 }
00095 
00096 
00097 /*
00098  *      o p e r a t o r =
00099  */
00100 Flipper& Flipper::operator=( const Flipper& rhs )
00101 {
00102         if ( this != &rhs )
00103         {
00104                 clear( );
00105                 copy( rhs );
00106         }
00107 
00108         return *this;
00109 }
00110 
00111 
00112 
00113 /*
00114  *      i n i t
00115  */
00116 returnValue Flipper::init(      int _nV,
00117                                                         int _nC
00118                                                         )
00119 {
00120         if ( ( _nV < 0 ) || ( _nC < 0 ) )
00121                 return THROWERROR( RET_INVALID_ARGUMENTS );
00122 
00123         clear( );
00124 
00125         nV = _nV;
00126         nC = _nC;
00127 
00128         /*if ( nV > 0 )
00129         {
00130                 R = new real_t[nV*nV];
00131         
00132                 if ( nC > 0 )
00133                 {
00134                         Q = new real_t[nV*nV];
00135                         T = new real_t[getDimT()];
00136                 }
00137         }*/
00138 
00139         return SUCCESSFUL_RETURN;
00140 }
00141 
00142 
00143 
00144 /*
00145  *      g e t
00146  */
00147 returnValue Flipper::get(       Bounds* const _bounds,
00148                                                         double* const _R,
00149                                                         Constraints* const _constraints,
00150                                                         double* const _Q,
00151                                                         double* const _T 
00152                                                         ) const
00153 {
00154         if ( _bounds != 0 )
00155                 *_bounds = bounds;
00156 
00157         if ( _constraints != 0 )
00158                 *_constraints = constraints;
00159 
00160         if ( ( _R != 0 ) && ( R != 0 ) )
00161                 memcpy( _R,R, nV*nV*sizeof(real_t) );
00162 
00163         if ( ( _Q != 0 ) && ( Q != 0 ) )
00164                 memcpy( _Q,Q, nV*nV*sizeof(real_t) );
00165 
00166         if ( ( _T != 0 ) && ( T != 0 ) )
00167                 memcpy( _T,T, getDimT()*sizeof(real_t) );
00168 
00169         return SUCCESSFUL_RETURN;
00170 }
00171 
00172 
00173 /*
00174  *      s e t
00175  */
00176 returnValue Flipper::set(       const Bounds* const _bounds,
00177                                                         const double* const _R,
00178                                                         const Constraints* const _constraints,
00179                                                         const double* const _Q,
00180                                                         const double* const _T
00181                                                         )
00182 {
00183         if ( _bounds != 0 )
00184                 bounds = *_bounds;
00185 
00186         if ( _constraints != 0 )
00187                 constraints = *_constraints;
00188 
00189         if ( _R != 0 )
00190         {
00191                 if ( R == 0 )
00192                         R = new real_t[nV*nV];
00193 
00194                 memcpy( R,_R, nV*nV*sizeof(real_t) );
00195         }
00196 
00197         if ( _Q != 0 )
00198         {
00199                 if ( Q == 0 )
00200                         Q = new real_t[nV*nV];
00201 
00202                 memcpy( Q,_Q, nV*nV*sizeof(real_t) );
00203         }
00204 
00205         if ( _T != 0 )
00206         {
00207                 if ( T == 0 )
00208                         T = new real_t[getDimT()];
00209 
00210                 memcpy( T,_T, getDimT()*sizeof(real_t) );
00211         }
00212 
00213         return SUCCESSFUL_RETURN;
00214 }
00215 
00216 
00217 
00218 /*****************************************************************************
00219  *  P R O T E C T E D                                                        *
00220  *****************************************************************************/
00221 
00222 /*
00223  *      c l e a r
00224  */
00225 returnValue Flipper::clear( )
00226 {
00227         if ( R != 0 )
00228         {
00229                 delete[] R;
00230                 R = 0;
00231         }
00232         
00233         if ( Q != 0 )
00234         {
00235                 delete[] Q;
00236                 Q = 0;
00237         }
00238         
00239         if ( T != 0 )
00240         {
00241                 delete[] T;
00242                 T = 0;
00243         }
00244 
00245         return SUCCESSFUL_RETURN;
00246 }
00247 
00248 
00249 /*
00250  *      c o p y
00251  */
00252 returnValue Flipper::copy(      const Flipper& rhs
00253                                                         )
00254 {
00255         return set( &(rhs.bounds),rhs.R, &(rhs.constraints),rhs.Q,rhs.T );
00256 }
00257 
00258 
00259 int Flipper::getDimT( ) const
00260 {
00261         if ( nV > nC )
00262                 return nC*nC;
00263         else
00264                 return nV*nV;
00265 }
00266 
00267 
00268 END_NAMESPACE_QPOASES
00269 
00270 
00271 /*
00272  *      end of file
00273  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Sat Jun 8 2019 19:37:02