Skip to content

Commit

Permalink
Optimize metadata handling and improve code readability
Browse files Browse the repository at this point in the history
Added `#include <utility>` to `CziMetadataDocumentInfo.cpp` to enable `std::move`. Updated `CCziMetadataDocumentInfo` constructor to use `std::move` for `metadata` initialization, optimizing ownership transfer. Re-indented code blocks in `Utilities::Split` and `GetNode` lambda for better readability without changing logic.
  • Loading branch information
ptahmose committed Aug 31, 2024
1 parent 7f2971a commit fd37d01
Showing 1 changed file with 58 additions and 56 deletions.
114 changes: 58 additions & 56 deletions Src/libCZI/CziMetadataDocumentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "CziMetadataDocumentInfo.h"

#include <utility>
#include "CziDimensionInfo.h"
#include "CziDisplaySettings.h"
#include "utilities.h"
Expand All @@ -12,7 +14,7 @@ using namespace libCZI;
using namespace std;

CCziMetadataDocumentInfo::CCziMetadataDocumentInfo(std::shared_ptr<CCziMetadata> md)
: metadata(md)
: metadata(std::move(md))
{
this->ParseDimensionInfo();
}
Expand Down Expand Up @@ -327,33 +329,33 @@ CCziMetadataDocumentInfo::CCziMetadataDocumentInfo(std::shared_ptr<CCziMetadata>
[&](const std::wstring str)->bool
{
size_t charsParsed;
bool parsedOk = false;
double x;
try
{
x = std::stod(str, &charsParsed);
parsedOk = true;
}
catch (invalid_argument&)
{
}

if (parsedOk == true)
{
if (charsParsed < str.length() && !isspace(str[charsParsed]))
{
parsedOk = false;
}
}

// TODO: currently, we stop parsing at the first syntax error and return what we have so far without an
// external error - what is the desired behavior here?
if (parsedOk == true)
{
data.push_back(x);
}

return parsedOk;
bool parsedOk = false;
double x;
try
{
x = std::stod(str, &charsParsed);
parsedOk = true;
}
catch (invalid_argument&)
{
}

if (parsedOk == true)
{
if (charsParsed < str.length() && !isspace(str[charsParsed]))
{
parsedOk = false;
}
}

// TODO: currently, we stop parsing at the first syntax error and return what we have so far without an
// external error - what is the desired behavior here?
if (parsedOk == true)
{
data.push_back(x);
}

return parsedOk;
});

zinfo->SetListDefinition(std::move(data));
Expand Down Expand Up @@ -411,33 +413,33 @@ CCziMetadataDocumentInfo::CCziMetadataDocumentInfo(std::shared_ptr<CCziMetadata>
[&](const std::wstring str)->bool
{
size_t charsParsed;
bool parsedOk = false;
double x;
try
{
x = std::stod(str, &charsParsed);
parsedOk = true;
}
catch (invalid_argument&)
{
}

if (parsedOk == true)
{
if (charsParsed < str.length() && !isspace(str[charsParsed]))
{
parsedOk = false;
}
}

// TODO: currently, we stop parsing at the first syntax error and return what we have so far without an
// external error - what is the desired behavior here?
if (parsedOk == true)
{
data.push_back(x);
}

return parsedOk;
bool parsedOk = false;
double x;
try
{
x = std::stod(str, &charsParsed);
parsedOk = true;
}
catch (invalid_argument&)
{
}

if (parsedOk == true)
{
if (charsParsed < str.length() && !isspace(str[charsParsed]))
{
parsedOk = false;
}
}

// TODO: currently, we stop parsing at the first syntax error and return what we have so far without an
// external error - what is the desired behavior here?
if (parsedOk == true)
{
data.push_back(x);
}

return parsedOk;
});

tinfo->SetListDefinition(std::move(data));
Expand Down Expand Up @@ -527,7 +529,7 @@ pugi::xml_node CCziMetadataDocumentInfo::GetNode(const wchar_t* path) const
[&](const std::wstring str)->bool
{
node = node.child(str.c_str());
return !node.empty();
return !node.empty();
});

return node;
Expand Down

0 comments on commit fd37d01

Please sign in to comment.