File tree 3 files changed +23
-0
lines changed
3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ namespace celero
45
45
// /
46
46
void setFileName (const std::string& x);
47
47
48
+ // /
49
+ // / Force the output file (if any) to close
50
+ // /
51
+ void closeFile ();
48
52
// /
49
53
// / Add a new result to the result table.
50
54
// /
Original file line number Diff line number Diff line change @@ -139,13 +139,15 @@ void celero::Run(int argc, char** argv)
139
139
}
140
140
141
141
// Has a result output file been specified?
142
+ bool must_close_file = false ;
142
143
auto argument = args.get <std::string>(" outputTable" );
143
144
if (argument.empty () == false )
144
145
{
145
146
std::cout << " Writing results to: " << argument << std::endl;
146
147
celero::ResultTable::Instance ().setFileName (argument);
147
148
148
149
celero::AddExperimentResultCompleteFunction ([](std::shared_ptr<celero::Result> p) { celero::ResultTable::Instance ().add (p); });
150
+ must_close_file = true ;
149
151
}
150
152
151
153
// Has a result output file been specified?
@@ -185,6 +187,9 @@ void celero::Run(int argc, char** argv)
185
187
executor::RunAll ();
186
188
}
187
189
190
+ if (must_close_file) {
191
+ celero::ResultTable::Instance ().closeFile ();
192
+ }
188
193
// Final output.
189
194
std::cout << " Complete.\n " ;
190
195
}
Original file line number Diff line number Diff line change @@ -38,6 +38,16 @@ class celero::ResultTable::Impl
38
38
{
39
39
}
40
40
41
+ ~Impl () {
42
+ closeFile ();
43
+ }
44
+
45
+ void closeFile () {
46
+ if (this ->ofs .is_open () == true ) {
47
+ this ->ofs .close ();
48
+ }
49
+ }
50
+
41
51
void setFileName (const std::string& x)
42
52
{
43
53
if (this ->ofs .is_open () == true )
@@ -88,6 +98,10 @@ void ResultTable::setFileName(const std::string& x)
88
98
this ->pimpl ->setFileName (x);
89
99
}
90
100
101
+ void ResultTable::closeFile () {
102
+ this ->pimpl ->closeFile ();
103
+ }
104
+
91
105
void ResultTable::add (std::shared_ptr<Result> x)
92
106
{
93
107
if (this ->pimpl ->ofs .is_open () == true )
You can’t perform that action at this time.
0 commit comments