Skip to content

Commit 4c485ed

Browse files
committed
I fix the problem in the init(), and add the documentation for the init() and term()
1 parent 86f98c3 commit 4c485ed

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

Simulator/Connections/Neuro/ConnGrowth.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include "ParseParamError.h"
4747

4848
#ifdef USE_HDF5
49-
//#include "Hdf5GrowthRecorder.h"
5049
#include "Hdf5Recorder.h"
5150
#endif
5251

Simulator/Recorders/Hdf5Recorder.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ Hdf5Recorder::Hdf5Recorder()
3131
fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file"));
3232

3333
resultOut_ = nullptr;
34-
35-
init();
3634
}
3735

36+
// destructor
3837
Hdf5Recorder::~Hdf5Recorder()
3938
{
4039
term();
@@ -86,21 +85,24 @@ void Hdf5Recorder::init()
8685
}
8786
}
8887

88+
// This method closes the HDF5 file and releases any associated resources
8989
void Hdf5Recorder::term()
9090
{
91+
// checks if the file object `resultOut_` is not null, then attempts to close the file and delete the object
9192
if (resultOut_ != nullptr) {
9293
try {
9394
resultOut_->close();
9495
delete resultOut_;
9596
resultOut_ = nullptr;
9697
} catch (FileIException &error) {
98+
// If an exception occurs during this process, it prints the error stack for debugging purposes
9799
cerr << "HDF5 File I/O Exception during termination: ";
98100
error.printErrorStack();
99101
}
100102
}
101103
}
102104

103-
/// Create data spaces and data sets of the hdf5 for recording histories.
105+
// Create data spaces and data sets of the hdf5 for recording histories.
104106
void Hdf5Recorder::initDataSet()
105107
{
106108
}

Simulator/Recorders/Hdf5Recorder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class Hdf5Recorder : public Recorder {
101101
Hdf5Recorder(const string &fileName)
102102
{
103103
resultFileName_ = fileName;
104-
init();
105104
}
106105

107106
private:

Testing/UnitTesting/Hdf5RecorderTests.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@ TEST(Hdf5RecorderTest, CreateInstanceSuccess)
1212
}
1313

1414
// Test case for init() and term()
15-
TEST(Hdf5RecorderTest, Hdf5InitAndTermTest) {
16-
// Create an instance of Hdf5Recorder with a specific output file name
17-
std::string outputFile = "../Testing/UnitTesting/TestOutput/Hdf5test_output_term.h5";
18-
Hdf5Recorder recorder(outputFile);
19-
20-
// Ensure the file has been created successfully by the constructor
21-
FILE *f = fopen(outputFile.c_str(), "r");
22-
ASSERT_TRUE(f != NULL);
23-
fclose(f);
15+
TEST(Hdf5RecorderTest, Hdf5InitAndTermTest)
16+
{
17+
// Create an instance of Hdf5Recorder with a specific output file name
18+
std::string outputFile = "../Testing/UnitTesting/TestOutput/Hdf5test_output_term.h5";
19+
Hdf5Recorder recorder(outputFile);
20+
recorder.init();
21+
22+
// Ensure the file has been created successfully by the constructor
23+
FILE *f = fopen(outputFile.c_str(), "r");
24+
ASSERT_TRUE(f != NULL);
25+
fclose(f);
2426

25-
// Call the term() method to close the HDF5 file
26-
recorder.term();
27+
// Call the term() method to close the HDF5 file
28+
recorder.term();
2729

28-
// Check if the file can be reopened, indicating it was closed properly
29-
f = fopen(outputFile.c_str(), "r");
30-
bool fileExist = f != NULL;
31-
fclose(f);
32-
ASSERT_TRUE(fileExist);
30+
// Check if the file can be reopened, indicating it was closed properly
31+
f = fopen(outputFile.c_str(), "r");
32+
bool fileExist = f != NULL;
33+
fclose(f);
34+
ASSERT_TRUE(fileExist);
3335
}
3436
#endif // HDF5

0 commit comments

Comments
 (0)