Skip to content

Commit

Permalink
wrap singleton<factory> objects in a func to avoid static data
Browse files Browse the repository at this point in the history
exported multiple time across different translation units
(where singleton is not single anymore;-0)
  • Loading branch information
artemp committed Feb 25, 2005
1 parent 3451489 commit 6e28c06
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
lib_LTLIBRARIES = libmapnik.la
nobase_include_HEADERS = attribute_container.hh attribute.hh color.hh config.hh coord.hh coord_array.hh vertex_vector.hh ctrans.hh datasource.hh datasource_cache.hh factory.hh feature.hh filter.hh envelope.hh gamma.hh geometry.hh geom_util.hh graphics.hh image_data.hh image_reader.hh image_util.hh layer.hh line_aa.hh map.hh mapnik.hh memory.hh params.hh plugin.hh line_symbolizer.hh polygon_symbolizer.hh image_symbolizer.hh pool.hh ptr.hh raster_feature.hh raster.hh render.hh scanline_aa.hh scanline.hh style.hh style_cache.hh style_factory.hh symbolizer.hh text.hh utils.hh vector_feature.hh vertex.hh vertex_transform.hh wkb.hh

libmapnik_la_SOURCES = attribute_container.cc attribute_container.hh attribute.hh color.cc color.hh coord.hh coord_array.hh vertex_vector.hh ctrans.hh datasource.hh datasource_cache.cc datasource_cache.hh envelope.cc envelope.hh factory.hh feature.cc feature.hh filter.hh geometry.hh gamma.hh geom_util.hh graphics.cc graphics.hh image_data.hh image_reader.hh image_util.cc image_util.hh layer.cc layer.hh line_aa.cc line_aa.hh map.cc map.hh mapnik.hh memory.cc memory.hh params.cc params.hh plugin.cc plugin.hh png_reader.cc line_symbolizer.hh polygon_symbolizer.hh image_symbolizer.hh pool.hh ptr.hh raster.cc raster_feature.cc raster_feature.hh raster.hh render.cc render.hh scanline_aa.cc scanline_aa.hh scanline.cc scanline.hh style.cc style.hh style_cache.cc style_cache.hh style_factory.hh symbolizer.hh text.cc text.hh utils.hh vector_feature.cc vector_feature.hh vertex.hh vertex_transform.hh wkb.cc wkb.hh
libmapnik_la_SOURCES = attribute_container.cc attribute_container.hh attribute.hh color.cc color.hh coord.hh coord_array.hh vertex_vector.hh ctrans.hh datasource.hh datasource_cache.cc datasource_cache.hh envelope.cc envelope.hh factory.hh feature.cc feature.hh filter.hh geometry.hh gamma.hh geom_util.hh graphics.cc graphics.hh image_data.hh image_reader.cc image_reader.hh image_util.cc image_util.hh layer.cc layer.hh line_aa.cc line_aa.hh map.cc map.hh mapnik.hh memory.cc memory.hh params.cc params.hh plugin.cc plugin.hh png_reader.cc line_symbolizer.hh polygon_symbolizer.hh image_symbolizer.hh pool.hh ptr.hh raster.cc raster_feature.cc raster_feature.hh raster.hh render.cc render.hh scanline_aa.cc scanline_aa.hh scanline.cc scanline.hh style.cc style.hh style_cache.cc style_cache.hh style_factory.hh symbolizer.hh text.cc text.hh utils.hh vector_feature.cc vector_feature.hh vertex.hh vertex_transform.hh wkb.cc wkb.hh

if BUILD_TIFF_READER
libmapnik_la_SOURCES += tiff_reader.cc
libmapnik_la_SOURCES += tiff_reader.cc
endif

libmapnik_la_CPPFLAGS = $(FREETYPE2_CFLAGS)
Expand Down
60 changes: 35 additions & 25 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@BUILD_TIFF_READER_TRUE@am__append_1 = tiff_reader.cc
@BUILD_TIFF_READER_TRUE@am__append_1 = tiff_reader.cc
subdir = src
DIST_COMMON = $(nobase_include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.hh.in
Expand Down Expand Up @@ -69,10 +69,10 @@ am__libmapnik_la_SOURCES_DIST = attribute_container.cc \
datasource_cache.cc datasource_cache.hh envelope.cc \
envelope.hh factory.hh feature.cc feature.hh filter.hh \
geometry.hh gamma.hh geom_util.hh graphics.cc graphics.hh \
image_data.hh image_reader.hh image_util.cc image_util.hh \
layer.cc layer.hh line_aa.cc line_aa.hh map.cc map.hh \
mapnik.hh memory.cc memory.hh params.cc params.hh plugin.cc \
plugin.hh png_reader.cc line_symbolizer.hh \
image_data.hh image_reader.cc image_reader.hh image_util.cc \
image_util.hh layer.cc layer.hh line_aa.cc line_aa.hh map.cc \
map.hh mapnik.hh memory.cc memory.hh params.cc params.hh \
plugin.cc plugin.hh png_reader.cc line_symbolizer.hh \
polygon_symbolizer.hh image_symbolizer.hh pool.hh ptr.hh \
raster.cc raster_feature.cc raster_feature.hh raster.hh \
render.cc render.hh scanline_aa.cc scanline_aa.hh scanline.cc \
Expand All @@ -84,16 +84,17 @@ am__libmapnik_la_SOURCES_DIST = attribute_container.cc \
am_libmapnik_la_OBJECTS = libmapnik_la-attribute_container.lo \
libmapnik_la-color.lo libmapnik_la-datasource_cache.lo \
libmapnik_la-envelope.lo libmapnik_la-feature.lo \
libmapnik_la-graphics.lo libmapnik_la-image_util.lo \
libmapnik_la-layer.lo libmapnik_la-line_aa.lo \
libmapnik_la-map.lo libmapnik_la-memory.lo \
libmapnik_la-params.lo libmapnik_la-plugin.lo \
libmapnik_la-png_reader.lo libmapnik_la-raster.lo \
libmapnik_la-raster_feature.lo libmapnik_la-render.lo \
libmapnik_la-scanline_aa.lo libmapnik_la-scanline.lo \
libmapnik_la-style.lo libmapnik_la-style_cache.lo \
libmapnik_la-text.lo libmapnik_la-vector_feature.lo \
libmapnik_la-wkb.lo $(am__objects_1)
libmapnik_la-graphics.lo libmapnik_la-image_reader.lo \
libmapnik_la-image_util.lo libmapnik_la-layer.lo \
libmapnik_la-line_aa.lo libmapnik_la-map.lo \
libmapnik_la-memory.lo libmapnik_la-params.lo \
libmapnik_la-plugin.lo libmapnik_la-png_reader.lo \
libmapnik_la-raster.lo libmapnik_la-raster_feature.lo \
libmapnik_la-render.lo libmapnik_la-scanline_aa.lo \
libmapnik_la-scanline.lo libmapnik_la-style.lo \
libmapnik_la-style_cache.lo libmapnik_la-text.lo \
libmapnik_la-vector_feature.lo libmapnik_la-wkb.lo \
$(am__objects_1)
libmapnik_la_OBJECTS = $(am_libmapnik_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
depcomp = $(SHELL) $(top_srcdir)/depcomp
Expand Down Expand Up @@ -248,16 +249,17 @@ libmapnik_la_SOURCES = attribute_container.cc attribute_container.hh \
datasource_cache.hh envelope.cc envelope.hh factory.hh \
feature.cc feature.hh filter.hh geometry.hh gamma.hh \
geom_util.hh graphics.cc graphics.hh image_data.hh \
image_reader.hh image_util.cc image_util.hh layer.cc layer.hh \
line_aa.cc line_aa.hh map.cc map.hh mapnik.hh memory.cc \
memory.hh params.cc params.hh plugin.cc plugin.hh \
png_reader.cc line_symbolizer.hh polygon_symbolizer.hh \
image_symbolizer.hh pool.hh ptr.hh raster.cc raster_feature.cc \
raster_feature.hh raster.hh render.cc render.hh scanline_aa.cc \
scanline_aa.hh scanline.cc scanline.hh style.cc style.hh \
style_cache.cc style_cache.hh style_factory.hh symbolizer.hh \
text.cc text.hh utils.hh vector_feature.cc vector_feature.hh \
vertex.hh vertex_transform.hh wkb.cc wkb.hh $(am__append_1)
image_reader.cc image_reader.hh image_util.cc image_util.hh \
layer.cc layer.hh line_aa.cc line_aa.hh map.cc map.hh \
mapnik.hh memory.cc memory.hh params.cc params.hh plugin.cc \
plugin.hh png_reader.cc line_symbolizer.hh \
polygon_symbolizer.hh image_symbolizer.hh pool.hh ptr.hh \
raster.cc raster_feature.cc raster_feature.hh raster.hh \
render.cc render.hh scanline_aa.cc scanline_aa.hh scanline.cc \
scanline.hh style.cc style.hh style_cache.cc style_cache.hh \
style_factory.hh symbolizer.hh text.cc text.hh utils.hh \
vector_feature.cc vector_feature.hh vertex.hh \
vertex_transform.hh wkb.cc wkb.hh $(am__append_1)
libmapnik_la_CPPFLAGS = $(FREETYPE2_CFLAGS) @INCLTDL@
libmapnik_la_LIBADD = @LIBLTDL@ -lpthread -lpng $(FREETYPE2_LIBS) -lz -lm
libmapnik_la_LDFLAGS = -version-info 0:0:0 $(TIFF_LDFLAGS)
Expand Down Expand Up @@ -358,6 +360,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-envelope.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-feature.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-graphics.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-image_reader.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-image_util.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-layer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmapnik_la-line_aa.Plo@am__quote@
Expand Down Expand Up @@ -441,6 +444,13 @@ libmapnik_la-graphics.lo: graphics.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmapnik_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libmapnik_la-graphics.lo `test -f 'graphics.cc' || echo '$(srcdir)/'`graphics.cc

libmapnik_la-image_reader.lo: image_reader.cc
@am__fastdepCXX_TRUE@ if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmapnik_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libmapnik_la-image_reader.lo -MD -MP -MF "$(DEPDIR)/libmapnik_la-image_reader.Tpo" -c -o libmapnik_la-image_reader.lo `test -f 'image_reader.cc' || echo '$(srcdir)/'`image_reader.cc; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libmapnik_la-image_reader.Tpo" "$(DEPDIR)/libmapnik_la-image_reader.Plo"; else rm -f "$(DEPDIR)/libmapnik_la-image_reader.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='image_reader.cc' object='libmapnik_la-image_reader.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmapnik_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libmapnik_la-image_reader.lo `test -f 'image_reader.cc' || echo '$(srcdir)/'`image_reader.cc

libmapnik_la-image_util.lo: image_util.cc
@am__fastdepCXX_TRUE@ if $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmapnik_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libmapnik_la-image_util.lo -MD -MP -MF "$(DEPDIR)/libmapnik_la-image_util.Tpo" -c -o libmapnik_la-image_util.lo `test -f 'image_util.cc' || echo '$(srcdir)/'`image_util.cc; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libmapnik_la-image_util.Tpo" "$(DEPDIR)/libmapnik_la-image_util.Plo"; else rm -f "$(DEPDIR)/libmapnik_la-image_util.Tpo"; exit 1; fi
Expand Down
6 changes: 4 additions & 2 deletions src/factory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <stdexcept>
#include <map>
#include "utils.hh"

namespace mapnik
{
Expand Down Expand Up @@ -50,8 +51,9 @@ namespace mapnik
typename key_type,
typename product_creator=product_type* (*)(),
template <typename,typename> class factory_error_policy=default_factory_error
>
class factory : public factory_error_policy <key_type,product_type>
>
class factory : public singleton<factory <product_type,key_type,product_creator,factory_error_policy> >,
factory_error_policy <key_type,product_type>
{
private:
typedef std::map<key_type,product_creator> product_map;
Expand Down
38 changes: 38 additions & 0 deletions src/image_reader.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* This file is part of Mapnik (c++ mapping toolkit)
* Copyright (C) 2005 Artem Pavlenko
*
* Mapnik is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

//$Id$


#include "image_reader.hh"
namespace mapnik
{
typedef factory<ImageReader,std::string,
ImageReader* (*)(const std::string&)> ImageReaderFactory;


bool register_image_reader(const std::string& type,ImageReader* (* fun)(const std::string&))
{
return ImageReaderFactory::instance()->register_product(type,fun);
}

ImageReader* get_image_reader(const std::string& type,const std::string& file)
{
return ImageReaderFactory::instance()->create_object(type,file);
}
}
6 changes: 4 additions & 2 deletions src/image_reader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "mapnik.hh"
#include <stdexcept>
#include <string>

namespace mapnik {

Expand All @@ -49,9 +50,10 @@ namespace mapnik {
virtual void read(unsigned x,unsigned y,ImageData32& image)=0;
virtual ~ImageReader() {}
};

bool register_image_reader(const std::string& type,ImageReader* (*)(const std::string&));
ImageReader* get_image_reader(const std::string& type,const std::string& file);

typedef singleton<factory<ImageReader,std::string,
ImageReader* (*)(const std::string&)> > ImageReaderFactory;
}

#endif //IMAGE_READER_HH
2 changes: 1 addition & 1 deletion src/image_symbolizer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace mapnik
{
try
{
std::auto_ptr<ImageReader> reader(ImageReaderFactory::instance()->create_object(type,file));
std::auto_ptr<ImageReader> reader(get_image_reader(type,file));
std::cout<<"image width="<<reader->width()<<std::endl;
std::cout<<"image height="<<reader->height()<<std::endl;
reader->read(0,0,symbol_);
Expand Down
4 changes: 1 addition & 3 deletions src/png_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ namespace mapnik
{
return new PngReader(file);
}
const bool registered =
ImageReaderFactory::instance()->register_product("png",createPngReader);
const bool registered = register_image_reader("png",createPngReader);
}


PngReader::PngReader(const std::string& fileName)
: fileName_(fileName),
width_(0),
Expand Down
2 changes: 1 addition & 1 deletion src/raster/raster_datasource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FeaturesetPtr raster_datasource::featuresInBox(const CoordTransform& t,
const mapnik::Envelope<double>& box) const
{
RasterInfo info(filename_,format_,extent_);
single_file_policy policy(info); //todo: handle different policies!
single_file_policy policy(info); //todo: handle different policies!
return FeaturesetPtr(new RasterFeatureset<single_file_policy>(policy,box,t));
}

Expand Down
10 changes: 7 additions & 3 deletions src/raster/raster_featureset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ RasterFeatureset<LookupPolicy>::RasterFeatureset(const LookupPolicy& policy,
extent_(box),
t_(t),
curIter_(policy_.query(box)),
endIter_(policy_.end()) {}
endIter_(policy_.end())

{}

template <typename LookupPolicy>
RasterFeatureset<LookupPolicy>::~RasterFeatureset() {}
Expand All @@ -41,8 +43,10 @@ Feature* RasterFeatureset<LookupPolicy>::next()
{
try
{
std::auto_ptr<ImageReader> reader(ImageReaderFactory::instance()->create_object(curIter_->format(),curIter_->file()));
if (reader.get())
std::cout<<"RasterFeatureset "<<curIter_->format()<<" "<<curIter_->file()<<std::endl;
std::auto_ptr<ImageReader> reader(get_image_reader(curIter_->format(),curIter_->file()));
std::cout<<reader.get()<<std::endl;
if (reader.get())
{
int image_width=reader->width();
int image_height=reader->height();
Expand Down
22 changes: 11 additions & 11 deletions src/raster_feature.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ namespace mapnik

class RasterFeature : public FeatureImpl
{
private:
RasterPtr ras_;
public:
RasterFeature(int id,const RasterPtr& ras);
virtual ~RasterFeature();
bool isRaster() const;
geometry_ptr& getGeometry();
const RasterPtr& getRaster() const;
private:
RasterFeature(const RasterFeature&);
RasterFeature& operator=(const RasterFeature&);
private:
RasterPtr ras_;
public:
RasterFeature(int id,const RasterPtr& ras);
virtual ~RasterFeature();
bool isRaster() const;
geometry_ptr& getGeometry();
const RasterPtr& getRaster() const;
private:
RasterFeature(const RasterFeature&);
RasterFeature& operator=(const RasterFeature&);
};
}
#endif //RASTER_FEATURE_HH
6 changes: 4 additions & 2 deletions src/render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ namespace mapnik
const Style& style=styles->find(l.getStyle());
//TODO fix scale
Style::Iterator itr = style.find(1.0/t.scale());
if (itr!=style.end()) {

if (itr!=style.end())
{
Feature* feature=0;
while (feature=fs->next())
{
// TODO refactor!!!!
// TODO
if (feature->isRaster())
{
const RasterPtr& ras=feature->getRaster();
Expand Down
3 changes: 1 addition & 2 deletions src/tiff_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ namespace mapnik
return new TiffReader(file);
}

const bool registered =
ImageReaderFactory::instance()->register_product("tiff",createTiffReader);
const bool registered = register_image_reader("tiff",createTiffReader);
}

TiffReader::TiffReader(const std::string& file_name)
Expand Down
1 change: 1 addition & 0 deletions src/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace mapnik
delete obj;
}
};

template <typename T>
class CreateStatic
{
Expand Down

0 comments on commit 6e28c06

Please sign in to comment.