Permalink
Browse files

+ singleton: return ref from instance() method

  • Loading branch information...
1 parent 11e6ba0 commit 967d6110bfa92d4574eb338bf8d1f7c95cf2f538 @artemp artemp committed Sep 7, 2012
@@ -81,7 +81,7 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
}
}
- return mapnik::datasource_cache::instance()->create(params, bind);
+ return mapnik::datasource_cache::instance().create(params, bind);
}
boost::python::dict describe(boost::shared_ptr<mapnik::datasource> const& ds)
@@ -61,22 +61,22 @@ boost::shared_ptr<mapnik::datasource> create_datasource(const dict& d)
}
}
- return mapnik::datasource_cache::instance()->create(params, bind);
+ return mapnik::datasource_cache::instance().create(params, bind);
}
void register_datasources(std::string const& path)
{
- mapnik::datasource_cache::instance()->register_datasources(path);
+ mapnik::datasource_cache::instance().register_datasources(path);
}
std::vector<std::string> plugin_names()
{
- return mapnik::datasource_cache::instance()->plugin_names();
+ return mapnik::datasource_cache::instance().plugin_names();
}
std::string plugin_directories()
{
- return mapnik::datasource_cache::instance()->plugin_directories();
+ return mapnik::datasource_cache::instance().plugin_directories();
}
}
@@ -77,7 +77,7 @@ struct layer_pickle_suite : boost::python::pickle_suite
l.set_queryable(extract<bool>(state[3]));
mapnik::parameters params = extract<parameters>(state[4]);
- l.set_datasource(datasource_cache::instance()->create(params));
+ l.set_datasource(datasource_cache::instance().create(params));
boost::python::list s = extract<boost::python::list>(state[5]);
for (int i=0;i<len(s);++i)
@@ -54,11 +54,11 @@ void set_marker_type(mapnik::markers_symbolizer & symbolizer, std::string const&
std::string filename;
if (marker_type == "ellipse")
{
- filename = mapnik::marker_cache::instance()->known_svg_prefix_ + "ellipse";
+ filename = mapnik::marker_cache::instance().known_svg_prefix_ + "ellipse";
}
else if (marker_type == "arrow")
{
- filename = mapnik::marker_cache::instance()->known_svg_prefix_ + "arrow";
+ filename = mapnik::marker_cache::instance().known_svg_prefix_ + "arrow";
}
else
{
@@ -96,8 +96,8 @@ void export_logger();
void clear_cache()
{
- mapnik::marker_cache::instance()->clear();
- mapnik::mapped_memory_cache::instance()->clear();
+ mapnik::marker_cache::instance().clear();
+ mapnik::mapped_memory_cache::instance().clear();
}
#if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO)
View
@@ -56,7 +56,7 @@ int main ( int argc , char** argv)
std::cout << " running demo ... \n";
std::string mapnik_dir(argv[1]);
std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/input/" << "\n";
- datasource_cache::instance()->register_datasources(mapnik_dir + "/input/");
+ datasource_cache::instance().register_datasources(mapnik_dir + "/input/");
std::cout << " looking for DejaVuSans font in... " << mapnik_dir << "/fonts/DejaVuSans.ttf" << "\n";
freetype_engine::register_font(mapnik_dir + "/fonts/DejaVuSans.ttf");
@@ -182,7 +182,7 @@ int main ( int argc , char** argv)
p["encoding"]="latin1";
layer lyr("Provinces");
- lyr.set_datasource(datasource_cache::instance()->create(p));
+ lyr.set_datasource(datasource_cache::instance().create(p));
lyr.add_style("provinces");
m.addLayer(lyr);
}
@@ -193,7 +193,7 @@ int main ( int argc , char** argv)
p["type"]="shape";
p["file"]="../data/qcdrainage";
layer lyr("Quebec Hydrography");
- lyr.set_datasource(datasource_cache::instance()->create(p));
+ lyr.set_datasource(datasource_cache::instance().create(p));
lyr.add_style("drainage");
m.addLayer(lyr);
}
@@ -204,7 +204,7 @@ int main ( int argc , char** argv)
p["file"]="../data/ontdrainage";
layer lyr("Ontario Hydrography");
- lyr.set_datasource(datasource_cache::instance()->create(p));
+ lyr.set_datasource(datasource_cache::instance().create(p));
lyr.add_style("drainage");
m.addLayer(lyr);
}
@@ -215,7 +215,7 @@ int main ( int argc , char** argv)
p["type"]="shape";
p["file"]="../data/boundaries_l";
layer lyr("Provincial borders");
- lyr.set_datasource(datasource_cache::instance()->create(p));
+ lyr.set_datasource(datasource_cache::instance().create(p));
lyr.add_style("provlines");
m.addLayer(lyr);
}
@@ -226,7 +226,7 @@ int main ( int argc , char** argv)
p["type"]="shape";
p["file"]="../data/roads";
layer lyr("Roads");
- lyr.set_datasource(datasource_cache::instance()->create(p));
+ lyr.set_datasource(datasource_cache::instance().create(p));
lyr.add_style("smallroads");
lyr.add_style("road-border");
lyr.add_style("road-fill");
@@ -242,7 +242,7 @@ int main ( int argc , char** argv)
p["file"]="../data/popplaces";
p["encoding"] = "latin1";
layer lyr("Populated Places");
- lyr.set_datasource(datasource_cache::instance()->create(p));
+ lyr.set_datasource(datasource_cache::instance().create(p));
lyr.add_style("popplaces");
m.addLayer(lyr);
}
@@ -258,7 +258,7 @@ int main ( int argc , char** argv)
save_to_file(buf,"demo.png","png");
save_to_file(buf,"demo256.png","png256");
save_to_file(buf,"demo.tif","tiff");
-
+
std::cout << "Three maps have been rendered using AGG in the current directory:\n"
"- demo.jpg\n"
"- demo.png\n"
View
@@ -45,7 +45,7 @@ int main( int argc, char **argv )
// register input plug-ins
QString plugins_dir = settings.value("mapnik/plugins_dir",
QVariant("/usr/local/lib/mapnik/input/")).toString();
- datasource_cache::instance()->register_datasources(plugins_dir.toStdString());
+ datasource_cache::instance().register_datasources(plugins_dir.toStdString());
// register fonts
int count = settings.beginReadArray("mapnik/fonts");
for (int index=0; index < count; ++index)
View
@@ -129,7 +129,7 @@ template <typename T,
#endif
singleton() {}
public:
- static T* instance()
+ static T& instance()
{
if (! pInstance_)
{
@@ -140,7 +140,6 @@ template <typename T,
{
if (destroyed_)
{
- destroyed_ = false;
onDeadReference();
}
else
@@ -152,7 +151,7 @@ template <typename T,
}
}
}
- return pInstance_;
+ return *pInstance_;
}
};
#ifdef MAPNIK_THREADSAFE
@@ -64,7 +64,7 @@ ogr_index_featureset<filterT>::ogr_index_featureset(mapnik::context_ptr const &
fidcolumn_(layer_.GetFIDColumn())
{
- boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::instance()->find(index_file.c_str(),true);
+ boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::instance().find(index_file.c_str(),true);
if (memory)
{
boost::interprocess::ibufferstream file(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
@@ -320,7 +320,7 @@ void MapSource::setOSMLayers(Map& m, const parameters &p)
if(boost::get<std::string>(q["type"])=="osm")
{
m.getLayer(count).set_datasource
- (datasource_cache::instance()->create(p));
+ (datasource_cache::instance().create(p));
}
}
}
@@ -353,7 +353,7 @@ void MapSource::addSRTMLayers(Map& m,double w,double s,double e,double n)
<<(lon>=0 ? lon:-lon)<<"c10";
p["file"] = str.str();
cerr<<"ADDING SRTM LAYER: " << p["file"] << endl;
- m.getLayer(i).set_datasource(datasource_cache::instance()->create(p));
+ m.getLayer(i).set_datasource(datasource_cache::instance().create(p));
// do we have more than one srtm layer?
if(floor(w) != floor(e) || floor(s) != floor(n))
@@ -385,7 +385,7 @@ void MapSource::addSRTMLayers(Map& m,double w,double s,double e,double n)
lyr.add_style("contours");
lyr.add_style("contours-text");
lyr.set_datasource
- (datasource_cache::instance()->create(p));
+ (datasource_cache::instance().create(p));
m.addLayer(lyr);
}
}
@@ -32,7 +32,7 @@ int main(int argc,char *argv[])
exit(1);
}
- datasource_cache::instance()->register_datasources
+ datasource_cache::instance().register_datasources
("/usr/local/lib/mapnik/input");
freetype_engine::register_font
("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf");
@@ -43,7 +43,7 @@ int main(int argc,char *argv[])
exit(0);
}
- mapnik::datasource_cache::instance()->register_datasources("/usr/local/lib/mapnik/input");
+ mapnik::datasource_cache::instance().register_datasources("/usr/local/lib/mapnik/input");
mapnik::freetype_engine::register_font("/usr/local/lib/mapnik/fonts/DejaVuSans.ttf");
mapnik::Map m(800, 800);
@@ -57,7 +57,7 @@ int main(int argc,char *argv[])
for (int count = 0; count < m.layer_count(); count++)
{
mapnik::parameters q = m.getLayer(count).datasource()->params();
- m.getLayer(count).set_datasource(mapnik::datasource_cache::instance()->create(p));
+ m.getLayer(count).set_datasource(mapnik::datasource_cache::instance().create(p));
}
}
@@ -120,10 +120,8 @@ void postgis_datasource::bind() const
boost::optional<mapnik::boolean> simplify_opt = params_.get<mapnik::boolean>("simplify_geometries", false);
simplify_geometries_ = simplify_opt && *simplify_opt;
- ConnectionManager* mgr = ConnectionManager::instance();
- mgr->registerPool(creator_, *initial_size, *max_size);
-
- shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
+ ConnectionManager::instance().registerPool(creator_, *initial_size, *max_size);
+ shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
@@ -430,8 +428,7 @@ postgis_datasource::~postgis_datasource()
{
if (is_bound_ && ! persist_connection_)
{
- ConnectionManager* mgr = ConnectionManager::instance();
- shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
+ shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
@@ -613,8 +610,7 @@ featureset_ptr postgis_datasource::features(const query& q) const
box2d<double> const& box = q.get_bbox();
double scale_denom = q.scale_denominator();
- ConnectionManager* mgr = ConnectionManager::instance();
- shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
+ shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
@@ -723,9 +719,7 @@ featureset_ptr postgis_datasource::features_at_point(coord2d const& pt) const
#ifdef MAPNIK_STATS
mapnik::progress_timer __stats__(std::clog, "postgis_datasource::features_at_point");
#endif
-
- ConnectionManager* mgr = ConnectionManager::instance();
- shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
+ shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
@@ -814,8 +808,7 @@ box2d<double> postgis_datasource::envelope() const
bind();
}
- ConnectionManager* mgr = ConnectionManager::instance();
- shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
+ shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
@@ -915,8 +908,7 @@ boost::optional<mapnik::datasource::geometry_t> postgis_datasource::get_geometry
boost::optional<mapnik::datasource::geometry_t> result;
- ConnectionManager* mgr = ConnectionManager::instance();
- shared_ptr< Pool<Connection,ConnectionCreator> > pool = mgr->getPool(creator_.id());
+ shared_ptr< Pool<Connection,ConnectionCreator> > pool = ConnectionManager::instance().getPool(creator_.id());
if (pool)
{
shared_ptr<Connection> conn = pool->borrowObject();
@@ -55,7 +55,7 @@ dbf_file::dbf_file(std::string const& file_name)
{
#ifdef SHAPE_MEMORY_MAPPED_FILE
- boost::optional<mapnik::mapped_region_ptr> memory = mapped_memory_cache::instance()->find(file_name.c_str(),true);
+ boost::optional<mapnik::mapped_region_ptr> memory = mapped_memory_cache::instance().find(file_name.c_str(),true);
if (memory)
{
file_.buffer(static_cast<char*>((*memory)->get_address()),(*memory)->get_size());
@@ -155,7 +155,7 @@ class shape_file : boost::noncopyable
{
#ifdef SHAPE_MEMORY_MAPPED_FILE
boost::optional<mapnik::mapped_region_ptr> memory =
- mapnik::mapped_memory_cache::instance()->find(file_name.c_str(),true);
+ mapnik::mapped_memory_cache::instance().find(file_name.c_str(),true);
if (memory)
{
View
@@ -137,7 +137,7 @@ void agg_renderer<T>::setup(Map const &m)
boost::optional<std::string> const& image_filename = m.background_image();
if (image_filename)
{
- boost::optional<mapnik::marker_ptr> bg_marker = mapnik::marker_cache::instance()->find(*image_filename,true);
+ boost::optional<mapnik::marker_ptr> bg_marker = mapnik::marker_cache::instance().find(*image_filename,true);
if (bg_marker && (*bg_marker)->is_bitmap())
{
mapnik::image_ptr bg_image = *(*bg_marker)->get_bitmap_data();
@@ -67,7 +67,7 @@ void agg_renderer<T>::process(line_pattern_symbolizer const& sym,
std::string filename = path_processor_type::evaluate( *sym.get_filename(), feature);
- boost::optional<marker_ptr> mark = marker_cache::instance()->find(filename,true);
+ boost::optional<marker_ptr> mark = marker_cache::instance().find(filename,true);
if (!mark) return;
if (!(*mark)->is_bitmap())
@@ -75,7 +75,7 @@ void agg_renderer<T>::process(markers_symbolizer const& sym,
if (!filename.empty())
{
- boost::optional<marker_ptr> mark = mapnik::marker_cache::instance()->find(filename, true);
+ boost::optional<marker_ptr> mark = mapnik::marker_cache::instance().find(filename, true);
if (mark && *mark)
{
ras_ptr->reset();
@@ -52,7 +52,7 @@ void agg_renderer<T>::process(point_symbolizer const& sym,
boost::optional<mapnik::marker_ptr> marker;
if ( !filename.empty() )
{
- marker = marker_cache::instance()->find(filename, true);
+ marker = marker_cache::instance().find(filename, true);
}
else
{
@@ -63,7 +63,7 @@ void agg_renderer<T>::process(polygon_pattern_symbolizer const& sym,
boost::optional<mapnik::marker_ptr> marker;
if ( !filename.empty() )
{
- marker = marker_cache::instance()->find(filename, true);
+ marker = marker_cache::instance().find(filename, true);
}
else
{
Oops, something went wrong.

0 comments on commit 967d611

Please sign in to comment.