/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2011 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ // mapnik #include #include #include #include #include #include // boost #include #include using boost::optional; using std::string; namespace mapnik { metawriter_ptr metawriter_create(xml_node const& pt) { metawriter_ptr writer; string type = pt.get_attr("type"); optional properties = pt.get_opt_attr("default-output"); if (type == "json") { string file = pt.get_attr("file"); metawriter_json_ptr json = boost::make_shared(properties, parse_path(file)); optional output_empty = pt.get_opt_attr("output-empty"); if (output_empty) { json->set_output_empty(*output_empty); } optional pixel_coordinates = pt.get_opt_attr("pixel-coordinates"); if (pixel_coordinates) { json->set_pixel_coordinates(*pixel_coordinates); } writer = json; } else if (type == "inmem") { metawriter_inmem_ptr inmem = boost::make_shared(properties); writer = inmem; } else { throw config_error(string("Unknown type '") + type + "'", pt); } return writer; } void metawriter_save(const metawriter_ptr &metawriter, boost::property_tree::ptree &metawriter_node, bool explicit_defaults) { metawriter_json *json = dynamic_cast(metawriter.get()); if (json) { set_attr(metawriter_node, "type", "json"); std::string const& filename = path_processor_type::to_string(*(json->get_filename())); if (!filename.empty() || explicit_defaults) { set_attr(metawriter_node, "file", filename); } } metawriter_inmem *inmem = dynamic_cast(metawriter.get()); if (inmem) { set_attr(metawriter_node, "type", "inmem"); } if (!metawriter->get_default_properties().empty() || explicit_defaults) { set_attr(metawriter_node, "default-output", metawriter->get_default_properties().to_string()); } } } // namespace mapnik