2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-03 09:41:50 +00:00

code review changes

This commit is contained in:
Alex
2024-02-09 11:39:51 -05:00
parent 42c4068d2a
commit 2478a1355f
11 changed files with 104 additions and 118 deletions

View File

@ -1,19 +1,19 @@
#include "Csv/ParsedCsv.h"
ParsedCsvRow::ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string>& row)
ParsedCsvRow::ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string> row)
: headers(headers),
values(row)
values(std::move(row))
{
}
const std::string ParsedCsvRow::GetValue(const std::string& header, bool required) const
std::string ParsedCsvRow::GetValue(const std::string& header, bool required) const
{
if (this->headers.find(header) == this->headers.end())
{
if (required)
std::cerr << "ERROR: Required column \"" << header << "\" was not found";
std::cerr << "ERROR: Required column \"" << header << "\" was not found" << std::endl;
else
std::cerr << "WARNING: Expected column \"" << header << "\" was not found";
std::cerr << "WARNING: Expected column \"" << header << "\" was not found" << std::endl;
return {};
}
@ -21,14 +21,14 @@ const std::string ParsedCsvRow::GetValue(const std::string& header, bool require
auto& value = this->values.at(this->headers[header]);
if (required && value.empty())
{
std::cerr << "ERROR: Required column \"" << header << "\" does not have a value";
std::cerr << "ERROR: Required column \"" << header << "\" does not have a value" << std::endl;
return {};
}
return value;
}
const float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) const
float ParsedCsvRow::GetValueFloat(const std::string& header, bool required) const
{
const auto& value = this->GetValue(header, required);
if (!value.empty())
@ -65,7 +65,7 @@ ParsedCsv::ParsedCsv(const CsvInputStream& inputStream, bool hasHeaders)
for (auto i = hasHeaders ? 1u : 0u; i < csvLines.size(); i++)
{
auto& rowValues = csvLines[i];
this->rows.push_back(ParsedCsvRow(this->headers, rowValues));
this->rows.emplace_back(this->headers, std::move(rowValues));
}
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <Csv/CsvStream.h>
#include <sstream>
#include <unordered_map>
#include "Csv/CsvStream.h"
class ParsedCsvRow
{
@ -9,9 +9,9 @@ class ParsedCsvRow
std::vector<std::string> values;
public:
explicit ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string>& row);
const std::string GetValue(const std::string& header, bool required = false) const;
const float GetValueFloat(const std::string& header, bool required = false) const;
explicit ParsedCsvRow(std::unordered_map<std::string, size_t>& headers, std::vector<std::string> row);
std::string GetValue(const std::string& header, bool required = false) const;
float GetValueFloat(const std::string& header, bool required = false) const;
template<typename T> T GetValueInt(const std::string& header, bool required = false) const
{