Skip to content

Commit

Permalink
merge mapnik-index::process_csv_file and csv_datasource::parse_csv
Browse files Browse the repository at this point in the history
- the function in plugin was already configurable via flags, and only
  contained two un-conditioned blocks that process_csv_file didn't have

- so I extracted the common parts into a separate function (in a class
  holding the flags and state), process_csv_file calls it with default
  flags, plugin sets them from params

- removed namespace ::detail, moving stuff that was used outside
  csv_utils to ::csv_utils, and the rest to ::csv_utils::detail
  • Loading branch information
lightmare committed Feb 26, 2016
1 parent aaffb1c commit c21778f
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 493 deletions.
344 changes: 64 additions & 280 deletions plugins/input/csv/csv_datasource.cpp

Large diffs are not rendered by default.

21 changes: 6 additions & 15 deletions plugins/input/csv/csv_datasource.hpp
Expand Up @@ -42,6 +42,7 @@
#pragma GCC diagnostic pop

// stl
#include <iosfwd>
#include <vector>
#include <string>

Expand All @@ -67,7 +68,8 @@ struct options_type<csv_linear<Max,Min> >
};
}}}}}

class csv_datasource : public mapnik::datasource
class csv_datasource : public mapnik::datasource,
private csv_utils::csv_file_parser
{
public:
using box_type = mapnik::box2d<double>;
Expand All @@ -84,26 +86,15 @@ class csv_datasource : public mapnik::datasource
mapnik::layer_descriptor get_descriptor() const;
boost::optional<mapnik::datasource_geometry_t> get_geometry_type() const;
private:
template <typename T>
void parse_csv(T & stream);
template <typename T>
boost::optional<mapnik::datasource_geometry_t> get_geometry_type_impl(T & stream) const;
void parse_csv(std::istream & );
virtual void add_feature(mapnik::value_integer index, mapnik::csv_line const & values);
boost::optional<mapnik::datasource_geometry_t> get_geometry_type_impl(std::istream & ) const;

mapnik::layer_descriptor desc_;
mapnik::box2d<double> extent_;
std::string filename_;
mapnik::value_integer row_limit_;
std::string inline_string_;
char separator_;
char quote_;
std::vector<std::string> headers_;
std::string manual_headers_;
bool strict_;
mapnik::context_ptr ctx_;
bool extent_initialized_;
std::unique_ptr<spatial_index_type> tree_;
detail::geometry_column_locator locator_;
bool has_disk_index_;
};

#endif // MAPNIK_CSV_DATASOURCE_HPP
6 changes: 3 additions & 3 deletions plugins/input/csv/csv_featureset.cpp
Expand Up @@ -31,7 +31,7 @@
#include <vector>
#include <deque>

csv_featureset::csv_featureset(std::string const& filename, detail::geometry_column_locator const& locator, char separator, char quote,
csv_featureset::csv_featureset(std::string const& filename, locator_type const& locator, char separator, char quote,
std::vector<std::string> const& headers, mapnik::context_ptr const& ctx, array_type && index_array)
:
#if defined(MAPNIK_MEMORY_MAPPED_FILE)
Expand Down Expand Up @@ -72,12 +72,12 @@ csv_featureset::~csv_featureset() {}
mapnik::feature_ptr csv_featureset::parse_feature(char const* beg, char const* end)
{
auto values = csv_utils::parse_line(beg, end, separator_, quote_, headers_.size());
auto geom = detail::extract_geometry(values, locator_);
auto geom = csv_utils::extract_geometry(values, locator_);
if (!geom.is<mapnik::geometry::geometry_empty>())
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_, ++feature_id_));
feature->set_geometry(std::move(geom));
detail::process_properties(*feature, headers_, values, locator_, tr_);
csv_utils::process_properties(*feature, headers_, values, locator_, tr_);
return feature;
}
return mapnik::feature_ptr();
Expand Down
4 changes: 2 additions & 2 deletions plugins/input/csv/csv_featureset.hpp
Expand Up @@ -40,7 +40,7 @@

class csv_featureset : public mapnik::Featureset
{
using locator_type = detail::geometry_column_locator;
using locator_type = csv_utils::geometry_column_locator;
public:
using array_type = std::deque<csv_datasource::item_type>;
csv_featureset(std::string const& filename,
Expand Down Expand Up @@ -69,7 +69,7 @@ class csv_featureset : public mapnik::Featureset
array_type::const_iterator index_end_;
mapnik::context_ptr ctx_;
mapnik::value_integer feature_id_ = 0;
detail::geometry_column_locator const& locator_;
locator_type const& locator_;
mapnik::transcoder tr_;
};

Expand Down
6 changes: 3 additions & 3 deletions plugins/input/csv/csv_index_featureset.cpp
Expand Up @@ -37,7 +37,7 @@

csv_index_featureset::csv_index_featureset(std::string const& filename,
mapnik::filter_in_box const& filter,
detail::geometry_column_locator const& locator,
locator_type const& locator,
char separator,
char quote,
std::vector<std::string> const& headers,
Expand Down Expand Up @@ -89,12 +89,12 @@ csv_index_featureset::~csv_index_featureset() {}
mapnik::feature_ptr csv_index_featureset::parse_feature(char const* beg, char const* end)
{
auto values = csv_utils::parse_line(beg, end, separator_, quote_, headers_.size());
auto geom = detail::extract_geometry(values, locator_);
auto geom = csv_utils::extract_geometry(values, locator_);
if (!geom.is<mapnik::geometry::geometry_empty>())
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_, ++feature_id_));
feature->set_geometry(std::move(geom));
detail::process_properties(*feature, headers_, values, locator_, tr_);
csv_utils::process_properties(*feature, headers_, values, locator_, tr_);
return feature;
}
return mapnik::feature_ptr();
Expand Down
4 changes: 2 additions & 2 deletions plugins/input/csv/csv_index_featureset.hpp
Expand Up @@ -41,7 +41,7 @@
class csv_index_featureset : public mapnik::Featureset
{
using value_type = std::pair<std::size_t, std::size_t>;
using locator_type = detail::geometry_column_locator;
using locator_type = csv_utils::geometry_column_locator;
public:

csv_index_featureset(std::string const& filename,
Expand All @@ -60,7 +60,7 @@ class csv_index_featureset : public mapnik::Featureset
std::vector<std::string> headers_;
mapnik::context_ptr ctx_;
mapnik::value_integer feature_id_ = 0;
detail::geometry_column_locator const& locator_;
locator_type const& locator_;
mapnik::transcoder tr_;
#if defined (MAPNIK_MEMORY_MAPPED_FILE)
using file_source_type = boost::interprocess::ibufferstream;
Expand Down
6 changes: 3 additions & 3 deletions plugins/input/csv/csv_inline_featureset.cpp
Expand Up @@ -33,7 +33,7 @@
#include <deque>

csv_inline_featureset::csv_inline_featureset(std::string const& inline_string,
detail::geometry_column_locator const& locator,
locator_type const& locator,
char separator,
char quote,
std::vector<std::string> const& headers,
Expand All @@ -57,12 +57,12 @@ mapnik::feature_ptr csv_inline_featureset::parse_feature(std::string const& str)
auto const* start = str.data();
auto const* end = start + str.size();
auto values = csv_utils::parse_line(start, end, separator_, quote_, headers_.size());
auto geom = detail::extract_geometry(values, locator_);
auto geom = csv_utils::extract_geometry(values, locator_);
if (!geom.is<mapnik::geometry::geometry_empty>())
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_, ++feature_id_));
feature->set_geometry(std::move(geom));
detail::process_properties(*feature, headers_, values, locator_, tr_);
csv_utils::process_properties(*feature, headers_, values, locator_, tr_);
return feature;
}
return mapnik::feature_ptr();
Expand Down
4 changes: 2 additions & 2 deletions plugins/input/csv/csv_inline_featureset.hpp
Expand Up @@ -31,7 +31,7 @@

class csv_inline_featureset : public mapnik::Featureset
{
using locator_type = detail::geometry_column_locator;
using locator_type = csv_utils::geometry_column_locator;
public:
using array_type = std::deque<csv_datasource::item_type>;
csv_inline_featureset(std::string const& inline_string,
Expand All @@ -54,7 +54,7 @@ class csv_inline_featureset : public mapnik::Featureset
array_type::const_iterator index_end_;
mapnik::context_ptr ctx_;
mapnik::value_integer feature_id_ = 0;
detail::geometry_column_locator const& locator_;
locator_type const& locator_;
mapnik::transcoder tr_;
};

Expand Down

0 comments on commit c21778f

Please sign in to comment.