-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathObjectManagerBase.cpp
More file actions
179 lines (159 loc) · 5.52 KB
/
ObjectManagerBase.cpp
File metadata and controls
179 lines (159 loc) · 5.52 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//---------------------------------------------------------------------------
#include "ObjectManagerBase.h"
#include "SimManager.h"
#include "WorkerBase.h"
//---------------------------------------------------------------------------
using namespace std;
////////////////////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////////////////////
clObjectManagerBase::clObjectManagerBase(clSimManager *p_oSimManager) {
try {
mp_oSimManager = p_oSimManager;
mp_oObjectArray = NULL;
m_iNumObjects = 0;
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::clObjectManagerBase";
throw(stcErr);
}
}
////////////////////////////////////////////////////////////////////////////
// Destructor
////////////////////////////////////////////////////////////////////////////
clObjectManagerBase::~clObjectManagerBase() {
FreeMemory();
}
////////////////////////////////////////////////////////////////////////////
// PassObjectPointer()
///////////////////////////////////////////////////////////////////////////*/
clWorkerBase* clObjectManagerBase::PassObjectPointer(int iObjectNumber) {
try {
clWorkerBase *p_oObject = NULL;
if (iObjectNumber >= 0 && iObjectNumber < m_iNumObjects)
p_oObject = mp_oObjectArray[iObjectNumber];
return p_oObject;
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::PassObjectPointer(int)";
throw(stcErr);
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////
// PassObjectPointer()
////////////////////////////////////////////////////////////////////////////
clWorkerBase* clObjectManagerBase::PassObjectPointer(string sName) {
try {
clWorkerBase *p_oObject = NULL;
for (int i = 0; i < m_iNumObjects; i++)
if (mp_oObjectArray[i] && mp_oObjectArray[i]->GetName().compare(sName) == 0)
p_oObject = mp_oObjectArray[i];
return p_oObject;
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::PassObjectPointer(string)";
throw(stcErr);
}
return NULL;
}
////////////////////////////////////////////////////////////////////////////
// TimestepCleanup()
////////////////////////////////////////////////////////////////////////////
void clObjectManagerBase::TimestepCleanup() {
try {
clWorkerBase *p_oObject = NULL;
//for each member object, trigger their timestep cleanup function
for (int i = 0; i < m_iNumObjects; i++) {
p_oObject = mp_oObjectArray[i];
p_oObject->TimestepCleanup();
}
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::TimestepCleanup";
throw(stcErr);
}
}
////////////////////////////////////////////////////////////////////////////
// EndOfRunCleanup()
////////////////////////////////////////////////////////////////////////////
void clObjectManagerBase::EndOfRunCleanup() {
try {
clWorkerBase *p_oObject = NULL;
//for each member object, trigger their timestep cleanup function
for (int i = 0; i < m_iNumObjects; i++) {
p_oObject = mp_oObjectArray[i];
p_oObject->EndOfRunCleanup();
}
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::EndOfRunCleanup";
throw(stcErr);
}
}
////////////////////////////////////////////////////////////////////////////
// FreeMemory()
////////////////////////////////////////////////////////////////////////////
void clObjectManagerBase::FreeMemory() {
try {
for (int i = 0; i < m_iNumObjects; i++) {
delete mp_oObjectArray[i];
} //end of for (int i = 0; i < m_iNumObjects; i++)
delete[] mp_oObjectArray; mp_oObjectArray = NULL;
m_iNumObjects = 0;
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::FreeMemory";
throw(stcErr);
}
}
////////////////////////////////////////////////////////////////////////////
// DoObjectSetup()
////////////////////////////////////////////////////////////////////////////
void clObjectManagerBase::DoObjectSetup(DOMDocument *p_oDoc,fileType iFileType){
try {
std::string strFileCode; //for getting the file code
//Make sure that the DOM_Document pointer is not NULL
if (NULL == p_oDoc) {
modelErr stcErr;
stcErr.sFunction = "clObjectManagerBase::DoObjectSetup";
stcErr.iErrorCode = CANT_FIND_OBJECT;
stcErr.sMoreInfo = "Document pointer passed is NULL.";
throw(stcErr);
}
for (int i = 0; i < m_iNumObjects; i++)
mp_oObjectArray[i]->DoObjectSetup(p_oDoc, iFileType);
}
catch(modelErr &err) {throw(err);}
catch (modelMsg &msg) {throw(msg);} //non-fatal error
catch(...) {
modelErr stcErr;
stcErr.iErrorCode = UNKNOWN;
stcErr.sFunction = "clObjectManagerBase::DoObjectSetup";
throw(stcErr);
}
}