mirror of
https://github.com/nqrduck/LimeDriver.git
synced 2024-11-22 01:52:24 +00:00
Refactor configuration array to vector
Replaced the array parameter in `dumpConfig` function with a vector reference, streamlining parameter passing and enhancing code maintainability. Included `<cstddef>` for `size_t` definition and removed redundant code that copied vector contents to an array, thus improving performance. These changes eliminate the need for manual array sizing and copying, reducing potential errors and improving readability.
This commit is contained in:
parent
8edfbda8f7
commit
77b3f90d34
1 changed files with 7 additions and 9 deletions
|
@ -16,6 +16,7 @@ $(h5c++ -show) limedriver.cpp -std=c++11 $(pkg-config --cflags --libs LimeSuite)
|
||||||
#include "H5Cpp.h"
|
#include "H5Cpp.h"
|
||||||
#include "lime/LimeSuite.h"
|
#include "lime/LimeSuite.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
@ -370,14 +371,14 @@ std::vector<Config2HDFattr_t> getHDFAttributes(LimeConfig_t& LimeCfg) {
|
||||||
return HDFattr;
|
return HDFattr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpConfig(Config2HDFattr_t *config, size_t size) {
|
void dumpConfig(std::vector<Config2HDFattr_t> &config) {
|
||||||
/* Dump the configuration to stdout in JSON format
|
/* Dump the configuration to stdout in JSON format
|
||||||
|
|
||||||
@param config: Array of Config2HDFattr_t
|
@param config: Array of Config2HDFattr_t
|
||||||
@param size: Size of the array
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
size_t size = config.size();
|
||||||
|
|
||||||
int ii_oupargs = 0; // TODO: Better name
|
int ii_oupargs = 0; // TODO: Better name
|
||||||
|
|
||||||
std::cout << "{" << std::endl;
|
std::cout << "{" << std::endl;
|
||||||
|
@ -774,10 +775,6 @@ int main(int argc, char **argv) {
|
||||||
std::vector<Config2HDFattr_t> HDFattrVector = getHDFAttributes(LimeCfg);
|
std::vector<Config2HDFattr_t> HDFattrVector = getHDFAttributes(LimeCfg);
|
||||||
size_t no_of_attr = HDFattrVector.size();
|
size_t no_of_attr = HDFattrVector.size();
|
||||||
|
|
||||||
// Converting to array to maintain compatibility with older code
|
|
||||||
Config2HDFattr_t HDFattr[no_of_attr];
|
|
||||||
std::copy(HDFattrVector.begin(), HDFattrVector.end(), HDFattr);
|
|
||||||
|
|
||||||
bool dumpFlag = false;
|
bool dumpFlag = false;
|
||||||
|
|
||||||
// Checking for dump flag
|
// Checking for dump flag
|
||||||
|
@ -789,7 +786,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
// If dump flag is set, dump the config and exit
|
// If dump flag is set, dump the config and exit
|
||||||
if (dumpFlag) {
|
if (dumpFlag) {
|
||||||
dumpConfig(HDFattr, no_of_attr);
|
dumpConfig(HDFattrVector);
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,7 +803,8 @@ int main(int argc, char **argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Converting to array to maintain compatibility with older code and update
|
// Converting to array to maintain compatibility with older code
|
||||||
|
Config2HDFattr_t HDFattr[no_of_attr];
|
||||||
std::copy(HDFattrVector.begin(), HDFattrVector.end(), HDFattr);
|
std::copy(HDFattrVector.begin(), HDFattrVector.end(), HDFattr);
|
||||||
|
|
||||||
// Find devices
|
// Find devices
|
||||||
|
|
Loading…
Reference in a new issue