From e94667a8ae866f0ff41518c8ff05edd5738b96e4 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 24 Jun 2011 00:53:00 +0000 Subject: [PATCH] use std::string --- src/datasource_cache.cpp | 13 +++-- src/image_util.cpp | 2 +- src/layer.cpp | 6 +- src/load_map.cpp | 120 +++++++++++++++++++-------------------- 4 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/datasource_cache.cpp b/src/datasource_cache.cpp index 37e1cb3de..ae27ec4a9 100644 --- a/src/datasource_cache.cpp +++ b/src/datasource_cache.cpp @@ -37,6 +37,7 @@ // stl #include +#include #include namespace mapnik @@ -58,7 +59,7 @@ datasource_cache::~datasource_cache() lt_dlexit(); } -std::map > datasource_cache::plugins_; +std::map > datasource_cache::plugins_; bool datasource_cache::registered_=false; std::vector datasource_cache::plugin_directories_; @@ -67,20 +68,20 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind) boost::optional type = params.get("type"); if ( ! type) { - throw config_error(string("Could not create datasource. Required ") + + throw config_error(std::string("Could not create datasource. Required ") + "parameter 'type' is missing"); } datasource_ptr ds; - std::map >::iterator itr=plugins_.find(*type); + std::map >::iterator itr=plugins_.find(*type); if ( itr == plugins_.end() ) { - throw config_error(string("Could not create datasource. No plugin ") + + throw config_error(std::string("Could not create datasource. No plugin ") + "found for type '" + * type + "' (searched in: " + plugin_directories() + ")"); } if ( ! itr->second->handle()) { - throw std::runtime_error(string("Cannot load library: ") + + throw std::runtime_error(std::string("Cannot load library: ") + lt_dlerror()); } // http://www.mr-edd.co.uk/blog/supressing_gcc_warnings @@ -92,7 +93,7 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind) if ( ! create_datasource) { - throw std::runtime_error(string("Cannot load symbols: ") + + throw std::runtime_error(std::string("Cannot load symbols: ") + lt_dlerror()); } #ifdef MAPNIK_DEBUG diff --git a/src/image_util.cpp b/src/image_util.cpp index 413703ce4..d0359c7b8 100644 --- a/src/image_util.cpp +++ b/src/image_util.cpp @@ -116,7 +116,7 @@ void save_to_stream(T const& image, if (type.length() > 6){ boost::char_separator sep(":"); boost::tokenizer< boost::char_separator > tokens(type, sep); - BOOST_FOREACH(string t, tokens) + BOOST_FOREACH(std::string t, tokens) { if (t == "m=h") { diff --git a/src/layer.cpp b/src/layer.cpp index ddfff4459..ba40a85f6 100644 --- a/src/layer.cpp +++ b/src/layer.cpp @@ -97,7 +97,7 @@ void layer::set_name( std::string const& name) name_ = name; } -string const& layer::name() const +std::string const& layer::name() const { return name_; } @@ -107,7 +107,7 @@ void layer::set_title( std::string const& title) title_ = title; } -string const& layer::title() const +std::string const& layer::title() const { return title_; } @@ -117,7 +117,7 @@ void layer::set_abstract( std::string const& abstract) abstract_ = abstract; } -string const& layer::abstract() const +std::string const& layer::abstract() const { return abstract_; } diff --git a/src/load_map.cpp b/src/load_map.cpp index 748b8d0f5..daf89f2da 100644 --- a/src/load_map.cpp +++ b/src/load_map.cpp @@ -229,7 +229,7 @@ void map_parser::parse_map( Map & map, ptree const & pt, std::string const& base map.set_background( * bgcolor ); } - optional image_filename = get_opt_attr(map_node, "background-image"); + optional image_filename = get_opt_attr(map_node, "background-image"); if (image_filename) { map.set_background_image(ensure_relative_to_xml(image_filename)); @@ -356,13 +356,13 @@ void map_parser::parse_map_include( Map & map, ptree const & include ) } else if (v.first == "FileSource") { - std::string name = get_attr( v.second, "name"); - std::string value = get_value( v.second, ""); + std::string name = get_attr( v.second, "name"); + std::string value = get_value( v.second, ""); file_sources_[name] = value; } else if (v.first == "Datasource") { - std::string name = get_attr(v.second, "name", string("Unnamed")); + std::string name = get_attr(v.second, "name", std::string("Unnamed")); parameters params; ptree::const_iterator paramIter = v.second.begin(); ptree::const_iterator endParam = v.second.end(); @@ -372,8 +372,8 @@ void map_parser::parse_map_include( Map & map, ptree const & include ) if (paramIter->first == "Parameter") { - std::string name = get_attr(param, "name"); - std::string value = get_value( param, + std::string name = get_attr(param, "name"); + std::string value = get_value( param, "datasource parameter"); params[name] = value; } @@ -406,10 +406,10 @@ void map_parser::parse_style( Map & map, ptree const & sty ) << "filter-mode"; ensure_attrs(sty, "Style", s.str()); - string name(""); + std::string name(""); try { - name = get_attr(sty, "name"); + name = get_attr(sty, "name"); feature_type_style style; filter_mode_e filter_mode = get_attr(sty, "filter-mode", FILTER_ALL); @@ -437,9 +437,9 @@ void map_parser::parse_style( Map & map, ptree const & sty ) } catch (const config_error & ex) { if ( ! name.empty() ) { - ex.append_context(string("in style '") + name + "'"); + ex.append_context(std::string("in style '") + name + "'"); } - ex.append_context(string("in map '") + filename_ + "'"); + ex.append_context(std::string("in map '") + filename_ + "'"); throw; } } @@ -447,19 +447,19 @@ void map_parser::parse_style( Map & map, ptree const & sty ) void map_parser::parse_metawriter(Map & map, ptree const & pt) { ensure_attrs(pt, "MetaWriter", "name,type,file,default-output,output-empty"); - string name(""); + std::string name(""); metawriter_ptr writer; try { - name = get_attr(pt, "name"); + name = get_attr(pt, "name"); writer = metawriter_create(pt); map.insert_metawriter(name, writer); } catch (const config_error & ex) { if (!name.empty()) { - ex.append_context(string("in meta writer '") + name + "'"); + ex.append_context(std::string("in meta writer '") + name + "'"); } - ex.append_context(string("in map '") + filename_ + "'"); + ex.append_context(std::string("in map '") + filename_ + "'"); throw; } } @@ -467,10 +467,10 @@ void map_parser::parse_metawriter(Map & map, ptree const & pt) void map_parser::parse_fontset( Map & map, ptree const & fset ) { ensure_attrs(fset, "FontSet", "name,Font"); - string name(""); + std::string name(""); try { - name = get_attr(fset, "name"); + name = get_attr(fset, "name"); font_set fontset(name); ptree::const_iterator itr = fset.begin(); @@ -499,9 +499,9 @@ void map_parser::parse_fontset( Map & map, ptree const & fset ) fontsets_.insert(pair(name, fontset)); } catch (const config_error & ex) { if ( ! name.empty() ) { - ex.append_context(string("in FontSet '") + name + "'"); + ex.append_context(std::string("in FontSet '") + name + "'"); } - ex.append_context(string("in map '") + filename_ + "'"); + ex.append_context(std::string("in map '") + filename_ + "'"); throw; } } @@ -510,7 +510,7 @@ void map_parser::parse_font(font_set & fset, ptree const & f) { ensure_attrs(f, "Font", "face-name"); - std::string face_name = get_attr(f, "face-name", string()); + std::string face_name = get_attr(f, "face-name", std::string()); if ( strict_ ) { @@ -536,7 +536,7 @@ void map_parser::parse_layer( Map & map, ptree const & lay ) ensure_attrs(lay, "Layer", s.str()); try { - name = get_attr(lay, "name", string("Unnamed")); + name = get_attr(lay, "name", std::string("Unnamed")); // XXX if no projection is given inherit from map? [DS] std::string srs = get_attr(lay, "srs", map.srs()); @@ -549,13 +549,13 @@ void map_parser::parse_layer( Map & map, ptree const & lay ) lyr.setActive( * status ); } - optional title = get_opt_attr(lay, "title"); + optional title = get_opt_attr(lay, "title"); if (title) { lyr.set_title( * title ); } - optional abstract = get_opt_attr(lay, "abstract"); + optional abstract = get_opt_attr(lay, "abstract"); if (abstract) { lyr.set_abstract( * abstract ); @@ -640,8 +640,8 @@ void map_parser::parse_layer( Map & map, ptree const & lay ) if (paramIter->first == "Parameter") { ensure_attrs(param, "Parameter", "name"); - std::string name = get_attr(param, "name"); - std::string value = get_value( param, + std::string name = get_attr(param, "name"); + std::string value = get_value( param, "datasource parameter"); params[name] = value; } @@ -718,13 +718,13 @@ void map_parser::parse_rule( feature_type_style & style, ptree const & r ) std::string name; try { - name = get_attr( r, "name", string()); - std::string title = get_attr( r, "title", string()); + name = get_attr( r, "name", std::string()); + std::string title = get_attr( r, "title", std::string()); rule rule(name,title); optional filter_expr = - get_opt_child( r, "Filter"); + get_opt_child( r, "Filter"); if (filter_expr) { // TODO - can we use encoding defined for XML document for filter expressions? @@ -732,7 +732,7 @@ void map_parser::parse_rule( feature_type_style & style, ptree const & r ) } optional else_filter = - get_opt_child(r, "ElseFilter"); + get_opt_child(r, "ElseFilter"); if (else_filter) { rule.set_else(true); @@ -823,7 +823,7 @@ void map_parser::parse_rule( feature_type_style & style, ptree const & r ) { if ( ! name.empty() ) { - ex.append_context(string("in rule '") + name + "' in map '" + filename_ + "')"); + ex.append_context(std::string("in rule '") + name + "' in map '" + filename_ + "')"); } throw; } @@ -831,9 +831,9 @@ void map_parser::parse_rule( feature_type_style & style, ptree const & r ) void map_parser::parse_metawriter_in_symbolizer(symbolizer_base &sym, ptree const &pt) { - optional writer = get_opt_attr(pt, "meta-writer"); + optional writer = get_opt_attr(pt, "meta-writer"); if (!writer) return; - optional output = get_opt_attr(pt, "meta-output"); + optional output = get_opt_attr(pt, "meta-output"); sym.add_metawriter(*writer, output); } @@ -844,8 +844,8 @@ void map_parser::parse_point_symbolizer( rule & rule, ptree const & sym ) std::stringstream s; s << "file,base,allow-overlap,ignore-placement,opacity,placement,transform,meta-writer,meta-output"; - optional file = get_opt_attr(sym, "file"); - optional base = get_opt_attr(sym, "base"); + optional file = get_opt_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); optional allow_overlap = get_opt_attr(sym, "allow-overlap"); optional ignore_placement = @@ -853,7 +853,7 @@ void map_parser::parse_point_symbolizer( rule & rule, ptree const & sym ) optional opacity = get_opt_attr(sym, "opacity"); - optional transform_wkt = get_opt_attr(sym, "transform"); + optional transform_wkt = get_opt_attr(sym, "transform"); if (file) { @@ -900,7 +900,7 @@ void map_parser::parse_point_symbolizer( rule & rule, ptree const & sym ) if (strict_) throw config_error(ss.str()); // value_error here? else - clog << "### WARNING: " << ss << endl; + std::clog << "### WARNING: " << ss << endl; } boost::array matrix; tr.store_to(&matrix[0]); @@ -912,7 +912,7 @@ void map_parser::parse_point_symbolizer( rule & rule, ptree const & sym ) } catch (image_reader_exception const & ex ) { - string msg("Failed to load image file '" + * file + + std::string msg("Failed to load image file '" + * file + "': " + ex.what()); if (strict_) { @@ -920,7 +920,7 @@ void map_parser::parse_point_symbolizer( rule & rule, ptree const & sym ) } else { - clog << "### WARNING: " << msg << endl; + std::clog << "### WARNING: " << msg << endl; } } @@ -963,9 +963,9 @@ void map_parser::parse_markers_symbolizer( rule & rule, ptree const & sym ) try { std::string filename(""); - optional file = get_opt_attr(sym, "file"); - optional base = get_opt_attr(sym, "base"); - optional transform_wkt = get_opt_attr(sym, "transform"); + optional file = get_opt_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); + optional transform_wkt = get_opt_attr(sym, "transform"); std::stringstream s; //s << "file,opacity,spacing,max-error,allow-overlap,placement,"; @@ -997,14 +997,14 @@ void map_parser::parse_markers_symbolizer( rule & rule, ptree const & sym ) } catch (...) { - string msg("Failed to load marker file '" + *file + "'!"); + std::string msg("Failed to load marker file '" + *file + "'!"); if (strict_) { throw config_error(msg); } else { - clog << "### WARNING: " << msg << endl; + std::clog << "### WARNING: " << msg << endl; } } } @@ -1029,7 +1029,7 @@ void map_parser::parse_markers_symbolizer( rule & rule, ptree const & sym ) if (strict_) throw config_error(ss.str()); // value_error here? else - clog << "### WARNING: " << ss << endl; + std::clog << "### WARNING: " << ss << endl; } boost::array matrix; tr.store_to(&matrix[0]); @@ -1094,8 +1094,8 @@ void map_parser::parse_line_pattern_symbolizer( rule & rule, ptree const & sym ) ensure_attrs(sym, "LinePatternSymbolizer", "file,base,meta-writer,meta-output"); try { - std::string file = get_attr(sym, "file"); - optional base = get_opt_attr(sym, "base"); + std::string file = get_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); try { @@ -1117,7 +1117,7 @@ void map_parser::parse_line_pattern_symbolizer( rule & rule, ptree const & sym ) } catch (image_reader_exception const & ex ) { - string msg("Failed to load image file '" + file + + std::string msg("Failed to load image file '" + file + "': " + ex.what()); if (strict_) { @@ -1125,7 +1125,7 @@ void map_parser::parse_line_pattern_symbolizer( rule & rule, ptree const & sym ) } else { - clog << "### WARNING: " << msg << endl; + std::clog << "### WARNING: " << msg << endl; } } } @@ -1142,8 +1142,8 @@ void map_parser::parse_polygon_pattern_symbolizer( rule & rule, ensure_attrs(sym, "PolygonPatternSymbolizer", "file,base,alignment,meta-writer,meta-output"); try { - std::string file = get_attr(sym, "file"); - optional base = get_opt_attr(sym, "base"); + std::string file = get_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); try { @@ -1169,7 +1169,7 @@ void map_parser::parse_polygon_pattern_symbolizer( rule & rule, } catch (image_reader_exception const & ex ) { - string msg("Failed to load image file '" + file + + std::string msg("Failed to load image file '" + file + "': " + ex.what()); if (strict_) { @@ -1177,7 +1177,7 @@ void map_parser::parse_polygon_pattern_symbolizer( rule & rule, } else { - clog << "### WARNING: " << msg << endl; + std::clog << "### WARNING: " << msg << endl; } } } @@ -1220,7 +1220,7 @@ void map_parser::parse_text_symbolizer( rule & rule, ptree const & sym ) placement_finder = text_placements_ptr(new text_placements_dummy()); } - std::string name = get_attr(sym, "name"); + std::string name = get_attr(sym, "name"); optional face_name = get_opt_attr(sym, "face-name"); @@ -1445,7 +1445,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym ) ensure_attrs(sym, "ShieldSymbolizer", s.str()); try { - std::string name = get_attr(sym, "name"); + std::string name = get_attr(sym, "name"); optional face_name = get_opt_attr(sym, "face-name"); @@ -1456,10 +1456,10 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym ) unsigned size = get_attr(sym, "size", 10U); color fill = get_attr(sym, "fill", color(0,0,0)); - std::string image_file = get_attr(sym, "file"); - optional base = get_opt_attr(sym, "base"); + std::string image_file = get_attr(sym, "file"); + optional base = get_opt_attr(sym, "base"); - optional transform_wkt = get_opt_attr(sym, "transform"); + optional transform_wkt = get_opt_attr(sym, "transform"); try { if( base ) @@ -1645,7 +1645,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym ) if (strict_) throw config_error(ss.str()); // value_error here? else - clog << "### WARNING: " << ss << endl; + std::clog << "### WARNING: " << ss << endl; } boost::array matrix; tr.store_to(&matrix[0]); @@ -1673,7 +1673,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym ) } catch (image_reader_exception const & ex ) { - string msg("Failed to load image file '" + image_file + + std::string msg("Failed to load image file '" + image_file + "': " + ex.what()); if (strict_) { @@ -1681,7 +1681,7 @@ void map_parser::parse_shield_symbolizer( rule & rule, ptree const & sym ) } else { - clog << "### WARNING: " << msg << endl; + std::clog << "### WARNING: " << msg << endl; } } @@ -1724,7 +1724,7 @@ void map_parser::parse_stroke(stroke & strk, ptree const & sym) if (dash_offset) strk.set_dash_offset(*dash_offset); // stroke-dasharray - optional str = get_opt_attr(sym,"stroke-dasharray"); + optional str = get_opt_attr(sym,"stroke-dasharray"); if (str) { tokenizer<> tok (*str);