Skip to content

Commit 855d18b

Browse files
Cleaned up virally infectious "using std;" statement;
more specific "using" statements largely remain
1 parent bebac6a commit 855d18b

File tree

7 files changed

+83
-88
lines changed

7 files changed

+83
-88
lines changed

IDAWin/OdeResultSet.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "Expression.h"
33
#include "SymbolTable.h"
44
#include "Exception.h"
5-
using namespace VCell;
65

76
#include <memory.h>
87

@@ -28,7 +27,7 @@ OdeResultSet::~OdeResultSet()
2827

2928
void OdeResultSet::addColumn(const string& aColumn) {
3029
if (numRowsAllocated != 0) {
31-
throw Exception("Can't add column when rowData is not empty");
30+
throw VCell::Exception("Can't add column when rowData is not empty");
3231
}
3332
columns.push_back(Column(aColumn, 0));
3433
numDataColumns ++;
@@ -43,7 +42,7 @@ void OdeResultSet::bindFunctionExpression(SymbolTable* symbolTable) {
4342
}
4443

4544
void OdeResultSet::addFunctionColumn(const string& aColumn, const string& exp) {
46-
columns.push_back(Column(aColumn, new Expression(exp)));
45+
columns.push_back(Column(aColumn, new VCell::Expression(exp)));
4746
numFunctionColumns ++;
4847
}
4948

@@ -76,7 +75,7 @@ void OdeResultSet::setColumnWeights(double* weights){
7675

7776
double* OdeResultSet::getRowData(int index) {
7877
if (index >= numRowsUsed) {
79-
throw Exception("OdeResultSet::getRowData(int index), row index is out of bounds");
78+
throw VCell::Exception("OdeResultSet::getRowData(int index), row index is out of bounds");
8079
}
8180
return rowData + index * numDataColumns;
8281
}
@@ -122,7 +121,7 @@ int OdeResultSet::getNumRows() {
122121
return numRowsUsed;
123122
}
124123

125-
Expression* OdeResultSet::getColumnFunctionExpression(int columnIndex) {
124+
VCell::Expression* OdeResultSet::getColumnFunctionExpression(int columnIndex) {
126125
if (columnIndex >= (int)columns.size()) {
127126
throw "OdeResultSet::getColumnFunctionExpression(), column index is out of bounds";
128127
}

IDAWin/OdeResultSet.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33

44
#include <string>
55
#include <vector>
6-
using namespace std;
76

87
namespace VCell {
98
class Expression;
109
}
1110
class SymbolTable;
1211

1312
struct Column {
14-
string name;
13+
std::string name;
1514
VCell::Expression* expression;
1615

17-
Column(string arg_name, VCell::Expression* exp) {
16+
Column(std::string arg_name, VCell::Expression* exp) {
1817
name = arg_name;
1918
expression = exp;
2019
}
@@ -25,8 +24,8 @@ class OdeResultSet
2524
public:
2625
OdeResultSet();
2726
~OdeResultSet();
28-
void addColumn(const string& aColumn);
29-
void addFunctionColumn(const string& aColumn, const string& columnExpression);
27+
void addColumn(const std::string& aColumn);
28+
void addFunctionColumn(const std::string& aColumn, const std::string& columnExpression);
3029
void addRow(double* aRow);
3130
void setColumnWeights(double* weights);
3231

@@ -37,16 +36,16 @@ class OdeResultSet
3736
return rowData;
3837
}
3938

40-
int findColumn(const string& aColumn);
39+
int findColumn(const std::string& aColumn);
4140
double getColumnWeight(int index);
42-
string& getColumnName(int index);
41+
std::string& getColumnName(int index);
4342
void getColumnData(int index, int numParams, double* paramValues, double* colData);
4443

4544
int getNumColumns();
4645
int getNumRows();
4746
int getNumFunctionColumns() { return numFunctionColumns; }
4847
int getNumDataColumns() { return numDataColumns; }
49-
vector<Column> getColumns(){ return columns;}
48+
std::vector<Column> getColumns(){ return columns;}
5049

5150
VCell::Expression* getColumnFunctionExpression(int columnIndex);
5251
void clearData();
@@ -57,7 +56,7 @@ class OdeResultSet
5756
private:
5857
// 0 : t
5958
// 1 ~ N : variable names;
60-
vector<Column> columns;
59+
std::vector<Column> columns;
6160
double* columnWeights;
6261
double* rowData;
6362
int numRowsAllocated;

IDAWin/SundialsSolverStandalone.cpp

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
1+
// Debug
12
#ifdef _DEBUG
2-
//#define _CRTDBG_MAP_ALLOC
3-
#ifdef _CRTDBG_MAP_ALLOC
4-
#include <stdlib.h>
5-
#include <crtdbg.h>
6-
#else
7-
//#include <vld.h>
3+
//#define _CRTDBG_MAP_ALLOC
4+
#ifdef _CRTDBG_MAP_ALLOC
5+
#include <stdlib.h>
6+
#include <crtdbg.h>
7+
#else
8+
//#include <vld.h>
9+
#endif
810
#endif
9-
#endif
10-
11+
// Messaging
1112
#ifdef USE_MESSAGING
1213
#include <VCELL/SimulationMessaging.h>
1314
#endif
15+
// Standard Includes
16+
#include <iomanip>
17+
#include <fstream>
18+
#include <sstream>
19+
#include <memory.h>
20+
#include <cstdlib>
21+
// Local Includes
1422
#include "VCellCVodeSolver.h"
1523
#include "VCellIDASolver.h"
1624
#include "OdeResultSet.h"
1725
#include "StoppedByUserException.h"
1826
#include <VCELL/GitDescribe.h>
1927

20-
#include <stdio.h>
21-
#include <iomanip>
22-
#include <fstream>
23-
#include <sstream>
24-
#include <string.h>
25-
using std::ifstream;
26-
using std::stringstream;
2728

28-
#include <memory.h>
29-
#include <stdlib.h>
3029

3130
#define CVODE_SOLVER "CVODE"
3231
#define IDA_SOLVER "IDA"
3332

3433
void printUsage() {
35-
cout << "Usage: SundialsSolverStandalone input output";
36-
#ifdef USE_MESSAGING
37-
cout << " [-tid 0]" << endl;
38-
#endif
39-
cout << endl;
34+
std::string usageMessage{"Usage: SundialsSolverStandalone input output"};
35+
#ifdef USE_MESSAGING
36+
usageMessage += " [-tid 0]";
37+
#endif
38+
std::cout << usageMessage << std::endl;
4039
}
4140

4241
void loadJMSInfo(istream& ifsInput, int taskID) {
@@ -93,7 +92,7 @@ void loadJMSInfo(istream& ifsInput, int taskID) {
9392
#endif
9493
}
9594

96-
void errExit(int returnCode, string& errorMsg) {
95+
void errExit(int returnCode, std::string& errorMsg) {
9796
#ifdef USE_MESSAGING
9897
if (returnCode != 0) {
9998
if (SimulationMessaging::getInstVar() != 0 && !SimulationMessaging::getInstVar()->isStopRequested()) {
@@ -110,7 +109,7 @@ void errExit(int returnCode, string& errorMsg) {
110109
}
111110
#else
112111
if (returnCode != 0) {
113-
cerr << errorMsg << endl;
112+
std::cerr << errorMsg << std::endl;
114113
}
115114
#endif
116115
}
@@ -119,7 +118,7 @@ int main(int argc, char *argv[]) {
119118
std::cout
120119
<< "Sundials Standalone version " << g_GIT_DESCRIBE
121120
<< std::endl;
122-
cout << setprecision(20);
121+
std::cout << std::setprecision(20);
123122

124123
int taskID = -1;
125124
string inputfname;
@@ -129,7 +128,7 @@ int main(int argc, char *argv[]) {
129128
int returnCode = 0;
130129

131130
if (argc < 3) {
132-
cout << "Missing arguments!" << endl;
131+
std::cout << "Missing arguments!" << std::endl;
133132
printUsage();
134133
exit(1);
135134
}
@@ -151,7 +150,7 @@ int main(int argc, char *argv[]) {
151150
}
152151
taskID = atoi(argv[i]);
153152
#else
154-
cout << "Wrong argument : " << argv[i] << endl;
153+
std::cout << "Wrong argument : " << argv[i] << std::endl;
155154
printUsage();
156155
exit(1);
157156
#endif
@@ -163,15 +162,15 @@ int main(int argc, char *argv[]) {
163162
}
164163

165164
FILE* outputFile = NULL;
166-
ifstream inputstream(inputfname.c_str());
165+
std::ifstream inputstream(inputfname.c_str());
167166
try {
168167
if (!inputstream.is_open()) {
169-
throw string("input file [") + inputfname + "] doesn't exit!";
168+
throw std::string("input file [") + inputfname + "] doesn't exit!";
170169
}
171170

172171
// Open the output file...
173172
if ((outputFile = fopen(argv[2], "w")) == NULL) {
174-
throw string("Could not open output file[") + outputfname + "] for writing.";
173+
throw std::string("Could not open output file[") + outputfname + "] for writing.";
175174
}
176175

177176
string nextToken;

IDAWin/VCellCVodeSolver.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ int VCellCVodeSolver::RHS (realtype t, N_Vector y, N_Vector r) {
231231
recoverableErrMsg = "";
232232
return 0;
233233
}catch (DivideByZeroException e){
234-
cout << "failed to evaluate residual: " << e.getMessage() << endl;
234+
std::cout << "failed to evaluate residual: " << e.getMessage() << std::endl;
235235
recoverableErrMsg = e.getMessage();
236236
return 1;
237237
}catch (FunctionDomainException e){
238-
cout << "failed to evaluate residual: " << e.getMessage() << endl;
238+
std::cout << "failed to evaluate residual: " << e.getMessage() << std::endl;
239239
recoverableErrMsg = e.getMessage();
240240
return 1;
241241
}catch (FunctionRangeException e){
242-
cout << "failed to evaluate residual: " << e.getMessage() << endl;
242+
std::cout << "failed to evaluate residual: " << e.getMessage() << std::endl;
243243
recoverableErrMsg = e.getMessage();
244244
return 1;
245245
}
@@ -326,7 +326,7 @@ bool VCellCVodeSolver::fixInitialDiscontinuities(double t) {
326326
double* oldy = new double[NEQ];
327327
memcpy(oldy, NV_DATA_S(y), NEQ * sizeof(realtype));
328328

329-
double epsilon = max(1e-15, ENDING_TIME * 1e-10);
329+
double epsilon = std::max(1e-15, ENDING_TIME * 1e-10);
330330
double currentTime = t;
331331
double tout = currentTime + epsilon;
332332
CVodeSetStopTime(solver, tout);
@@ -341,7 +341,7 @@ bool VCellCVodeSolver::fixInitialDiscontinuities(double t) {
341341
// evaluate discontinuities at t+epsilon
342342
double v = odeDiscontinuities[i]->discontinuityExpression->evaluateVector(values);
343343
if (v != discontinuityValues[i]) {
344-
cout << "fixInitialDiscontinuities() : update discontinuities at time " << t << " : " << odeDiscontinuities[i]->discontinuityExpression->infix() << " " << discontinuityValues[i] << " " << v << endl;
344+
std::cout << "fixInitialDiscontinuities() : update discontinuities at time " << t << " : " << odeDiscontinuities[i]->discontinuityExpression->infix() << " " << discontinuityValues[i] << " " << v << std::endl;
345345
discontinuityValues[i] = v;
346346
bInitChanged = true;
347347
}
@@ -364,7 +364,7 @@ void VCellCVodeSolver::onCVodeReturn(realtype Time, int returnCode) {
364364
// flip discontinuities
365365
int flag = CVodeGetRootInfo(solver, rootsFound);
366366
checkCVodeFlag(flag);
367-
cout << endl << "cvodeSolve() : roots found at time " << Time << endl;
367+
std::cout << std::endl << "cvodeSolve() : roots found at time " << Time << std::endl;
368368
#ifdef SUNDIALS_DEBUG
369369
printVariableValues(Time);
370370
#endif
@@ -419,8 +419,8 @@ void VCellCVodeSolver::cvodeSolve(bool bPrintProgress, FILE* outputFile, void (*
419419
checkStopRequested(Time, iterationCount);
420420
}
421421

422-
double tstop = min(ENDING_TIME, Time + 2 * maxTimeStep + (1e-15));
423-
tstop = min(tstop, getNextEventTime());
422+
double tstop = std::min(ENDING_TIME, Time + 2 * maxTimeStep + (1e-15));
423+
tstop = std::min(tstop, getNextEventTime());
424424

425425
CVodeSetStopTime(solver, tstop);
426426
int returnCode = CVode(solver, ENDING_TIME, y, &Time, CV_ONE_STEP_TSTOP);
@@ -462,8 +462,8 @@ void VCellCVodeSolver::cvodeSolve(bool bPrintProgress, FILE* outputFile, void (*
462462
checkStopRequested(Time, iterationCount);
463463
}
464464

465-
double tstop = min(sampleTime, Time + 2 * maxTimeStep + (1e-15));
466-
tstop = min(tstop, getNextEventTime());
465+
double tstop = std::min(sampleTime, Time + 2 * maxTimeStep + (1e-15));
466+
tstop = std::min(tstop, getNextEventTime());
467467

468468
CVodeSetStopTime(solver, tstop);
469469
int returnCode = CVode(solver, sampleTime, y, &Time, CV_NORMAL_TSTOP);

IDAWin/VCellIDASolver.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <DivideByZeroException.h>
88
#include <FunctionDomainException.h>
99
#include <FunctionRangeException.h>
10-
#include <time.h>
1110
#include <sys/timeb.h>
1211
#include <sstream>
1312
using std::stringstream;
@@ -16,7 +15,7 @@ using std::stringstream;
1615
#include <VCELL/SimulationMessaging.h>
1716
#endif
1817

19-
#include <assert.h>
18+
#include <cassert>
2019
#include <ida/ida.h>
2120
#include <ida/ida_dense.h>
2221
//#include <ida/ida_spgmr.h>
@@ -250,15 +249,15 @@ int VCellIDASolver::Residual(realtype t, N_Vector y, N_Vector yp, N_Vector resid
250249
recoverableErrMsg = "";
251250
return 0;
252251
}catch (DivideByZeroException e){
253-
cout << "failed to evaluate residual: " << e.getMessage() << endl;
252+
std::cout << "failed to evaluate residual: " << e.getMessage() << std::endl;
254253
recoverableErrMsg = e.getMessage();
255254
return 1;
256255
}catch (FunctionDomainException e){
257-
cout << "failed to evaluate residual: " << e.getMessage() << endl;
256+
std::cout << "failed to evaluate residual: " << e.getMessage() << std::endl;
258257
recoverableErrMsg = e.getMessage();
259258
return 1;
260259
}catch (FunctionRangeException e){
261-
cout << "failed to evaluate residual: " << e.getMessage() << endl;
260+
std::cout << "failed to evaluate residual: " << e.getMessage() << std::endl;
262261
recoverableErrMsg = e.getMessage();
263262
return 1;
264263
}
@@ -493,7 +492,7 @@ void VCellIDASolver::reInit(double t) {
493492
}
494493
checkIDAFlag(flag);
495494

496-
realtype tout1 = min(ENDING_TIME, t + 2 * maxTimeStep + (1e-15));
495+
realtype tout1 = std::min(ENDING_TIME, t + 2 * maxTimeStep + (1e-15));
497496

498497
flag = IDACalcIC(solver, IDA_YA_YDP_INIT, tout1);
499498
checkIDAFlag(flag);
@@ -510,7 +509,7 @@ bool VCellIDASolver::fixInitialDiscontinuities(double t) {
510509
double* oldy = new double[NEQ];
511510
memcpy(oldy, NV_DATA_S(y), NEQ * sizeof(realtype));
512511

513-
double epsilon = max(1e-15, ENDING_TIME * 1e-8);
512+
double epsilon = std::max(1e-15, ENDING_TIME * 1e-8);
514513
double currentTime = t;
515514
realtype tout = currentTime + epsilon;
516515
IDASetStopTime(solver, tout);
@@ -524,7 +523,7 @@ bool VCellIDASolver::fixInitialDiscontinuities(double t) {
524523
for (int i = 0; i < numDiscontinuities; i ++) {
525524
double v = odeDiscontinuities[i]->discontinuityExpression->evaluateVector(values);
526525
if (v != discontinuityValues[i]) {
527-
cout << "update discontinuities at time " << t << " : " << odeDiscontinuities[i]->discontinuityExpression->infix() << " " << discontinuityValues[i] << " " << v << endl;
526+
std::cout << "update discontinuities at time " << t << " : " << odeDiscontinuities[i]->discontinuityExpression->infix() << " " << discontinuityValues[i] << " " << v << std::endl;
528527
discontinuityValues[i] = v;
529528
bInitChanged = true;
530529
}
@@ -551,7 +550,7 @@ void VCellIDASolver::onIDAReturn(realtype Time, int returnCode) {
551550
// flip discontinuities
552551
int flag = IDAGetRootInfo(solver, rootsFound);
553552
checkIDAFlag(flag);
554-
cout << endl << "idaSolve() : roots found at time " << Time << endl;
553+
std::cout << std::endl << "idaSolve() : roots found at time " << Time << std::endl;
555554
#ifdef SUNDIALS_DEBUG
556555
printVariableValues(Time);
557556
#endif
@@ -608,8 +607,8 @@ void VCellIDASolver::idaSolve(bool bPrintProgress, FILE* outputFile, void (*chec
608607
checkStopRequested(Time, iterationCount);
609608
}
610609

611-
double tstop = min(ENDING_TIME, Time + 2 * maxTimeStep + (1e-15));
612-
tstop = min(tstop, getNextEventTime());
610+
double tstop = std::min(ENDING_TIME, Time + 2 * maxTimeStep + (1e-15));
611+
tstop = std::min(tstop, getNextEventTime());
613612

614613
IDASetStopTime(solver, tstop);
615614
int returnCode = IDASolve(solver, ENDING_TIME, &Time, y, yp, IDA_ONE_STEP_TSTOP);
@@ -651,8 +650,8 @@ void VCellIDASolver::idaSolve(bool bPrintProgress, FILE* outputFile, void (*chec
651650
checkStopRequested(Time, iterationCount);
652651
}
653652

654-
double tstop = min(sampleTime, Time + 2 * maxTimeStep + (1e-15));
655-
tstop = min(tstop, getNextEventTime());
653+
double tstop = std::min(sampleTime, Time + 2 * maxTimeStep + (1e-15));
654+
tstop = std::min(tstop, getNextEventTime());
656655

657656
IDASetStopTime(solver, tstop);
658657
int returnCode = IDASolve(solver, sampleTime, &Time, y, yp, IDA_NORMAL_TSTOP);

0 commit comments

Comments
 (0)