-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWorkerBase.cpp
More file actions
112 lines (96 loc) · 3.53 KB
/
WorkerBase.cpp
File metadata and controls
112 lines (96 loc) · 3.53 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//---------------------------------------------------------------------------
#include <stdio.h>
#include <sstream>
#include "WorkerBase.h"
#include "SimManager.h"
#include "ParsingFunctions.h"
//---------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////
// Constructor
//////////////////////////////////////////////////////////////////////////////
clWorkerBase::clWorkerBase(clSimManager *p_oSimManager) {
try {
mp_oSimManager = p_oSimManager;
mp_iAllowedFileTypes = NULL;
m_iNumAllowedTypes = 0;
//namestring - defaults to empty string
m_sNameString = "";
}
catch (modelErr&err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch (...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clWorkerBase::clWorkerBase";
throw(stcErr);
}
}
//////////////////////////////////////////////////////////////////////////////
// Destructor
//////////////////////////////////////////////////////////////////////////////
clWorkerBase::~clWorkerBase() {
delete[] mp_iAllowedFileTypes;
}
//////////////////////////////////////////////////////////////////////////////
// AssembleFileCode
//////////////////////////////////////////////////////////////////////////////
void clWorkerBase::AssembleFileCode(int iFileType, int iFileVersion, char *cCode) {
int iMajorModelVersion, iMinorModelVersion; //model major and minor versions
//Make sure the sim manager pointer isn't NULL - if it is return error
if (NULL == mp_oSimManager) {
modelErr stcErr;
stcErr.iErrorCode = CANT_FIND_OBJECT;
stcErr.sFunction = "clWorkerBase::AssembleFileCode";
stcErr.sMoreInfo = "Pointer to Simulation Manager is NULL";
throw(stcErr);
}
//Query the sim manager for the model versions
iMajorModelVersion = mp_oSimManager->GetMajorVersion();
iMinorModelVersion = mp_oSimManager->GetMinorVersion();
//Make sure the codes are all two-digit
sprintf(cCode, "%02d%02d%02d%02d", iMajorModelVersion, iMinorModelVersion,
iFileType, iFileVersion);
}
////////////////////////////////////////////////////////////////////////////
// DoObjectSetup()
////////////////////////////////////////////////////////////////////////////
void clWorkerBase::DoObjectSetup(DOMDocument *p_oDoc, fileType iFileType) {
try {
bool bOKFile = false; //flag for whether this is an OK file type
//Make sure the pointer is not NULL - if it is, throw error
if (NULL == p_oDoc) {
modelErr stcErr;
stcErr.sFunction = "clWorkerBase::DoObjectSetup";
stcErr.iErrorCode = BAD_FILE;
throw(stcErr);
}
//Make sure that the file is one of the allowed types for this object
// iFileType = mp_oSimManager->GetFileType(p_oDoc);
for (int i = 0; i < m_iNumAllowedTypes; i++) {
if (iFileType == mp_iAllowedFileTypes[i]) {
bOKFile = true;
break;
}
}
if (!bOKFile) {
modelErr stcErr;
stcErr.sFunction = "clWorkerBase::DoObjectSetup";
stcErr.iErrorCode = BAD_FILE_TYPE;
std::stringstream s;
s << iFileType;
stcErr.sMoreInfo = s.str();
throw(stcErr);
}
//Call GetData for the object
GetData(p_oDoc);
}
catch (modelErr&err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch (...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clWorkerBase::DoObjectSetup";
throw(stcErr);
}
}
//---------------------------------------------------------------------------