acado_message_handling.hpp
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 
00032 #ifndef ACADO_TOOLKIT_ACADO_MESSAGE_HANDLING_HPP
00033 #define ACADO_TOOLKIT_ACADO_MESSAGE_HANDLING_HPP
00034 
00035 #include <acado/utils/acado_namespace_macros.hpp>
00036 #include <acado/utils/acado_types.hpp>
00037 
00038 #include <cstdlib>
00039 #include <iostream>
00040 #include <vector>
00041 #include <string>
00042 
00043 BEGIN_NAMESPACE_ACADO
00044 
00046 enum VisibilityStatus
00047 {
00048         VS_VISIBLE,     
00049         VS_HIDDEN       
00050 };
00051 
00053 #ifndef __MATLAB__
00054 
00055 #define COL_DEBUG               "\033[1;34m"
00056 #define COL_FATAL               "\033[0;31m"
00057 #define COL_ERROR               "\033[1;31m"
00058 #define COL_WARNING             "\033[1;33m"
00059 #define COL_INFO                "\033[0m"
00060 
00061 #else
00062 
00063 #define COL_DEBUG               ""
00064 #define COL_FATAL               ""
00065 #define COL_ERROR               ""
00066 #define COL_WARNING             ""
00067 #define COL_INFO                ""
00068 
00069 #endif /* __MATLAB__ */
00070 
00072 enum returnValueStatus {
00073         STATUS_UNHANDLED, 
00074         STATUS_HANDLED    
00075 };
00076 
00078 const char* returnValueLevelToString(returnValueLevel level);
00079 
00081 const char* returnValueTypeToString(returnValueType type);
00082 
00083 // define DEBUG macros if necessary
00084 #ifndef __FUNCTION__
00085         #define __FUNCTION__ 0
00086 #endif
00087 
00088 #ifndef __FILE__
00089         #define __FILE__ 0
00090 #endif
00091 
00092 #ifndef __LINE__
00093         #define __LINE__ 0
00094 #endif
00095 
00097 #define QUOTE_(x) #x
00098 #define QUOTE(x) QUOTE_(x)
00099 
00101 #define ACADOERROR(retval) \
00102                 returnValue("Code: ("#retval") \n  File: " __FILE__ "\n  Line: " QUOTE(__LINE__), LVL_ERROR, retval)
00103 
00105 #define ACADOERRORTEXT(retval, text) \
00106                 returnValue("Message: "#text"\n  Code:    ("#retval") \n  File:    " __FILE__ "\n  Line:    " QUOTE(__LINE__), LVL_ERROR, retval)
00107 
00109 #define ACADOFATAL(retval) \
00110                 returnValue("Code: ("#retval") \n  File: " __FILE__ "\n  Line: " QUOTE(__LINE__), LVL_FATAL, retval)
00111 
00113 #define ACADOFATALTEXT(retval, text) \
00114                 returnValue("Message: "#text"\n  Code:    ("#retval") \n  File:    " __FILE__ "\n  Line:    " QUOTE(__LINE__), LVL_FATAL, retval)
00115 
00117 #define ACADOWARNING(retval) \
00118                 returnValue("Code: ("#retval") \n  File: " __FILE__ "\n  Line: " QUOTE(__LINE__), LVL_WARNING, retval)
00119 
00121 #define ACADOWARNINGTEXT(retval,text) \
00122                 returnValue("Message: "#text"\n  Code:    ("#retval") \n  File:    " __FILE__ "\n  Line:    " QUOTE(__LINE__), LVL_WARNING, retval)
00123 
00125 #define ACADOINFO(retval) \
00126                 returnValue("", LVL_INFO, retval)
00127 
00129 #define ACADOINFOTEXT(retval,text) \
00130                 returnValue("Message: "#text"\n  Code:    ("#retval") \n  File:    " __FILE__ "\n  Line:    " QUOTE(__LINE__), LVL_INFO, retval)
00131 
00132 
00139 #define ACADO_TRY(X) for(returnValue ACADO_R = X; !ACADO_R;) return ACADO_R
00140 
00147 class Logger
00148 {
00149 public:
00151         static Logger& instance()
00152         {
00153                 static Logger instance;
00154                 return instance;
00155         }
00156 
00158         Logger& setLogLevel(returnValueLevel level)
00159         {
00160                 logLevel = level;
00161 
00162                 return *this;
00163         }
00164 
00166         returnValueLevel getLogLevel()
00167         {
00168                 return logLevel;
00169         }
00170 
00172         std::ostream& get(returnValueLevel level);
00173 
00174 private:
00175         returnValueLevel logLevel;
00176 
00177         Logger()
00178                 : logLevel( LVL_FATAL )
00179         {}
00180 
00181         Logger(const Logger&);
00182         Logger& operator=(const Logger&);
00183         ~Logger()
00184         {}
00185 };
00186 
00188 #define LOG( level ) \
00189                 if (level < Logger::instance().getLogLevel()); \
00190                 else Logger::instance().get( level )
00191 
00192 CLOSE_NAMESPACE_ACADO
00193 
00194 
00195 
00196 #endif  // ACADO_TOOLKIT_ACADO_MESSAGE_HANDLING_HPP
00197 
00198 /*
00199  *      end of file
00200  */


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