formatting mostly

This commit is contained in:
Artem Pavlenko 2006-07-24 20:08:32 +00:00
parent d11153ccf8
commit 0bb121a747
8 changed files with 270 additions and 275 deletions

View file

@ -32,68 +32,68 @@ namespace mapnik
{
template <typename T,int dim>
struct coord {
typedef T type;
typedef T type;
};
template <typename T>
struct coord<T,2>
{
typedef T type;
T x;
T y;
typedef T type;
T x;
T y;
public:
coord()
: x(),y() {}
coord(T x,T y)
: x(x),y(y) {}
template <typename T2>
coord (const coord<T2,2>& rhs)
: x(type(rhs.x)),
y(type(rhs.y)) {}
coord()
: x(),y() {}
coord(T x,T y)
: x(x),y(y) {}
template <typename T2>
coord (const coord<T2,2>& rhs)
: x(type(rhs.x)),
y(type(rhs.y)) {}
template <typename T2>
coord<T,2>& operator=(const coord<T2,2>& rhs)
{
if ((void*)this==(void*)&rhs)
{
return *this;
}
x=type(rhs.x);
y=type(rhs.y);
return *this;
}
template <typename T2>
coord<T,2>& operator=(const coord<T2,2>& rhs)
{
if ((void*)this==(void*)&rhs)
{
return *this;
}
x=type(rhs.x);
y=type(rhs.y);
return *this;
}
};
template <typename T>
struct coord<T,3>
{
typedef T type;
T x;
T y;
T z;
typedef T type;
T x;
T y;
T z;
public:
coord()
: x(),y(),z() {}
coord(T x,T y,T z)
: x(x),y(y),z(z) {}
template <typename T2>
coord (const coord<T2,3>& rhs)
: x(type(rhs.x)),
y(type(rhs.y)),
z(type(rhs.z)) {}
coord()
: x(),y(),z() {}
coord(T x,T y,T z)
: x(x),y(y),z(z) {}
template <typename T2>
coord (const coord<T2,3>& rhs)
: x(type(rhs.x)),
y(type(rhs.y)),
z(type(rhs.z)) {}
template <typename T2>
coord<T,3>& operator=(const coord<T2,3>& rhs)
{
if ((void*)this==(void*)&rhs)
{
return *this;
}
x=type(rhs.x);
y=type(rhs.y);
z=type(rhs.z);
return *this;
}
template <typename T2>
coord<T,3>& operator=(const coord<T2,3>& rhs)
{
if ((void*)this==(void*)&rhs)
{
return *this;
}
x=type(rhs.x);
y=type(rhs.y);
z=type(rhs.z);
return *this;
}
};
typedef coord<double,2> coord2d;
@ -103,12 +103,12 @@ namespace mapnik
template <typename charT,typename traits,typename T ,int dim>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
const coord<T,dim>& c);
const coord<T,dim>& c);
template <typename charT,typename traits,typename T>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
const coord<T,2>& c)
const coord<T,2>& c)
{
std::basic_ostringstream<charT,traits> s;
s.copyfmt(out);
@ -121,7 +121,7 @@ namespace mapnik
template <typename charT,typename traits,typename T>
inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out,
const coord<T,3>& c)
const coord<T,3>& c)
{
std::basic_ostringstream<charT,traits> s;
s.copyfmt(out);

View file

@ -32,21 +32,21 @@
namespace mapnik
{
template <typename key_type,
typename product_type>
typename product_type>
class default_factory_error
{
public:
struct factory_exception : public std::exception
{
const char* what() const throw()
{
return "uknown object type";
}
};
static product_type* on_unknown_type(const key_type&)
{
return 0;
}
struct factory_exception : public std::exception
{
const char* what() const throw()
{
return "uknown object type";
}
};
static product_type* on_unknown_type(const key_type&)
{
return 0;
}
};
template
@ -55,34 +55,34 @@ namespace mapnik
typename key_type,
typename product_creator=product_type* (*)(),
template <typename,typename> class factory_error_policy=default_factory_error
>
>
class factory : public singleton<factory <product_type,key_type,product_creator,factory_error_policy> >,
factory_error_policy <key_type,product_type>
factory_error_policy <key_type,product_type>
{
private:
typedef std::map<key_type,product_creator> product_map;
product_map map_;
typedef std::map<key_type,product_creator> product_map;
product_map map_;
public:
bool register_product(const key_type& key,product_creator creator)
{
return map_.insert(typename product_map::value_type(key,creator)).second;
}
bool register_product(const key_type& key,product_creator creator)
{
return map_.insert(typename product_map::value_type(key,creator)).second;
}
bool unregister_product(const key_type& key)
{
return map_.erase(key)==1;
}
bool unregister_product(const key_type& key)
{
return map_.erase(key)==1;
}
product_type* create_object(const key_type& key,const std::string& file)
{
typename product_map::const_iterator pos=map_.find(key);
if (pos!=map_.end())
{
return (pos->second)(file);
}
return on_unknown_type(key);
}
product_type* create_object(const key_type& key,const std::string& file)
{
typename product_map::const_iterator pos=map_.find(key);
if (pos!=map_.end())
{
return (pos->second)(file);
}
return on_unknown_type(key);
}
};
}
#endif //FACTORY_HPP

View file

@ -27,7 +27,7 @@
#include <vector>
#include <iostream>
#include <boost/progress.hpp>
#include "envelope.hpp"
#include "datasource.hpp"
#include "layer.hpp"
@ -37,7 +37,6 @@
namespace mapnik
{
template <typename Processor>
class feature_style_processor
{
@ -61,7 +60,7 @@ namespace mapnik
void apply()
{
timer clock;
boost::progress_timer t;
Processor & p = static_cast<Processor&>(*this);
p.start_map_processing(m_);
@ -76,11 +75,7 @@ namespace mapnik
}
++itr;
}
p.end_map_processing(m_);
clock.stop();
}
private:
void apply_to_layer(Layer const& lay,Processor & p)

View file

@ -35,30 +35,30 @@ namespace mapnik
class filter_to_string : public filter_visitor<FeatureT>
{
private:
std::string text_;
std::string text_;
public:
filter_to_string() {}
void visit(filter<FeatureT>& /*filter*/)
{
//not interested
}
void visit(expression<FeatureT>& exp)
{
property<FeatureT>* pf;
if ((pf = dynamic_cast<property<FeatureT>*>(&exp)))
{
names_.insert(pf->name());
}
}
std::string const& text() const
{
return text_;
}
filter_to_string() {}
void visit(filter<FeatureT>& /*filter*/)
{
//not interested
}
void visit(expression<FeatureT>& exp)
{
property<FeatureT>* pf;
if ((pf = dynamic_cast<property<FeatureT>*>(&exp)))
{
names_.insert(pf->name());
}
}
std::string const& text() const
{
return text_;
}
virtual ~filter_to_string() {}
virtual ~filter_to_string() {}
private:
filter_to_string(filter_to_string const&);
filter_to_string& operator=(filter_to_string const&);
filter_to_string(filter_to_string const&);
filter_to_string& operator=(filter_to_string const&);
};
}

View file

@ -30,10 +30,10 @@ namespace mapnik
class MAPNIK_DECL ImageUtils
{
public:
static void save_to_file(const std::string& filename,const std::string& type,const Image32& image);
static void save_to_file(const std::string& filename,const std::string& type,const Image32& image);
private:
static void save_as_png(const std::string& filename,const Image32& image);
static void save_as_jpeg(const std::string& filename,int quality, const Image32& image);
static void save_as_png(const std::string& filename,const Image32& image);
static void save_as_jpeg(const std::string& filename,int quality, const Image32& image);
};
template <typename T>
@ -121,7 +121,7 @@ namespace mapnik
namespace
{
template <typename Image>
inline void scale_up(Image& target,const Image& source,unsigned scale)
inline void scale_up(Image& target,const Image& source,unsigned scale)
{
int source_width=source.width();
int source_height=source.height();

View file

@ -28,25 +28,25 @@ namespace mapnik
{
struct point_
{
double x;
double y;
point_()
: x(0),y(0) {}
point_(double x_,double y_)
: x(x_),y(y_) {}
double x;
double y;
point_()
: x(0),y(0) {}
point_(double x_,double y_)
: x(x_),y(y_) {}
};
class label_placement
{
private:
point_ anchor_;
point_ displacement_;
double rotation_;
point_ anchor_;
point_ displacement_;
double rotation_;
public:
label_placement()
: anchor_(),
displacement_(),
rotation_(0.0) {}
label_placement()
: anchor_(),
displacement_(),
rotation_(0.0) {}
};
}

View file

@ -35,174 +35,174 @@ namespace mapnik
template <typename T>
class quad_tree : boost::noncopyable
{
struct node
{
typedef T value_t;
typedef std::vector<T> cont_t;
typedef typename cont_t::iterator iterator;
typedef typename cont_t::const_iterator const_iterator;
Envelope<double> extent_;
cont_t cont_;
node * children_[4];
struct node
{
typedef T value_t;
typedef std::vector<T> cont_t;
typedef typename cont_t::iterator iterator;
typedef typename cont_t::const_iterator const_iterator;
Envelope<double> extent_;
cont_t cont_;
node * children_[4];
explicit node(Envelope<double> const& ext)
: extent_(ext)
{
std::memset(children_,0,4*sizeof(node*));
}
explicit node(Envelope<double> const& ext)
: extent_(ext)
{
std::memset(children_,0,4*sizeof(node*));
}
Envelope<double> const& extent() const
{
return extent_;
}
Envelope<double> const& extent() const
{
return extent_;
}
iterator begin()
{
return cont_.begin();
}
iterator begin()
{
return cont_.begin();
}
const_iterator begin() const
{
return cont_.begin();
}
const_iterator begin() const
{
return cont_.begin();
}
iterator end()
{
return cont_.end();
}
iterator end()
{
return cont_.end();
}
const_iterator end() const
{
return cont_.end();
}
~node () {}
};
const_iterator end() const
{
return cont_.end();
}
~node () {}
};
typedef boost::ptr_vector<node> nodes_t;
typedef typename node::cont_t cont_t;
typedef typename cont_t::iterator node_data_iterator;
typedef boost::ptr_vector<node> nodes_t;
typedef typename node::cont_t cont_t;
typedef typename cont_t::iterator node_data_iterator;
nodes_t nodes_;
node * root_;
const double ratio_;
nodes_t nodes_;
node * root_;
const double ratio_;
public:
typedef typename nodes_t::iterator iterator;
typedef typename nodes_t::const_iterator const_iterator;
typedef typename boost::ptr_vector<T,boost::view_clone_allocator> result_t;
typedef typename result_t::iterator query_iterator;
typedef typename nodes_t::iterator iterator;
typedef typename nodes_t::const_iterator const_iterator;
typedef typename boost::ptr_vector<T,boost::view_clone_allocator> result_t;
typedef typename result_t::iterator query_iterator;
result_t query_result_;
result_t query_result_;
explicit quad_tree(Envelope<double> const& ext,double ratio=0.55)
: ratio_(ratio)
{
nodes_.push_back(new node(ext));
root_ = &nodes_[0];
}
explicit quad_tree(Envelope<double> const& ext,double ratio=0.55)
: ratio_(ratio)
{
nodes_.push_back(new node(ext));
root_ = &nodes_[0];
}
void insert(T data, Envelope<double> const& box)
{
do_insert_data(data,box,root_);
}
void insert(T data, Envelope<double> const& box)
{
do_insert_data(data,box,root_);
}
query_iterator query_in_box(Envelope<double> const& box)
{
query_result_.clear();
query_node(box,query_result_,root_);
return query_result_.begin();
}
query_iterator query_in_box(Envelope<double> const& box)
{
query_result_.clear();
query_node(box,query_result_,root_);
return query_result_.begin();
}
query_iterator query_end()
{
return query_result_.end();
}
query_iterator query_end()
{
return query_result_.end();
}
iterator begin()
{
return nodes_.begin();
}
iterator begin()
{
return nodes_.begin();
}
const_iterator begin() const
{
return nodes_.begin();
}
const_iterator begin() const
{
return nodes_.begin();
}
iterator end()
{
return nodes_.end();
}
iterator end()
{
return nodes_.end();
}
const_iterator end() const
{
return nodes_.end();
}
const_iterator end() const
{
return nodes_.end();
}
private:
void query_node(Envelope<double> const& box, result_t & result, node * node_) const
{
if (node_)
{
Envelope<double> const& node_extent = node_->extent();
if (box.intersects(node_extent))
{
node_data_iterator i=node_->begin();
node_data_iterator end=node_->end();
while ( i!=end)
{
result.push_back(&(*i));
++i;
}
for (int k = 0; k < 4; ++k)
{
query_node(box,result,node_->children_[k]);
}
}
}
}
void query_node(Envelope<double> const& box, result_t & result, node * node_) const
{
if (node_)
{
Envelope<double> const& node_extent = node_->extent();
if (box.intersects(node_extent))
{
node_data_iterator i=node_->begin();
node_data_iterator end=node_->end();
while ( i!=end)
{
result.push_back(&(*i));
++i;
}
for (int k = 0; k < 4; ++k)
{
query_node(box,result,node_->children_[k]);
}
}
}
}
void do_insert_data(T data, Envelope<double> const& box, node * n)
{
if (n)
{
Envelope<double> const& node_extent = n->extent();
Envelope<double> ext[4];
split_box(node_extent,ext);
for (int i=0;i<4;++i)
{
if (ext[i].contains(box))
{
if (!n->children_[i])
{
nodes_.push_back(new node(ext[i]));
n->children_[i]=&nodes_.back();
}
do_insert_data(data,box,n->children_[i]);
return;
}
}
n->cont_.push_back(data);
}
}
void do_insert_data(T data, Envelope<double> const& box, node * n)
{
if (n)
{
Envelope<double> const& node_extent = n->extent();
Envelope<double> ext[4];
split_box(node_extent,ext);
for (int i=0;i<4;++i)
{
if (ext[i].contains(box))
{
if (!n->children_[i])
{
nodes_.push_back(new node(ext[i]));
n->children_[i]=&nodes_.back();
}
do_insert_data(data,box,n->children_[i]);
return;
}
}
n->cont_.push_back(data);
}
}
void split_box(Envelope<double> const& node_extent,Envelope<double> * ext)
{
coord2d c=node_extent.center();
void split_box(Envelope<double> const& node_extent,Envelope<double> * ext)
{
coord2d c=node_extent.center();
double width=node_extent.width();
double height=node_extent.height();
double width=node_extent.width();
double height=node_extent.height();
double lox=node_extent.minx();
double loy=node_extent.miny();
double hix=node_extent.maxx();
double hiy=node_extent.maxy();
double lox=node_extent.minx();
double loy=node_extent.miny();
double hix=node_extent.maxx();
double hiy=node_extent.maxy();
ext[0]=Envelope<double>(lox,loy,lox + width * ratio_,loy + height * ratio_);
ext[1]=Envelope<double>(hix - width * ratio_,loy,hix,loy + height * ratio_);
ext[2]=Envelope<double>(lox,hiy - height*ratio_,lox + width * ratio_,hiy);
ext[3]=Envelope<double>(hix - width * ratio_,hiy - height*ratio_,hix,hiy);
}
ext[0]=Envelope<double>(lox,loy,lox + width * ratio_,loy + height * ratio_);
ext[1]=Envelope<double>(hix - width * ratio_,loy,hix,loy + height * ratio_);
ext[2]=Envelope<double>(lox,hiy - height*ratio_,lox + width * ratio_,hiy);
ext[3]=Envelope<double>(hix - width * ratio_,hiy - height*ratio_,hix,hiy);
}
};
}

View file

@ -28,16 +28,16 @@
namespace mapnik
{
typedef factory<ImageReader,std::string,
ImageReader* (*)(const std::string&)> ImageReaderFactory;
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);
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);
return ImageReaderFactory::instance()->create_object(type,file);
}
}