Skip to content

Commit

Permalink
Merge pull request #80 from ami-iit/fix_struct_creation
Browse files Browse the repository at this point in the history
Fix struct creation
  • Loading branch information
S-Dafarra authored May 14, 2024
2 parents 1d40080 + 136419e commit 842ba12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ example/build/*
# Qtcreator
*.user*
*.autosave

# Visual studio
.vs/*
.vscode/*
CMakeSettings.json
13 changes: 8 additions & 5 deletions src/Struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ matioCpp::Struct::Struct(const std::string &name)
matioCpp::Struct::Struct(const std::string &name, const std::vector<Variable> &elements)
{
size_t emptyDimensions[] = {1, 1};
std::vector<matvar_t*> vectorOfPointers(elements.size() + 1, nullptr); //The vector of pointers has to be null terminated
std::vector<matvar_t*> vectorOfPointers;
for (size_t i = 0; i < elements.size(); ++i)
{
if (!elements[i].isValid())
if (elements[i].isValid())
{
std::cerr << "[ERROR][matioCpp::Struct::Struct] The element at index "<< i << " (0-based) is not valid." << std::endl;
assert(false);
vectorOfPointers.push_back(matioCpp::MatvarHandler::GetMatvarDuplicate(elements[i].toMatio()));
}
else
{
std::cerr << "[ERROR][matioCpp::Struct::Struct] The element of " << name << " at index " << i << " (0-based) is not valid. It will be skipped." << std::endl;
}
vectorOfPointers[i] = matioCpp::MatvarHandler::GetMatvarDuplicate(elements[i].toMatio());
}
vectorOfPointers.push_back(nullptr); //The vector of pointers has to be null terminated

initializeVariable(name,
VariableType::Struct,
Expand Down

0 comments on commit 842ba12

Please sign in to comment.