/
ModelicaUtilities.cpp
72 lines (64 loc) · 1.43 KB
/
ModelicaUtilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/** @addtogroup coreUtils
*
* @{
*/
#include <Core/ModelicaDefine.h>
#include <Core/Modelica.h>
#include <Core/Utils/Modelica/ModelicaUtilities.h>
#include <stdexcept>
#include <exception>
#include <string>
#include <stdio.h>
#include <stdarg.h>
#include <sstream>
#ifdef __cplusplus
extern "C" {
#endif
void ModelicaMessage(const char* string)
{
throw ModelicaSimulationError(UTILITY,"ModelicaMessage not implemented yet");
}
void ModelicaVFormatMessage(const char*string, va_list args)
{
vfprintf(stdout, string, args);
fflush(stdout);
}
void ModelicaFormatMessage(const char* string,...)
{
va_list args;
va_start(args, string);
ModelicaVFormatMessage(string, args);
va_end(args);
}
void ModelicaError(const char* string)
{
throw ModelicaSimulationError(UTILITY,string);
}
void ModelicaVFormatError(const char*string, va_list args)
{
throw ModelicaSimulationError(UTILITY,"ModelicaVFormatError not implemented yet");
}
void ModelicaFormatError(const char* text, ...)
{
std::stringstream ss;
va_list args;
va_start(args, text);
ss << text;
va_end(args);
ModelicaError(ss.str().c_str());
}
char* ModelicaAllocateString(size_t len)
{
return new char[len];
}
char* ModelicaAllocateStringWithErrorReturn(size_t len)
{
char *res = new char[len];
if(!res)
ModelicaFormatError("%s:%d: ModelicaAllocateString failed", __FILE__, __LINE__);
return res;
}
#ifdef __cplusplus
}
#endif
/** @} */ // end of coreUtils