Changed template parameter type from stream to iterator and added a specialization for std::ostream_iterator.
This commit is contained in:
parent
26e4fedfde
commit
b5b94a868c
16 changed files with 72 additions and 109 deletions
|
@ -33,15 +33,16 @@
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik
|
||||||
{
|
{
|
||||||
// parameterized with the type of ostream it will use for output.
|
// parameterized with the type of output iterator it will use for output.
|
||||||
|
// output iterators add more flexibility than streams, because iterators
|
||||||
|
// can target many other output destinations besides streams.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class MAPNIK_DECL svg_renderer : public feature_style_processor<svg_renderer<T> >,
|
class MAPNIK_DECL svg_renderer : public feature_style_processor<svg_renderer<T> >,
|
||||||
private boost::noncopyable
|
private boost::noncopyable
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// the only parameter I'm sure of is the map.
|
svg_renderer(Map const& m, T& output_iterator);
|
||||||
svg_renderer(Map const& m, T& output_stream);
|
|
||||||
~svg_renderer();
|
~svg_renderer();
|
||||||
|
|
||||||
void start_map_processing(Map const& map);
|
void start_map_processing(Map const& map);
|
||||||
|
@ -83,15 +84,15 @@ namespace mapnik
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
// should this function be inline?
|
// should this function be inline?
|
||||||
inline T& get_output_stream()
|
inline T& get_output_iterator()
|
||||||
{
|
{
|
||||||
return output_stream_;
|
return output_iterator_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// should this function be inline?
|
// should this function be inline?
|
||||||
inline const T& get_output_stream() const
|
inline const T& get_output_iterator() const
|
||||||
{
|
{
|
||||||
return output_stream_;
|
return output_iterator_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// XML declaration.
|
// XML declaration.
|
||||||
|
@ -104,7 +105,7 @@ namespace mapnik
|
||||||
static const std::string SVG_NAMESPACE_URL;
|
static const std::string SVG_NAMESPACE_URL;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T& output_stream_;
|
T& output_iterator_;
|
||||||
const int width_;
|
const int width_;
|
||||||
const int height_;
|
const int height_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,17 +28,13 @@ namespace mapnik
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void svg_renderer<T>::process(building_symbolizer const& sym,
|
void svg_renderer<T>::process(building_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
{
|
{
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(building_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(building_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(building_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,17 +28,13 @@ namespace mapnik
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void svg_renderer<T>::process(glyph_symbolizer const& sym,
|
void svg_renderer<T>::process(glyph_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
{
|
{
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(glyph_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(glyph_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(glyph_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(line_pattern_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(line_pattern_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(line_pattern_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(line_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(line_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(line_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(markers_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(markers_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(markers_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(point_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(point_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(point_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(polygon_pattern_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(polygon_pattern_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(polygon_pattern_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(polygon_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(polygon_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(polygon_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(raster_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(raster_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(raster_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(shield_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(shield_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(shield_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,7 @@ namespace mapnik
|
||||||
// nothing yet.
|
// nothing yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
template void svg_renderer<std::ostringstream>::process(text_symbolizer const& sym,
|
template void svg_renderer<std::ostream_iterator<char> >::process(text_symbolizer const& sym,
|
||||||
Feature const& feature,
|
Feature const& feature,
|
||||||
proj_transform const& prj_trans);
|
proj_transform const& prj_trans);
|
||||||
|
|
||||||
template void svg_renderer<std::ofstream>::process(text_symbolizer const& sym,
|
|
||||||
Feature const& feature,
|
|
||||||
proj_transform const& prj_trans);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#endif
|
#endif
|
||||||
#include <sstream>
|
#include <ostream>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
// boost
|
// boost
|
||||||
#include <boost/fusion/tuple.hpp>
|
#include <boost/fusion/tuple.hpp>
|
||||||
|
@ -64,9 +63,9 @@ namespace mapnik
|
||||||
const std::string svg_renderer<T>::SVG_NAMESPACE_URL = "http://www.w3.org/2000/svg";
|
const std::string svg_renderer<T>::SVG_NAMESPACE_URL = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
svg_renderer<T>::svg_renderer(Map const& m, T & output_stream) :
|
svg_renderer<T>::svg_renderer(Map const& m, T & output_iterator) :
|
||||||
feature_style_processor<svg_renderer>(m),
|
feature_style_processor<svg_renderer>(m),
|
||||||
output_stream_(output_stream),
|
output_iterator_(output_iterator),
|
||||||
width_(m.width()),
|
width_(m.width()),
|
||||||
height_(m.height())
|
height_(m.height())
|
||||||
{
|
{
|
||||||
|
@ -91,11 +90,9 @@ namespace mapnik
|
||||||
using repository::confix;
|
using repository::confix;
|
||||||
using fusion::tuple;
|
using fusion::tuple;
|
||||||
|
|
||||||
std::ostream_iterator<char> output_stream_iterator(output_stream_);
|
|
||||||
|
|
||||||
// generate XML header.
|
// generate XML header.
|
||||||
generate(
|
generate(
|
||||||
output_stream_iterator,
|
output_iterator_,
|
||||||
string << eol << string << eol,
|
string << eol << string << eol,
|
||||||
XML_DECLARATION, SVG_DTD);
|
XML_DECLARATION, SVG_DTD);
|
||||||
|
|
||||||
|
@ -104,7 +101,7 @@ namespace mapnik
|
||||||
// which is taken from the map's dimensions.
|
// which is taken from the map's dimensions.
|
||||||
|
|
||||||
generate(
|
generate(
|
||||||
output_stream_iterator,
|
output_iterator_,
|
||||||
confix("<", ">")[
|
confix("<", ">")[
|
||||||
"svg width=" << confix('"', '"')[int_ << string]
|
"svg width=" << confix('"', '"')[int_ << string]
|
||||||
<< " height=" << confix('"', '"')[int_ << string]
|
<< " height=" << confix('"', '"')[int_ << string]
|
||||||
|
@ -118,13 +115,14 @@ namespace mapnik
|
||||||
{
|
{
|
||||||
// generate background color as a rectangle that spans the whole image.
|
// generate background color as a rectangle that spans the whole image.
|
||||||
generate(
|
generate(
|
||||||
output_stream_iterator,
|
output_iterator_,
|
||||||
confix("<", "/>")[
|
confix("<", "/>")[
|
||||||
"rect x=" << confix('"', '"')[int_]
|
"rect x=" << confix('"', '"')[int_]
|
||||||
<< " y=" << confix('"', '"')[int_]
|
<< " y=" << confix('"', '"')[int_]
|
||||||
<< " width=" << confix('"', '"')[int_ << string]
|
<< " width=" << confix('"', '"')[int_ << string]
|
||||||
<< " height=" << confix('"', '"')[int_ << string]
|
<< " height=" << confix('"', '"')[int_ << string]
|
||||||
<< " style=" << confix('"', '"')["fill: " << string]],
|
<< " style=" << confix('"', '"')["fill: " << string]]
|
||||||
|
<< eol,
|
||||||
0, 0, tuple<int, std::string>(width_, "px"), tuple<int, std::string>(height_, "px"), bgcolor->to_hex_string());
|
0, 0, tuple<int, std::string>(width_, "px"), tuple<int, std::string>(height_, "px"), bgcolor->to_hex_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,11 +130,13 @@ namespace mapnik
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void svg_renderer<T>::end_map_processing(Map const& map)
|
void svg_renderer<T>::end_map_processing(Map const& map)
|
||||||
{
|
{
|
||||||
using karma::format;
|
using karma::generate;
|
||||||
using karma::lit;
|
using karma::lit;
|
||||||
|
|
||||||
// generate SVG root element closing tag.
|
// generate SVG root element closing tag.
|
||||||
output_stream_ << format(lit("\n</svg>"));
|
generate(
|
||||||
|
output_iterator_,
|
||||||
|
lit("</svg>"));
|
||||||
|
|
||||||
#ifdef MAPNIK_DEBUG
|
#ifdef MAPNIK_DEBUG
|
||||||
std::clog << "end map processing" << std::endl;
|
std::clog << "end map processing" << std::endl;
|
||||||
|
@ -163,6 +163,5 @@ namespace mapnik
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template class svg_renderer<std::ostringstream>;
|
template class svg_renderer<std::ostream_iterator<char> >;
|
||||||
template class svg_renderer<std::ofstream>;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
// std
|
// std
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test case tests all the generators inside svg_renderer,
|
* This test case tests all the generators inside svg_renderer,
|
||||||
|
@ -26,13 +27,14 @@
|
||||||
BOOST_AUTO_TEST_CASE(combined_test_case)
|
BOOST_AUTO_TEST_CASE(combined_test_case)
|
||||||
{
|
{
|
||||||
using namespace mapnik;
|
using namespace mapnik;
|
||||||
typedef svg_renderer<std::ostringstream> svg_ren;
|
typedef svg_renderer<std::ostream_iterator<char> > svg_ren;
|
||||||
|
|
||||||
Map map(800, 600);
|
Map map(800, 600);
|
||||||
map.set_background(color_factory::from_string("white"));
|
map.set_background(color_factory::from_string("white"));
|
||||||
|
|
||||||
std::ostringstream output_stream;
|
std::ostringstream output_stream;
|
||||||
svg_ren renderer(map, output_stream);
|
std::ostream_iterator<char> output_stream_iterator(output_stream);
|
||||||
|
svg_ren renderer(map, output_stream_iterator);
|
||||||
renderer.apply();
|
renderer.apply();
|
||||||
|
|
||||||
std::string expected_output =
|
std::string expected_output =
|
||||||
|
@ -48,7 +50,7 @@ BOOST_AUTO_TEST_CASE(combined_test_case)
|
||||||
+"\n"
|
+"\n"
|
||||||
+"</svg>";
|
+"</svg>";
|
||||||
|
|
||||||
std::string actual_output = renderer.get_output_stream().str();
|
std::string actual_output = output_stream.str();
|
||||||
BOOST_CHECK_EQUAL(actual_output, expected_output);
|
BOOST_CHECK_EQUAL(actual_output, expected_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
// std
|
// std
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test is meant to see if the empty
|
* This test is meant to see if the empty
|
||||||
|
@ -24,7 +25,8 @@ BOOST_AUTO_TEST_CASE(compile_test_case)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::ostringstream output_stream;
|
std::ostringstream output_stream;
|
||||||
svg_renderer<std::ostringstream> renderer(map, output_stream);
|
std::ostream_iterator<char> output_stream_iterator(output_stream);
|
||||||
|
svg_renderer<std::ostream_iterator<char> > renderer(map, output_stream_iterator);
|
||||||
renderer.apply();
|
renderer.apply();
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
namespace filesystem = boost::filesystem;
|
namespace filesystem = boost::filesystem;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ namespace filesystem = boost::filesystem;
|
||||||
BOOST_AUTO_TEST_CASE(file_output_test_case)
|
BOOST_AUTO_TEST_CASE(file_output_test_case)
|
||||||
{
|
{
|
||||||
using namespace mapnik;
|
using namespace mapnik;
|
||||||
typedef svg_renderer<std::ofstream> svg_ren;
|
typedef svg_renderer<std::ostream_iterator<char> > svg_ren;
|
||||||
|
|
||||||
Map map(800, 600);
|
Map map(800, 600);
|
||||||
map.set_background(color_factory::from_string("blue"));
|
map.set_background(color_factory::from_string("blue"));
|
||||||
|
@ -49,7 +50,9 @@ BOOST_AUTO_TEST_CASE(file_output_test_case)
|
||||||
|
|
||||||
if(output_stream)
|
if(output_stream)
|
||||||
{
|
{
|
||||||
svg_ren renderer(map, output_stream);
|
std::ostream_iterator<char> output_stream_iterator(output_stream);
|
||||||
|
|
||||||
|
svg_ren renderer(map, output_stream_iterator);
|
||||||
renderer.apply();
|
renderer.apply();
|
||||||
|
|
||||||
output_stream.close();
|
output_stream.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue