-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathhelpers.h
78 lines (68 loc) · 2.72 KB
/
helpers.h
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
73
74
75
76
77
78
#include "sierrachart.h"
#include <utility>
class Helper
{
protected:
template <typename T>
void logit(T t) {
SCString log_message;
SCString typenm = typeid(t).name();
const char* strtype = typenm.GetChars();
//log_message.Format("%s", strtype);
//sc.AddMessageToLog(log_message,1);
if (typenm == "PKc") {
// pointer to character array - string
//log_message.Format("String(%s)='%s'", strtype, t);
log_message.Format("'%s'", t);
}
else if (typenm == "i") {
// int
//log_message.Format("Int(%s)='%d'", strtype, t);
log_message.Format("'%d'", t);
}
else if (typenm == "d" || typenm == "f") {
// double/float
//log_message.Format("Float(%s)='%f'", strtype, t);
log_message.Format("'%f'",t);
}
else if (typenm == "8SCString") {
// SCString obj
SCString* sptr = (SCString*)&t;
SCString ksptr = *sptr;
//log_message.Format("SCString(%s)='%s'", strtype, ksptr.GetChars());
log_message.Format("'%s'", ksptr.GetChars());
}
else if (typenm == "class SCString") {
// SCString obj
SCString &st = (SCString&)t;
log_message.Format("'%s'", st.GetChars());
}
else {
log_message.Format("Unknown type: \"%s\"", strtype);
}
sc.AddMessageToLog(log_message,1);
}
private:
SCStudyInterfaceRef sc;
public:
// constructor with inline initialization
Helper(SCStudyInterfaceRef r) : sc(r) {}
// dump functions
template <typename... Args>
void dump(Args&&... args) {
int tmp[] = {0, ((void) logit(std::forward<Args>(args)), 0)... };
}
void log(SCString log_message) {
unsigned int bytesWritten = 0;
int fileHandle;
int msgLength = 0;
SCString nowStr = sc.DateTimeToString(sc.CurrentSystemDateTime, FLAG_DT_COMPLETE_DATETIME_MS);
log_message = nowStr + " | " + log_message;
msgLength = log_message.GetLength() + 2;
SCString filePath = "C:\\SierraChart\\debug.log";
sc.OpenFile(filePath, n_ACSIL::FILE_MODE_OPEN_TO_APPEND, fileHandle);
log_message = log_message + "\r\n";
sc.WriteFile(fileHandle, log_message, msgLength, &bytesWritten);
sc.CloseFile(fileHandle);
}
};