external_packages/qpOASES-3.2.0/src/MessageHandling.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2015 by Hans Joachim Ferreau, Andreas Potschka,
6  * Christian Kirches et al. All rights reserved.
7  *
8  * qpOASES is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * qpOASES is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with qpOASES; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 
36 #include <stdio.h>
37 
38 #ifdef __MATLAB__
39  #include "mex.h"
40 #endif
41 
42 #include <qpOASES/MessageHandling.hpp>
43 #include <qpOASES/Utils.hpp>
44 
45 
47 
49 FILE* stdFile = stdout;
50 
51 
52 
53 #ifndef __SUPPRESSANYOUTPUT__
54 
57 {
58 /* miscellaneous */
59 { SUCCESSFUL_RETURN, "Successful return", VS_VISIBLE },
60 { RET_DIV_BY_ZERO, "Division by zero", VS_VISIBLE },
61 { RET_INDEX_OUT_OF_BOUNDS, "Index out of bounds", VS_VISIBLE },
62 { RET_INVALID_ARGUMENTS, "At least one of the arguments is invalid", VS_VISIBLE },
63 { RET_ERROR_UNDEFINED, "Error number undefined", VS_VISIBLE },
64 { RET_WARNING_UNDEFINED, "Warning number undefined", VS_VISIBLE },
65 { RET_INFO_UNDEFINED, "Info number undefined", VS_VISIBLE },
66 { RET_EWI_UNDEFINED, "Error/warning/info number undefined", VS_VISIBLE },
67 { RET_AVAILABLE_WITH_LINUX_ONLY, "This function is available under Linux only", VS_HIDDEN },
68 { RET_UNKNOWN_BUG, "The error occurred is not yet known", VS_VISIBLE },
69 { RET_PRINTLEVEL_CHANGED, "Print level changed", VS_VISIBLE },
70 { RET_NOT_YET_IMPLEMENTED, "Requested function is not yet implemented.", VS_VISIBLE },
71 /* Indexlist */
72 { RET_INDEXLIST_MUST_BE_REORDERD, "Index list has to be reordered", VS_VISIBLE },
73 { RET_INDEXLIST_EXCEEDS_MAX_LENGTH, "Index list exceeds its maximal physical length", VS_VISIBLE },
74 { RET_INDEXLIST_CORRUPTED, "Index list corrupted", VS_VISIBLE },
75 { RET_INDEXLIST_OUTOFBOUNDS, "Physical index is out of bounds", VS_VISIBLE },
76 { RET_INDEXLIST_ADD_FAILED, "Adding indices from another index set failed", VS_VISIBLE },
77 { RET_INDEXLIST_INTERSECT_FAILED, "Intersection with another index set failed", VS_VISIBLE },
78 /* SubjectTo / Bounds / Constraints */
79 { RET_INDEX_ALREADY_OF_DESIRED_STATUS, "Index is already of desired status", VS_VISIBLE },
80 { RET_ADDINDEX_FAILED, "Adding index to index set failed", VS_VISIBLE },
81 { RET_REMOVEINDEX_FAILED, "Removing index from index set failed", VS_VISIBLE },
82 { RET_SWAPINDEX_FAILED, "Cannot swap between different indexsets", VS_VISIBLE },
83 { RET_NOTHING_TO_DO, "Nothing to do", VS_VISIBLE },
84 { RET_SETUP_BOUND_FAILED, "Setting up bound index failed", VS_VISIBLE },
85 { RET_SETUP_CONSTRAINT_FAILED, "Setting up constraint index failed", VS_VISIBLE },
86 { RET_MOVING_BOUND_FAILED, "Moving bound between index sets failed", VS_VISIBLE },
87 { RET_MOVING_CONSTRAINT_FAILED, "Moving constraint between index sets failed", VS_VISIBLE },
88 { RET_SHIFTING_FAILED, "Shifting of bounds/constraints failed", VS_VISIBLE },
89 { RET_ROTATING_FAILED, "Rotating of bounds/constraints failed", VS_VISIBLE },
90 /* QProblem */
91 { RET_QPOBJECT_NOT_SETUP, "The QP object has not been setup correctly, use another constructor", VS_VISIBLE },
92 { RET_QP_ALREADY_INITIALISED, "QProblem has already been initialised", VS_VISIBLE },
93 { RET_NO_INIT_WITH_STANDARD_SOLVER, "Initialisation via extern QP solver is not yet implemented", VS_VISIBLE },
94 { RET_RESET_FAILED, "Reset failed", VS_VISIBLE },
95 { RET_INIT_FAILED, "Initialisation failed", VS_VISIBLE },
96 { RET_INIT_FAILED_TQ, "Initialisation failed due to TQ factorisation", VS_VISIBLE },
97 { RET_INIT_FAILED_CHOLESKY, "Initialisation failed due to Cholesky decomposition", VS_VISIBLE },
98 { RET_INIT_FAILED_HOTSTART, "Initialisation failed! QP could not be solved!", VS_VISIBLE },
99 { RET_INIT_FAILED_INFEASIBILITY, "Initial QP could not be solved due to infeasibility!", VS_VISIBLE },
100 { RET_INIT_FAILED_UNBOUNDEDNESS, "Initial QP could not be solved due to unboundedness!", VS_VISIBLE },
101 { RET_INIT_FAILED_REGULARISATION, "Initialisation failed as Hessian matrix could not be regularised", VS_VISIBLE },
102 { RET_INIT_SUCCESSFUL, "Initialisation done", VS_VISIBLE },
103 { RET_OBTAINING_WORKINGSET_FAILED, "Failed to obtain working set for auxiliary QP", VS_VISIBLE },
104 { RET_SETUP_WORKINGSET_FAILED, "Failed to setup working set for auxiliary QP", VS_VISIBLE },
105 { RET_SETUP_AUXILIARYQP_FAILED, "Failed to setup auxiliary QP for initialised homotopy", VS_VISIBLE },
106 { RET_NO_CHOLESKY_WITH_INITIAL_GUESS, "Externally computed Cholesky factor cannot be combined with an initial guess", VS_VISIBLE },
107 { RET_NO_EXTERN_SOLVER, "No extern QP solver available", VS_VISIBLE },
108 { RET_QP_UNBOUNDED, "QP is unbounded", VS_VISIBLE },
109 { RET_QP_INFEASIBLE, "QP is infeasible", VS_VISIBLE },
110 { RET_QP_NOT_SOLVED, "Problems occurred while solving QP with standard solver", VS_VISIBLE },
111 { RET_QP_SOLVED, "QP successfully solved", VS_VISIBLE },
112 { RET_UNABLE_TO_SOLVE_QP, "Problems occurred while solving QP", VS_VISIBLE },
113 { RET_INITIALISATION_STARTED, "Starting problem initialisation...", VS_VISIBLE },
114 { RET_HOTSTART_FAILED, "Unable to perform homotopy due to internal error", VS_VISIBLE },
115 { RET_HOTSTART_FAILED_TO_INIT, "Unable to initialise problem", VS_VISIBLE },
116 { RET_HOTSTART_FAILED_AS_QP_NOT_INITIALISED, "Unable to perform homotopy as previous QP is not solved", VS_VISIBLE },
117 { RET_ITERATION_STARTED, "Iteration", VS_VISIBLE },
118 { RET_SHIFT_DETERMINATION_FAILED, "Determination of shift of the QP data failed", VS_VISIBLE },
119 { RET_STEPDIRECTION_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE },
120 { RET_STEPLENGTH_DETERMINATION_FAILED, "Determination of step direction failed", VS_VISIBLE },
121 { RET_OPTIMAL_SOLUTION_FOUND, "Optimal solution of neighbouring QP found", VS_VISIBLE },
122 { RET_HOMOTOPY_STEP_FAILED, "Unable to perform homotopy step", VS_VISIBLE },
123 { RET_HOTSTART_STOPPED_INFEASIBILITY, "Premature homotopy termination because QP is infeasible", VS_VISIBLE },
124 { RET_HOTSTART_STOPPED_UNBOUNDEDNESS, "Premature homotopy termination because QP is unbounded", VS_VISIBLE },
125 { RET_WORKINGSET_UPDATE_FAILED, "Unable to update working sets according to initial guesses", VS_VISIBLE },
126 { RET_MAX_NWSR_REACHED, "Maximum number of working set recalculations performed", VS_VISIBLE },
127 { RET_CONSTRAINTS_NOT_SPECIFIED, "Problem does comprise constraints! You have to specify new constraints' bounds", VS_VISIBLE },
128 { RET_INVALID_FACTORISATION_FLAG, "Invalid factorisation flag", VS_VISIBLE },
129 { RET_UNABLE_TO_SAVE_QPDATA, "Unable to save QP data", VS_VISIBLE },
130 { RET_STEPDIRECTION_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE },
131 { RET_STEPDIRECTION_FAILED_CHOLESKY, "Abnormal termination due to Cholesky factorisation", VS_VISIBLE },
132 { RET_CYCLING_DETECTED, "Cycling detected", VS_VISIBLE },
133 { RET_CYCLING_NOT_RESOLVED, "Cycling cannot be resolved, QP is probably infeasible", VS_VISIBLE },
134 { RET_CYCLING_RESOLVED, "Cycling probably resolved", VS_VISIBLE },
135 { RET_STEPSIZE, "", VS_VISIBLE },
136 { RET_STEPSIZE_NONPOSITIVE, "", VS_VISIBLE },
137 { RET_SETUPSUBJECTTOTYPE_FAILED, "Setup of SubjectToTypes failed", VS_VISIBLE },
138 { RET_ADDCONSTRAINT_FAILED, "Addition of constraint to working set failed", VS_VISIBLE },
139 { RET_ADDCONSTRAINT_FAILED_INFEASIBILITY, "Addition of constraint to working set failed", VS_VISIBLE },
140 { RET_ADDBOUND_FAILED, "Addition of bound to working set failed", VS_VISIBLE },
141 { RET_ADDBOUND_FAILED_INFEASIBILITY, "Addition of bound to working set failed", VS_VISIBLE },
142 { RET_REMOVECONSTRAINT_FAILED, "Removal of constraint from working set failed", VS_VISIBLE },
143 { RET_REMOVEBOUND_FAILED, "Removal of bound from working set failed", VS_VISIBLE },
144 { RET_REMOVE_FROM_ACTIVESET, "Removing from active set:", VS_VISIBLE },
145 { RET_ADD_TO_ACTIVESET, "Adding to active set:", VS_VISIBLE },
146 { RET_REMOVE_FROM_ACTIVESET_FAILED, "Removing from active set failed", VS_VISIBLE },
147 { RET_ADD_TO_ACTIVESET_FAILED, "Adding to active set failed", VS_VISIBLE },
148 { RET_CONSTRAINT_ALREADY_ACTIVE, "Constraint is already active", VS_VISIBLE },
149 { RET_ALL_CONSTRAINTS_ACTIVE, "All constraints are active, no further constraint can be added", VS_VISIBLE },
150 { RET_LINEARLY_DEPENDENT, "New bound/constraint is linearly dependent", VS_VISIBLE },
151 { RET_LINEARLY_INDEPENDENT, "New bound/constraint is linearly independent", VS_VISIBLE },
152 { RET_LI_RESOLVED, "Linear independence of active constraint matrix successfully resolved", VS_VISIBLE },
153 { RET_ENSURELI_FAILED, "Failed to ensure linear independence of active constraint matrix", VS_VISIBLE },
154 { RET_ENSURELI_FAILED_TQ, "Abnormal termination due to TQ factorisation", VS_VISIBLE },
155 { RET_ENSURELI_FAILED_NOINDEX, "QP is infeasible", VS_VISIBLE },
156 { RET_ENSURELI_FAILED_CYCLING, "QP is infeasible", VS_VISIBLE },
157 { RET_BOUND_ALREADY_ACTIVE, "Bound is already active", VS_VISIBLE },
158 { RET_ALL_BOUNDS_ACTIVE, "All bounds are active, no further bound can be added", VS_VISIBLE },
159 { RET_CONSTRAINT_NOT_ACTIVE, "Constraint is not active", VS_VISIBLE },
160 { RET_BOUND_NOT_ACTIVE, "Bound is not active", VS_VISIBLE },
161 { RET_HESSIAN_NOT_SPD, "Projected Hessian matrix not positive definite", VS_VISIBLE },
162 { RET_HESSIAN_INDEFINITE, "Hessian matrix is indefinite", VS_VISIBLE },
163 { RET_MATRIX_SHIFT_FAILED, "Unable to update matrices or to transform vectors", VS_VISIBLE },
164 { RET_MATRIX_FACTORISATION_FAILED, "Unable to calculate new matrix factorisations", VS_VISIBLE },
165 { RET_PRINT_ITERATION_FAILED, "Unable to print information on current iteration", VS_VISIBLE },
166 { RET_NO_GLOBAL_MESSAGE_OUTPUTFILE, "No global message output file initialised", VS_VISIBLE },
167 { RET_DISABLECONSTRAINTS_FAILED, "Unable to disable constraints", VS_VISIBLE },
168 { RET_ENABLECONSTRAINTS_FAILED, "Unable to enable constraints", VS_VISIBLE },
169 { RET_ALREADY_ENABLED, "Bound or constraint is already enabled", VS_VISIBLE },
170 { RET_ALREADY_DISABLED, "Bound or constraint is already disabled", VS_VISIBLE },
171 { RET_NO_HESSIAN_SPECIFIED, "No Hessian matrix has been specified", VS_VISIBLE },
172 { RET_USING_REGULARISATION, "Using regularisation as Hessian matrix is not positive definite", VS_VISIBLE },
173 { RET_EPS_MUST_BE_POSITVE, "Eps for regularisation must be sufficiently positive", VS_VISIBLE },
174 { RET_REGSTEPS_MUST_BE_POSITVE, "Maximum number of regularisation steps must be non-negative", VS_VISIBLE },
175 { RET_HESSIAN_ALREADY_REGULARISED, "Hessian has been already regularised", VS_VISIBLE },
176 { RET_CANNOT_REGULARISE_IDENTITY, "Identity Hessian matrix cannot be regularised", VS_VISIBLE },
177 { RET_CANNOT_REGULARISE_SPARSE, "Sparse matrix cannot be regularised as diagonal entry is missing", VS_VISIBLE },
178 { RET_NO_REGSTEP_NWSR, "No additional regularisation step could be performed due to limits", VS_VISIBLE },
179 { RET_FEWER_REGSTEPS_NWSR, "Fewer additional regularisation steps have been performed due to limits", VS_VISIBLE },
180 { RET_CHOLESKY_OF_ZERO_HESSIAN, "Cholesky decomposition of (unregularised) zero Hessian matrix", VS_VISIBLE },
181 { RET_ZERO_HESSIAN_ASSUMED, "Zero Hessian matrix assumed as null pointer passed without specifying hessianType", VS_VISIBLE },
182 { RET_CONSTRAINTS_ARE_NOT_SCALED, "(should not be thrown, no longer in use)", VS_VISIBLE },
183 { RET_INITIAL_BOUNDS_STATUS_NYI, "(should not be thrown, no longer in use)", VS_VISIBLE },
184 { RET_ERROR_IN_CONSTRAINTPRODUCT, "Error in user-defined constraint product function", VS_VISIBLE },
185 { RET_FIX_BOUNDS_FOR_LP, "All initial bounds must be fixed when solving an (unregularised) LP", VS_VISIBLE },
186 { RET_USE_REGULARISATION_FOR_LP, "Set options.enableRegularisation=BT_TRUE for solving LPs", VS_VISIBLE },
187 /* SQProblem */
188 { RET_UPDATEMATRICES_FAILED, "Unable to update QP matrices", VS_VISIBLE },
189 { RET_UPDATEMATRICES_FAILED_AS_QP_NOT_SOLVED, "Unable to update matrices as previous QP is not solved", VS_VISIBLE },
190 /* Utils */
191 { RET_UNABLE_TO_OPEN_FILE, "Unable to open file", VS_VISIBLE },
192 { RET_UNABLE_TO_WRITE_FILE, "Unable to write into file", VS_VISIBLE },
193 { RET_UNABLE_TO_READ_FILE, "Unable to read from file", VS_VISIBLE },
194 { RET_FILEDATA_INCONSISTENT, "File contains inconsistent data", VS_VISIBLE },
195 /* Options */
196 { RET_OPTIONS_ADJUSTED, "Options needed to be adjusted for consistency reasons", VS_VISIBLE },
197 /* SolutionAnalysis */
198 { RET_UNABLE_TO_ANALYSE_QPROBLEM, "Unable to analyse (S)QProblem(B) object", VS_VISIBLE },
199 /* Benchmark */
200 { RET_NWSR_SET_TO_ONE, "Maximum number of working set changes was set to 1", VS_VISIBLE },
201 { RET_UNABLE_TO_READ_BENCHMARK, "Unable to read benchmark data", VS_VISIBLE },
202 { RET_BENCHMARK_ABORTED, "Benchmark aborted", VS_VISIBLE },
203 { RET_INITIAL_QP_SOLVED, "Initial QP solved", VS_VISIBLE },
204 { RET_QP_SOLUTION_STARTED, "Solving QP no.", VS_VISIBLE },
205 { RET_BENCHMARK_SUCCESSFUL, "Benchmark terminated successfully", VS_VISIBLE },
206 /* Sparse matrices */
207 { RET_NO_DIAGONAL_AVAILABLE, "Sparse matrix does not have entries on full diagonal", VS_VISIBLE },
208 { RET_DIAGONAL_NOT_INITIALISED, "Diagonal data of sparse matrix has not been initialised", VS_VISIBLE },
209 /* Dropping of infeasible constraints */
210 { RET_ENSURELI_DROPPED, "Linear independence resolved by dropping blocking constraint", VS_VISIBLE },
211 /* Schur complement computations */
212 { RET_KKT_MATRIX_SINGULAR, "KKT matrix is singular", VS_VISIBLE },
213 { RET_QR_FACTORISATION_FAILED, "QR factorization of Schur complement failed", VS_VISIBLE },
214 { RET_INERTIA_CORRECTION_FAILED, "Inertia correction of KKT matrix failed", VS_VISIBLE },
215 { RET_NO_SPARSE_SOLVER, "No Sparse Solver installed", VS_VISIBLE },
216 /* Simple exitflags */
217 { RET_SIMPLE_STATUS_P1, "QP problem could not be solved within given number of iterations", VS_VISIBLE },
218 { RET_SIMPLE_STATUS_P0, "QP problem solved", VS_VISIBLE },
219 { RET_SIMPLE_STATUS_M1, "QP problem could not be solved due to an internal error", VS_VISIBLE },
220 { RET_SIMPLE_STATUS_M2, "QP problem is infeasible (and thus could not be solved)", VS_VISIBLE },
221 { RET_SIMPLE_STATUS_M3, "QP problem is unbounded (and thus could not be solved)", VS_VISIBLE },
222 /* IMPORTANT: Terminal list element! */
223 { TERMINAL_LIST_ELEMENT, "", VS_HIDDEN }
224 };
225 
226 #else /* __SUPPRESSANYOUTPUT__ */
227 
228 MessageHandling::ReturnValueList returnValueList[1]; /* Do not use messages for embedded platforms! */
229 
230 #endif /* __SUPPRESSANYOUTPUT__ */
231 
232 
233 
234 /*****************************************************************************
235  * P U B L I C *
236  *****************************************************************************/
237 
238 /*
239  * M e s s a g e H a n d l i n g
240  */
242 {
246 
248  errorCount = 0;
249 }
250 
251 /*
252  * M e s s a g e H a n d l i n g
253  */
254 MessageHandling::MessageHandling( FILE* _outputFile )
255 {
259 
260  outputFile = _outputFile;
261  errorCount = 0;
262 }
263 
264 /*
265  * M e s s a g e H a n d l i n g
266  */
268  VisibilityStatus _warningVisibility,
269  VisibilityStatus _infoVisibility
270  )
271 {
272  errorVisibility = _errorVisibility;
273  warningVisibility = _warningVisibility;
274  infoVisibility = _infoVisibility;
275 
277  errorCount = 0;
278 }
279 
280 /*
281  * M e s s a g e H a n d l i n g
282  */
283 MessageHandling::MessageHandling( FILE* _outputFile,
284  VisibilityStatus _errorVisibility,
285  VisibilityStatus _warningVisibility,
286  VisibilityStatus _infoVisibility
287  )
288 {
289  errorVisibility = _errorVisibility;
290  warningVisibility = _warningVisibility;
291  infoVisibility = _infoVisibility;
292 
293  outputFile = _outputFile;
294  errorCount = 0;
295 }
296 
297 
298 
299 /*
300  * M e s s a g e H a n d l i n g
301  */
303 {
307 
308  outputFile = rhs.outputFile;
309  errorCount = rhs.errorCount;
310 }
311 
312 
313 /*
314  * ~ M e s s a g e H a n d l i n g
315  */
317 {
318  #ifndef __SUPPRESSANYOUTPUT__
319  if ( ( outputFile != 0 ) && ( outputFile != stdout ) && ( outputFile != stderr ) )
320  fclose( outputFile );
321  #endif /* __SUPPRESSANYOUTPUT__ */
322 }
323 
324 
325 /*
326  * o p e r a t o r =
327  */
329 {
330  if ( this != &rhs )
331  {
335 
336  outputFile = rhs.outputFile;
337  errorCount = rhs.errorCount;
338  }
339 
340  return *this;
341 }
342 
343 
344 /*
345  * t h r o w E r r o r
346  */
348  const char* additionaltext,
349  const char* functionname,
350  const char* filename,
351  const unsigned long linenumber,
352  VisibilityStatus localVisibilityStatus
353  )
354 {
355  /* consistency check */
356  if ( Enumber <= SUCCESSFUL_RETURN )
358 
359  /* Call to common throwMessage function if error shall be displayed. */
360  if ( errorVisibility == VS_VISIBLE )
361  return throwMessage( Enumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"ERROR" );
362  else
363  return Enumber;
364 }
365 
366 
367 /*
368  * t h r o w W a r n i n g
369  */
371  const char* additionaltext,
372  const char* functionname,
373  const char* filename,
374  const unsigned long linenumber,
375  VisibilityStatus localVisibilityStatus
376  )
377 {
378  /* consistency check */
379  if ( Wnumber <= SUCCESSFUL_RETURN )
381 
382  /* Call to common throwMessage function if warning shall be displayed. */
383  if ( warningVisibility == VS_VISIBLE )
384  return throwMessage( Wnumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"WARNING" );
385  else
386  return Wnumber;
387 }
388 
389 
390 /*
391  * t h r o w I n f o
392  */
394  const char* additionaltext,
395  const char* functionname,
396  const char* filename,
397  const unsigned long linenumber,
398  VisibilityStatus localVisibilityStatus
399  )
400 {
401  /* consistency check */
402  if ( Inumber < SUCCESSFUL_RETURN )
404 
405  /* Call to common throwMessage function if info shall be displayed. */
406  if ( infoVisibility == VS_VISIBLE )
407  return throwMessage( Inumber,additionaltext,functionname,filename,linenumber,localVisibilityStatus,"INFO" );
408  else
409  return Inumber;
410 }
411 
412 
413 /*
414  * r e s e t
415  */
417 {
421 
423  setErrorCount( 0 );
424 
425  return SUCCESSFUL_RETURN;
426 }
427 
428 
429 /*
430  * l i s t A l l M e s s a g e s
431  */
433 {
434  #ifndef __SUPPRESSANYOUTPUT__
435  int_t keypos = 0;
436  char myPrintfString[MAX_STRING_LENGTH];
437 
438  /* Run through whole returnValueList and print each item. */
439  while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
440  {
441  snprintf( myPrintfString,MAX_STRING_LENGTH," %d - %s \n",(int)keypos,returnValueList[keypos].data );
442  myPrintf( myPrintfString );
443 
444  ++keypos;
445  }
446  #endif /* __SUPPRESSANYOUTPUT__ */
447 
448  return SUCCESSFUL_RETURN;
449 }
450 
451 
452 
453 /*****************************************************************************
454  * P R O T E C T E D *
455  *****************************************************************************/
456 
457 
458 /*
459  * t h r o w M e s s a g e
460  */
462  const char* additionaltext,
463  const char* functionname,
464  const char* filename,
465  const unsigned long linenumber,
466  VisibilityStatus localVisibilityStatus,
467  const char* RETstring
468  )
469 {
470  #ifndef __SUPPRESSANYOUTPUT__
471 
472  int_t keypos = 0;
473  char myPrintfString[MAX_STRING_LENGTH];
474 
475  /* 1) Determine number of whitespace for output. */
476  char whitespaces[MAX_STRING_LENGTH];
477  int_t numberOfWhitespaces = (errorCount-1)*2;
478 
479  if ( numberOfWhitespaces < 0 )
480  numberOfWhitespaces = 0;
481 
482  if ( numberOfWhitespaces > 40 )
483  numberOfWhitespaces = 40;
484 
485  if ( numberOfWhitespaces >= (int_t)MAX_STRING_LENGTH )
486  numberOfWhitespaces = (int_t)MAX_STRING_LENGTH-1;
487 
488  memset( whitespaces, ' ', (size_t) numberOfWhitespaces );
489  whitespaces[numberOfWhitespaces] = '\0';
490 
491  /* 2) Find error/warning/info in list. */
492  while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
493  {
494  if ( returnValueList[keypos].key == RETnumber )
495  break;
496  else
497  ++keypos;
498  }
499 
500  if ( returnValueList[keypos].key == TERMINAL_LIST_ELEMENT )
501  {
503  return RETnumber;
504  }
505 
506  /* 3) Print error/warning/info. */
507  if ( ( returnValueList[keypos].globalVisibilityStatus == VS_VISIBLE ) && ( localVisibilityStatus == VS_VISIBLE ) )
508  {
509  if ( errorCount < 0 )
510  {
511  myPrintf( "\n" );
512  errorCount = 0;
513  }
514 
515  if ( errorCount > 0 )
516  {
517  snprintf( myPrintfString,MAX_STRING_LENGTH,"%s->", whitespaces );
518  myPrintf( myPrintfString );
519  }
520 
521  if ( additionaltext == 0 )
522  {
523  #ifdef __DEBUG__
524  snprintf( myPrintfString,MAX_STRING_LENGTH,"%s (%s, %s:%d): \t%s\n",
525  RETstring,functionname,filename,(int_t)linenumber,returnValueList[keypos].data
526  );
527  #else
528  snprintf( myPrintfString,MAX_STRING_LENGTH,"%s: %s\n",
529  RETstring,returnValueList[keypos].data
530  );
531  #endif
532  myPrintf( myPrintfString );
533  }
534  else
535  {
536  #ifdef __DEBUG__
537  snprintf( myPrintfString,MAX_STRING_LENGTH,"%s (%s, %s:%d): \t%s %s\n",
538  RETstring,functionname,filename,(int_t)linenumber,returnValueList[keypos].data,additionaltext
539  );
540  #else
541  snprintf( myPrintfString,MAX_STRING_LENGTH,"%s: %s %s\n",
542  RETstring,returnValueList[keypos].data,additionaltext
543  );
544  #endif
545  myPrintf( myPrintfString );
546  }
547 
548  /* take care of proper indention for subsequent error messages */
549  if ( RETstring[0] == 'E' )
550  {
551  ++errorCount;
552  }
553  else
554  {
555  if ( errorCount > 0 )
556  myPrintf( "\n" );
557  errorCount = 0;
558  }
559  }
560 
561  #endif /* __SUPPRESSANYOUTPUT__ */
562 
563  return RETnumber;
564 }
565 
566 /****************************************************************************/
567 /* S T A T I C P U B L I C */
568 /****************************************************************************/
569 
570 const char* MessageHandling::getErrorCodeMessage( const returnValue _returnValue
571  )
572 {
573  #ifndef __SUPPRESSANYOUTPUT__
574 
575  int_t keypos = 0;
576 
577  /* 2) Find error/warning/info in list. */
578  while ( returnValueList[keypos].key != TERMINAL_LIST_ELEMENT )
579  {
580  if ( returnValueList[keypos].key == _returnValue )
581  break;
582  else
583  ++keypos;
584  }
585 
586  if ( returnValueList[keypos].key == TERMINAL_LIST_ELEMENT )
587  {
588  return "Unknown error code";
589  }
590 
591  return (returnValueList[keypos].data != 0) ? returnValueList[keypos].data : "No message for this error code";
592 
593  #else /* __SUPPRESSANYOUTPUT__ */
594 
595  return "No message for this error code";
596 
597  #endif /* __SUPPRESSANYOUTPUT__ */
598 }
599 
600 
601 /*****************************************************************************
602  * G L O B A L M E S S A G E H A N D L E R *
603  *****************************************************************************/
604 
605 
607 #if defined(__DSPACE__) || defined(__XPCTARGET__)
609 #endif
610 
611 
612 /*
613  * g e t G l o b a l M e s s a g e H a n d l e r
614  */
616 {
617  #ifndef __DSPACE__
618  #ifndef __XPCTARGET__
620  #endif /* __DSPACE__ */
621  #endif /* __XPCTARGET__ */
622 
623  return &globalMessageHandler;
624 }
625 
626 
628 
629 
630 /*
631  * end of file
632  */
#define __LINE__
returnValue throwError(returnValue Enumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
returnValue throwInfo(returnValue Inumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
Allows to pass back messages to the calling function.
BEGIN_NAMESPACE_QPOASES FILE * stdFile
void setOutputFile(myFILE *_outputFile)
returnValue throwWarning(returnValue Wnumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus)
MessageHandling globalMessageHandler(myStderr, VS_VISIBLE, VS_VISIBLE, VS_VISIBLE)
returnValue myPrintf(const char *s)
static const char * getErrorCodeMessage(const returnValue _returnValue)
MessageHandling * getGlobalMessageHandler()
void setInfoVisibilityStatus(VisibilityStatus _infoVisibility)
returnValue setErrorCount(int _errorCount)
Handles all kind of error messages, warnings and other information.
void rhs(const real_t *x, real_t *f)
void setErrorVisibilityStatus(VisibilityStatus _errorVisibility)
returnValue throwMessage(returnValue RETnumber, const char *additionaltext, const char *functionname, const char *filename, const unsigned long linenumber, VisibilityStatus localVisibilityStatus, const char *RETstring)
#define __FILE__
MessageHandling::ReturnValueList returnValueList[]
void setWarningVisibilityStatus(VisibilityStatus _warningVisibility)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:53