Skip to content

Commit

Permalink
Simplify assignment of headers/query a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 27, 2020
1 parent 1f72e5f commit a9b139c
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions io/EptReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <pdal/Polygon.hpp>
#include <pdal/SrsBounds.hpp>
#include <pdal/pdal_features.hpp>
#include <nlohmann/json.hpp>

#include "private/ept/Connector.hpp"
#include "private/ept/EptArtifact.hpp"
Expand Down Expand Up @@ -141,45 +142,25 @@ void EptReader::addArgs(ProgramArgs& args)
m_args->m_ogr);
}

namespace
{

// Extract a string map from JSON. Used in setForwards().
StringMap toStringMap(const NL::json& fwd)
{
StringMap map;

if (fwd.is_null())
return map;
if (!fwd.is_object())
throw pdal_error("Not an object type.");
for (auto& entry : fwd.items())
{
if (!entry.value().is_string())
throw pdal_error("Expected string type.");
map.insert({entry.key(), entry.value().get<std::string>()});
}
return map;
}

}

void EptReader::setForwards(StringMap& headers, StringMap& query)
{
try
{
headers = toStringMap(m_args->m_headers);
if (!m_args->m_headers.is_null())
headers = m_args->m_headers.get<StringMap>();
}
catch (const pdal_error& err)
catch (const std::exception& err)
{
throwError(std::string("Error parsing 'headers': ") + err.what());
}

try
{
query = toStringMap(m_args->m_query);
if (!m_args->m_query.is_null())
query = m_args->m_query.get<StringMap>();
}
catch (const pdal_error& err)
catch (const std::exception& err)
{
throwError(std::string("Error parsing 'query': ") + err.what());
}
Expand Down

0 comments on commit a9b139c

Please sign in to comment.