OpenVSP API Documentation 3.51.0
Loading...
Searching...
No Matches
APIErrorMgr.h
1//
2// This file is released under the terms of the NASA Open Source Agreement (NOSA)
3// version 1.3 as detailed in the LICENSE file which accompanies this software.
4//
5
6// API.h: interface for the Vehicle Class and Vehicle Mgr Singleton.
7// J.R Gloudemans
8//
10
11#if !defined(APIERRORMGR__INCLUDED_)
12#define APIERRORMGR__INCLUDED_
13
14#include "APIDefines.h"
15#include "MessageMgr.h"
16
17#include <string>
18#include <stack>
19#include <vector>
20
21using std::string;
22using std::stack;
23using std::vector;
24
25class Vehicle;
26
27namespace vsp
28{
29
30
31//======================== Error Object ================================//
38class ErrorObj
39{
40public:
41 ErrorObj();
42 ErrorObj( ERROR_CODE err_code, const string & err_str );
43 ErrorObj( const ErrorObj& from );
44 ~ErrorObj() {}
45
70
72
73 {
74 return m_ErrorCode;
75 }
76
102
104
105 {
106 return m_ErrorString;
107 }
108
109 ERROR_CODE m_ErrorCode;
110 string m_ErrorString;
111
112 void NoError()
113 {
114 m_ErrorCode = VSP_OK;
115 m_ErrorString = "No Error";
116 }
117};
118
119
120//======================== Error Mgr ================================//
121class ErrorMgrSingleton : public MessageBase
122{
123public:
124
166
167 bool GetErrorLastCallFlag(); // Did the last call have an error?
168
213
214 int GetNumTotalErrors(); // Total number of errors on stack
215
260
261 ErrorObj PopLastError(); // Pop last error off stack
262
306
307 ErrorObj GetLastError(); // Get last error but leave on stack
308
309 bool PopErrorAndPrint( FILE* stream ); // Check for error, pop and print to stream
310
343
344 void SilenceErrors() { m_PrintErrors = false; };
345
378
379 void PrintOnErrors() { m_PrintErrors = true; };
380
381
382 void AddError( ERROR_CODE code, const string & desc );
383 void NoError();
384
385 virtual void MessageCallback( const MessageBase* from, const MessageData& data );
386
387 static ErrorMgrSingleton& getInstance()
388 {
389 static ErrorMgrSingleton instance;
390 return instance;
391 }
392
393private:
394
395 bool m_PrintErrors;
396 bool m_ErrorLastCallFlag;
397 stack< ErrorObj > m_ErrorStack;
398
399 ErrorMgrSingleton();
400 ~ErrorMgrSingleton();
401 ErrorMgrSingleton( ErrorMgrSingleton const& copy ) = delete; // Not Implemented
402 ErrorMgrSingleton& operator=( ErrorMgrSingleton const& copy ) = delete; // Not Implemented
403};
404
405#define ErrorMgr ErrorMgrSingleton::getInstance()
406
407}
408
409#endif // !defined(APIERRORMGR__INCLUDED_)
410
string GetErrorString()
ERROR_CODE GetErrorCode()
Definition APIErrorMgr.h:71
ERROR_CODE
Definition APIDefines.h:508
@ VSP_OK
Definition APIDefines.h:509