logging.cpp
Go to the documentation of this file.
00001 /*
00002  *    This file is part of ACADO Toolkit.
00003  *
00004  *    ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
00005  *    Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
00006  *    Milan Vukov, Rien Quirynen, KU Leuven.
00007  *    Developed within the Optimization in Engineering Center (OPTEC)
00008  *    under supervision of Moritz Diehl. All rights reserved.
00009  *
00010  *    ACADO Toolkit is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 3 of the License, or (at your option) any later version.
00014  *
00015  *    ACADO Toolkit is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with ACADO Toolkit; if not, write to the Free Software
00022  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023  *
00024  */
00025 
00026 
00033 #include <acado/user_interaction/logging.hpp>
00034 
00035 using namespace std;
00036 
00037 BEGIN_NAMESPACE_ACADO
00038 
00039 //
00040 // PUBLIC MEMBER FUNCTIONS:
00041 //
00042 
00043 
00044 Logging::Logging( )
00045 {
00046         logIdx = -1;
00047 }
00048 
00049 Logging::~Logging( )
00050 {}
00051 
00052 int Logging::operator<<(        LogRecord& _record
00053                                                         )
00054 {
00055         return addLogRecord( _record );
00056 }
00057 
00058 int Logging::addLogRecord(      LogRecord& _record
00059                                                         )
00060 {
00061         unsigned newIndex;
00062         if (_record.aliasIdx >= 0)
00063         {
00064                 logCollection[ _record.aliasIdx ] = _record;
00065                 newIndex = _record.aliasIdx;
00066         }
00067         else
00068         {
00069                 logCollection.push_back( _record );
00070                 newIndex = logCollection.size() - 1;
00071                 logCollection.back().aliasIdx = _record.aliasIdx = newIndex;
00072         }
00073 
00074         return newIndex;
00075 }
00076 
00077 returnValue Logging::getLogRecord(      LogRecord& _record
00078                                                                         ) const
00079 {
00080         if (_record.aliasIdx < 0  || _record.aliasIdx >= ((int)getNumLogRecords( ) - 1))
00081                 return ACADOERROR( RET_INDEX_OUT_OF_BOUNDS );
00082 
00083         _record = logCollection[ _record.aliasIdx ];
00084 
00085         return SUCCESSFUL_RETURN;
00086 }
00087 
00088 
00089 returnValue Logging::updateLogRecord(   LogRecord& _record
00090                                                                                 ) const
00091 {
00092         for (unsigned ind = 0; ind < logCollection.size(); ++ind)
00093         {
00094                 if (logCollection[ ind ].getLogFrequency() != _record.getLogFrequency())
00095                         continue;
00096 
00097                 logCollection[ ind ].updateLogRecord( _record );
00098         }
00099 
00100         return SUCCESSFUL_RETURN;
00101 }
00102 
00103 uint Logging::getNumLogRecords( ) const
00104 {
00105         return logCollection.size();
00106 }
00107 
00108 returnValue Logging::printLoggingInfo( ) const
00109 {
00110         cout << "LogCollection having the following records: \n";
00111         for (uint i = 0; i < logCollection.size(); ++i)
00112                 logCollection[ i ].printInfo();
00113 
00114         return SUCCESSFUL_RETURN;
00115 }
00116 
00117 returnValue Logging::printNumDoubles( ) const
00118 {
00119         unsigned nDoubles = 0;
00120 
00121         for (unsigned i = 0; i < logCollection.size(); ++i)
00122                 nDoubles += logCollection[ i ].getNumDoubles();
00123 
00124         return nDoubles;
00125 
00126         cout << "LogCollection contains " << nDoubles <<  "doubles.\n";
00127         return SUCCESSFUL_RETURN;
00128 }
00129 
00130 //
00131 // PROTECTED MEMBER FUNCTIONS:
00132 //
00133 
00134 returnValue Logging::setupLogging( )
00135 {
00136         return SUCCESSFUL_RETURN;
00137 }
00138 
00139 CLOSE_NAMESPACE_ACADO
00140 
00141 /*
00142  *      end of file
00143  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:05