+ make client methods non-static in classes derived from

mapnik::singleton<> (TODO: apply to all)
+ ensure client methods are accessed through instance() method
This commit is contained in:
artemp 2012-09-07 14:41:07 +01:00
parent 5f8bb423e8
commit 8fa0742a53
12 changed files with 53 additions and 62 deletions

View file

@ -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::known_svg_prefix_ + "ellipse";
filename = mapnik::marker_cache::instance()->known_svg_prefix_ + "ellipse";
}
else if (marker_type == "arrow")
{
filename = mapnik::marker_cache::known_svg_prefix_ + "arrow";
filename = mapnik::marker_cache::instance()->known_svg_prefix_ + "arrow";
}
else
{

View file

@ -36,28 +36,27 @@
// stl
#include <map>
namespace mapnik { namespace detail {
class MAPNIK_DECL datasource_cache_impl
namespace mapnik {
class MAPNIK_DECL datasource_cache
: public singleton<datasource_cache, CreateStatic>,
private boost::noncopyable
{
friend class CreateStatic<datasource_cache>;
public:
datasource_cache_impl();
~datasource_cache_impl();
std::vector<std::string> plugin_names();
std::string plugin_directories();
void register_datasources(std::string const& path);
bool register_datasource(std::string const& path);
boost::shared_ptr<datasource> create(parameters const& params, bool bind=true);
private:
datasource_cache();
~datasource_cache();
std::map<std::string,boost::shared_ptr<PluginInfo> > plugins_;
bool registered_;
bool insert(std::string const& name,const lt_dlhandle module);
std::vector<std::string> plugin_directories_;
};
}
typedef singleton<detail::datasource_cache_impl, CreateStatic> datasource_cache;
}
#endif // MAPNIK_DATASOURCE_CACHE_HPP

View file

@ -42,17 +42,16 @@ using namespace boost::interprocess;
typedef boost::shared_ptr<mapped_region> mapped_region_ptr;
struct MAPNIK_DECL mapped_memory_cache :
public singleton <mapped_memory_cache, CreateStatic>,
public singleton<mapped_memory_cache, CreateStatic>,
private boost::noncopyable
{
friend class CreateStatic<mapped_memory_cache>;
static boost::unordered_map<std::string,mapped_region_ptr> cache_;
static bool insert(std::string const& key, mapped_region_ptr);
static boost::optional<mapped_region_ptr> find(std::string const& key, bool update_cache = false);
static void clear();
boost::unordered_map<std::string,mapped_region_ptr> cache_;
bool insert(std::string const& key, mapped_region_ptr);
boost::optional<mapped_region_ptr> find(std::string const& key, bool update_cache = false);
void clear();
};
}
#endif // MAPNIK_MAPPED_MEMORY_CACHE_HPP

View file

@ -49,15 +49,15 @@ class MAPNIK_DECL marker_cache :
private:
marker_cache();
~marker_cache();
static bool insert_marker(std::string const& key, marker_ptr path);
static boost::unordered_map<std::string,marker_ptr> marker_cache_;
static bool insert_svg(std::string const& name, std::string const& svg_string);
static boost::unordered_map<std::string,std::string> svg_cache_;
bool insert_marker(std::string const& key, marker_ptr path);
boost::unordered_map<std::string,marker_ptr> marker_cache_;
bool insert_svg(std::string const& name, std::string const& svg_string);
boost::unordered_map<std::string,std::string> svg_cache_;
public:
static std::string known_svg_prefix_;
static bool is_uri(std::string const& path);
static boost::optional<marker_ptr> find(std::string const& key, bool update_cache = false);
static void clear();
std::string known_svg_prefix_;
bool is_uri(std::string const& path);
boost::optional<marker_ptr> find(std::string const& key, bool update_cache = false);
void clear();
};
}

View file

@ -140,6 +140,7 @@ public:
{
if (destroyed_)
{
destroyed_ = false;
onDeadReference();
}
else

View file

@ -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::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());

View file

@ -34,6 +34,8 @@
#include <string>
using mapnik::mapped_memory_cache;
dbf_file::dbf_file()
: num_records_(0),
num_fields_(0),
@ -53,7 +55,7 @@ dbf_file::dbf_file(std::string const& file_name)
{
#ifdef SHAPE_MEMORY_MAPPED_FILE
boost::optional<mapnik::mapped_region_ptr> memory = mapnik::mapped_memory_cache::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());

View file

@ -155,7 +155,7 @@ public:
{
#ifdef SHAPE_MEMORY_MAPPED_FILE
boost::optional<mapnik::mapped_region_ptr> memory =
mapnik::mapped_memory_cache::find(file_name.c_str(),true);
mapnik::mapped_memory_cache::instance()->find(file_name.c_str(),true);
if (memory)
{

View file

@ -38,7 +38,7 @@
#include <iostream>
#include <stdexcept>
namespace mapnik { namespace detail {
namespace mapnik {
bool is_input_plugin (std::string const& filename)
{
@ -46,21 +46,17 @@ bool is_input_plugin (std::string const& filename)
}
datasource_cache_impl::datasource_cache_impl()
datasource_cache::datasource_cache()
{
if (lt_dlinit()) throw std::runtime_error("lt_dlinit() failed");
}
datasource_cache_impl::~datasource_cache_impl()
datasource_cache::~datasource_cache()
{
lt_dlexit();
}
//std::map<std::string,boost::shared_ptr<PluginInfo> > datasource_cache::plugins_;
//bool datasource_cache::registered_=false;
//std::vector<std::string> datasource_cache::plugin_directories_;
datasource_ptr datasource_cache_impl::create(const parameters& params, bool bind)
datasource_ptr datasource_cache::create(const parameters& params, bool bind)
{
boost::optional<std::string> type = params.get<std::string>("type");
if ( ! type)
@ -70,7 +66,7 @@ datasource_ptr datasource_cache_impl::create(const parameters& params, bool bind
}
#ifdef MAPNIK_THREADSAFE
//mutex::scoped_lock lock(mutex_);
mutex::scoped_lock lock(mutex_);
#endif
datasource_ptr ds;
@ -101,34 +97,34 @@ datasource_ptr datasource_cache_impl::create(const parameters& params, bool bind
}
#ifdef MAPNIK_LOG
MAPNIK_LOG_DEBUG(datasource_cache_impl) << "datasource_cache: Size=" << params.size();
MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Size=" << params.size();
parameters::const_iterator i = params.begin();
for (; i != params.end(); ++i)
{
MAPNIK_LOG_DEBUG(datasource_cache_impl) << "datasource_cache: -- " << i->first << "=" << i->second;
MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: -- " << i->first << "=" << i->second;
}
#endif
ds = datasource_ptr(create_datasource(params, bind), datasource_deleter());
MAPNIK_LOG_DEBUG(datasource_cache_impl) << "datasource_cache: Datasource=" << ds << " type=" << type;
MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Datasource=" << ds << " type=" << type;
return ds;
}
bool datasource_cache_impl::insert(std::string const& type,const lt_dlhandle module)
bool datasource_cache::insert(std::string const& type,const lt_dlhandle module)
{
return plugins_.insert(make_pair(type,boost::make_shared<PluginInfo>
(type,module))).second;
}
std::string datasource_cache_impl::plugin_directories()
std::string datasource_cache::plugin_directories()
{
return boost::algorithm::join(plugin_directories_,", ");
}
std::vector<std::string> datasource_cache_impl::plugin_names()
std::vector<std::string> datasource_cache::plugin_names()
{
std::vector<std::string> names;
std::map<std::string,boost::shared_ptr<PluginInfo> >::const_iterator itr;
@ -139,11 +135,10 @@ std::vector<std::string> datasource_cache_impl::plugin_names()
return names;
}
void datasource_cache_impl::register_datasources(std::string const& str)
void datasource_cache::register_datasources(std::string const& str)
{
#ifdef MAPNIK_THREADSAFE
//mutex::scoped_lock lock(mapnik::singleton<mapnik::datasource_cache,
// mapnik::CreateStatic>::mutex_);
mutex::scoped_lock lock(mutex_);
#endif
boost::filesystem::path path(str);
// TODO - only push unique paths
@ -174,7 +169,7 @@ void datasource_cache_impl::register_datasources(std::string const& str)
}
}
bool datasource_cache_impl::register_datasource(std::string const& str)
bool datasource_cache::register_datasource(std::string const& str)
{
bool success = false;
try
@ -215,4 +210,4 @@ bool datasource_cache_impl::register_datasource(std::string const& str)
return success;
}
}}
}

View file

@ -974,11 +974,11 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
{
if (*marker_type == "ellipse")
{
filename = marker_cache::known_svg_prefix_ + "ellipse";
filename = marker_cache::instance()->known_svg_prefix_ + "ellipse";
}
else if (*marker_type == "arrow")
{
filename = marker_cache::known_svg_prefix_ + "arrow";
filename = marker_cache::instance()->known_svg_prefix_ + "arrow";
}
}
}
@ -1011,16 +1011,16 @@ void map_parser::parse_markers_symbolizer(rule & rule, xml_node const& sym)
optional<color> c = sym.get_opt_attr<color>("fill");
if (c) symbol.set_fill(*c);
optional<double> spacing = sym.get_opt_attr<double>("spacing");
if (spacing) symbol.set_spacing(*spacing);
optional<double> max_error = sym.get_opt_attr<double>("max-error");
if (max_error) symbol.set_max_error(*max_error);
optional<boolean> allow_overlap = sym.get_opt_attr<boolean>("allow-overlap");
if (allow_overlap) symbol.set_allow_overlap(*allow_overlap);
optional<boolean> ignore_placement = sym.get_opt_attr<boolean>("ignore-placement");
if (ignore_placement) symbol.set_ignore_placement(*ignore_placement);
@ -1605,7 +1605,7 @@ void map_parser::ensure_font_face(std::string const& face_name)
std::string map_parser::ensure_relative_to_xml(boost::optional<std::string> opt_path)
{
if (marker_cache::is_uri(*opt_path))
if (marker_cache::instance()->is_uri(*opt_path))
return *opt_path;
if (relative_to_xml_)
@ -1633,7 +1633,7 @@ std::string map_parser::ensure_relative_to_xml(boost::optional<std::string> opt_
void map_parser::ensure_exists(std::string const& file_path)
{
if (marker_cache::is_uri(file_path))
if (marker_cache::instance()->is_uri(file_path))
return;
// validate that the filename exists if it is not a dynamic PathExpression
if (!boost::algorithm::find_first(file_path,"[") && !boost::algorithm::find_first(file_path,"]"))

View file

@ -33,8 +33,6 @@
namespace mapnik
{
boost::unordered_map<std::string, mapped_region_ptr> mapped_memory_cache::cache_;
void mapped_memory_cache::clear()
{
#ifdef MAPNIK_THREADSAFE

View file

@ -45,11 +45,8 @@
namespace mapnik
{
boost::unordered_map<std::string, marker_ptr> marker_cache::marker_cache_;
boost::unordered_map<std::string, std::string> marker_cache::svg_cache_;
std::string marker_cache::known_svg_prefix_ = "shape://";
marker_cache::marker_cache()
: known_svg_prefix_("shape://")
{
insert_svg("ellipse",
"<?xml version='1.0' standalone='no'?>"