Skip to content

Commit

Permalink
pass by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Sep 24, 2010
1 parent 9b33d6d commit 7ee1114
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 85 deletions.
11 changes: 5 additions & 6 deletions src/map_utils.hpp
Expand Up @@ -28,10 +28,10 @@ namespace http {
namespace map_utils {


inline boost::optional<box2d<double> > parse_bbox_from_string(const std::string& bbox_string)
inline bool parse_bbox_from_string(Envelope<double>& box, const std::string& bbox_string)
{

boost::optional<Envelope<double> > result;

boost::char_separator<char> sep(",");
boost::tokenizer<boost::char_separator<char> > tok(bbox_string,sep);
unsigned i = 0;
Expand Down Expand Up @@ -59,12 +59,11 @@ inline boost::optional<box2d<double> > parse_bbox_from_string(const std::string&

if (success)
{
Envelope<double> bbox(d[0],d[1],d[2],d[3]);
result.reset(bbox);
return result;
box.init(d[0],d[1],d[2],d[3]);
return true;
}

return result;
return false;
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/posix_main.cpp
Expand Up @@ -91,7 +91,7 @@ int main(int argc, char* argv[])

// custom max_extent_string and max_extent
optional<std::string> max_extent_string;
optional<box2d<double> > max_extent;
box2d<double> max_extent;

// font list we register
std::vector<std::string> face_names;
Expand Down Expand Up @@ -280,8 +280,8 @@ int main(int argc, char* argv[])
max_extent_string = pt.get_optional<std::string>("max_extent");
if (max_extent_string)
{
max_extent = http::map_utils::parse_bbox_from_string(*max_extent_string);
if (!max_extent) config_errors = true;
if (!http::map_utils::parse_bbox_from_string(max_extent,*max_extent_string))
config_errors = true;
}

}
Expand Down
51 changes: 25 additions & 26 deletions src/request_handler.cpp
Expand Up @@ -151,27 +151,25 @@ void request_handler::handle_request(const request& req, reply& rep)

wms_query wms_query(query);

boost::optional<std::string> bbox_string = wms_query.get_bbox_string();
if (!bbox_string)
std::string bbox_string;
if (!wms_query.get_bbox_string(bbox_string))
{
rep = reply::reply_html("missing bbox");
//rep = reply::stock_reply(reply::bad_request);
return;
}

boost::optional<Envelope<double> > bbox = wms_query.parse_bbox_string(*bbox_string);

if (!bbox)
Envelope<double> bbox;
if (!wms_query.parse_bbox_string(bbox,bbox_string))
{
rep = reply::reply_html("failed to parse bbox");
//rep = reply::stock_reply(reply::bad_request);
return;
}

boost::optional<unsigned> w = wms_query.width();
boost::optional<unsigned> h = wms_query.height();
unsigned w;
unsigned h;

if (!w || !h)
if (!wms_query.get_width(w) || !wms_query.get_height(h))
{
std::ostringstream s_error;
s_error << "missing width or height. got width value of: " << w
Expand All @@ -182,18 +180,21 @@ void request_handler::handle_request(const request& req, reply& rep)
}


std::string layer_string = wms_query.get_layer_string();
if (layer_string.empty())
std::string layer_string;
if (!wms_query.get_layer_string(layer_string))
{
rep = reply::reply_html("missing layers");
return;
}

std::string srs = wms_query.get_srs();
if (!srs.empty())
std::string srs;
if (!wms_query.get_srs(srs))
{
map_.set_srs("+init=" + srs);
rep = reply::reply_html("missing srs");
return;
}

map_.set_srs("+init=" + srs);

// check for intersection with max/valid extent
//boost::optional<mapnik::box2d<double> > bounds = max_extent();
Expand All @@ -205,12 +206,11 @@ void request_handler::handle_request(const request& req, reply& rep)
}*/

// setup transparent response image
image_32 im(*w,*h);
image_32 im(w,h);

if (intersects)
{
// handle layers
/*
if (boost::algorithm::iequals(layer_string,"__all__"))
{
BOOST_FOREACH ( layer & lyr, map_.layers() )
Expand All @@ -221,20 +221,19 @@ void request_handler::handle_request(const request& req, reply& rep)
else
{
// convert comma separated layers to vector
std::set<std::string> layer_names = wms_query.parse_layer_string(layer_string);
std::set<std::string> layer_names;
wms_query.parse_layer_string(layer_names, layer_string);
BOOST_FOREACH ( layer & lyr, map_.layers() )
{
bool requested = (layer_names.find(lyr.name()) != layer_names.end());
lyr.setActive(requested);
}
}
*/

map_.resize(*w,*h);
map_.resize(w,h);

#ifdef MAP_PER_IO
map_.zoom_to_box(*bbox);
map_.zoom_to_box(bbox);

//map_.set_aspect_fix_mode(mapnik::Map::ADJUST_CANVAS_HEIGHT);
agg_renderer<image_32> ren(map_,im);
Expand All @@ -244,20 +243,20 @@ void request_handler::handle_request(const request& req, reply& rep)
#ifdef MAP_REQUEST
// requires ripped apart mapnik:Map object...
// http://svn.mapnik.org/branches/map_request/
mapnik::request r_(*w,*h);
mapnik::request r_(w,h);
r_.set_srs(map_.srs());
r_.set_buffer_size(128);
boost::optional<color> const& bg = map_.background();
if (bg) r_.set_background(*bg);

r_.zoom_to_box(*bbox);
r_.zoom_to_box(bbox);
// todo, pass only layers and styles?
// std::vector<layer> & map_.layers()
// setActive(true)
agg_renderer<image_32> ren(map_,im,r_);
#else

map_.zoom_to_box(*bbox);
map_.zoom_to_box(bbox);
//map_.set_buffer_size(128);
agg_renderer<image_32> ren(map_,im);

Expand All @@ -277,8 +276,8 @@ void request_handler::handle_request(const request& req, reply& rep)
if (bg) im.set_background(*bg);
}

std::string mime = wms_query.get_mime();
if (mime.empty())
std::string mime;
if (!wms_query.get_mime(mime))
{
mime = "image/png";
}
Expand Down
70 changes: 28 additions & 42 deletions src/uri_parser.cpp
Expand Up @@ -63,15 +63,14 @@ wms_query::wms_query(const std::string& query)
}
}

boost::optional<Envelope<double> > wms_query::parse_bbox_string(const std::string& bbox_string)
bool wms_query::parse_bbox_string(Envelope<double>& box, const std::string& bbox_string)
{
return map_utils::parse_bbox_from_string(bbox_string);
return map_utils::parse_bbox_from_string(box, bbox_string);
}

std::set<std::string> wms_query::parse_layer_string(const std::string& layer_string)
void wms_query::parse_layer_string(std::set<std::string>& layers, const std::string& layer_string)
{

std::set<std::string> result;
boost::char_separator<char> sep(",");
boost::tokenizer<boost::char_separator<char> > tok(layer_string,sep);
for (boost::tokenizer<boost::char_separator<char> >::iterator beg=tok.begin();
Expand All @@ -82,7 +81,7 @@ wms_query::wms_query(const std::string& query)
std::string layer_name = boost::trim_copy(*beg);
if (!layer_name.empty())
{
result.insert(layer_name);
layers.insert(layer_name);
}
}
catch (boost::bad_lexical_cast & ex)
Expand All @@ -91,7 +90,6 @@ wms_query::wms_query(const std::string& query)
break;
}
}
return result;

}

Expand All @@ -100,82 +98,70 @@ wms_query::wms_query(const std::string& query)
}*/

boost::optional<std::string> wms_query::get_bbox_string()
bool wms_query::get_bbox_string(std::string& bbox_string)
{

boost::optional<std::string> result;
iterator_type itr = params_.find("bbox");
if (itr != params_.end())
{
result.reset(itr->second);
return result;
bbox_string = itr->second;
return true;
}
return result;
return false;
}

std::string wms_query::get_layer_string()
bool wms_query::get_layer_string(std::string& layer_string)
{

std::string result("");
iterator_type itr = params_.find("layers");
if (itr != params_.end())
{
result = itr->second;
return result;
layer_string = itr->second;
return true;
}
return result;
return false;
}

std::string wms_query::get_mime()
bool wms_query::get_mime(std::string& mime)
{

std::string result("");
iterator_type itr = params_.find("format");
if (itr != params_.end())
{
result = itr->second;
return result;
mime = itr->second;
return true;
}
return result;
return false;
}

std::string wms_query::get_srs()
bool wms_query::get_srs(std::string& srs)
{

std::string result("");
iterator_type itr = params_.find("srs");
if (itr != params_.end())
{
result = itr->second;
return result;
srs = itr->second;
return true;
}
return result;
return false;
}

boost::optional<unsigned> wms_query::width()
bool wms_query::get_width(unsigned& w)
{
boost::optional<unsigned> result;
iterator_type itr = params_.find("width");
if (itr != params_.end())
{
unsigned w = atoi(itr->second.c_str());
result.reset(w);
return result;
w = atoi(itr->second.c_str());
return true;
}
return result;
return false;
}

boost::optional<unsigned> wms_query::height()
bool wms_query::get_height(unsigned& h)
{
boost::optional<unsigned> result;
iterator_type itr = params_.find("height");
if (itr != params_.end())
{
unsigned h = atoi(itr->second.c_str());
result.reset(h);
return result;
h = atoi(itr->second.c_str());
return true;
}
return result;
return false;
}


Expand Down
16 changes: 8 additions & 8 deletions src/uri_parser.hpp
Expand Up @@ -42,15 +42,15 @@ class wms_query
public:
explicit wms_query(const std::string& request_path);

boost::optional<std::string> get_bbox_string();
std::string get_layer_string();
std::string get_mime();
std::string get_srs();
bool get_bbox_string(std::string& bbox_string);
bool get_layer_string(std::string& layer_string);
bool get_mime(std::string& mime);
bool get_srs(std::string& srs);
//static boost::optional<color>& bgcolor();
boost::optional<Envelope<double> > parse_bbox_string(const std::string& bbox_string);
std::set<std::string> parse_layer_string(const std::string& layer_string);
boost::optional<unsigned> width();
boost::optional<unsigned> height();
bool parse_bbox_string(Envelope<double>& box, const std::string& bbox_string);
void parse_layer_string(std::set<std::string>& layers, const std::string& layer_string);
bool get_width(unsigned& w);
bool get_height(unsigned& h);

protected:
Envelope<double> bbox_;
Expand Down

0 comments on commit 7ee1114

Please sign in to comment.