00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef COORD_ARRAY_HPP
00026 #define COORD_ARRAY_HPP
00027
00028
00029 #include <mapnik/coord.hpp>
00030
00031 #include <cassert>
00032
00033 namespace mapnik {
00034 template <typename T>
00035 class coord_array
00036 {
00037 typedef T coord_type;
00038 coord_type* pt_;
00039 const unsigned size_;
00040 public:
00041 coord_array(unsigned size=0)
00042 : pt_(static_cast<coord_type*>(size==0?0: ::operator new (sizeof(coord_type)*size))),
00043 size_(size) {}
00044
00045 coord_array(const coord_array& rhs)
00046 : pt_(static_cast<coord_type*>(rhs.size_==0?0: ::operator new (sizeof(coord_type)*rhs.size_))),
00047 size_(rhs.size_) {
00048 memcpy(pt_,rhs.pt_,sizeof(coord_type)*rhs.size_);
00049 }
00050
00051 ~coord_array()
00052 {
00053 ::operator delete (pt_);
00054 }
00055
00056 unsigned size() const
00057 {
00058 return size_;
00059 }
00060
00061 void set(unsigned index,double x,double y)
00062 {
00063 assert(index<size_);
00064 pt_[index].x=x;
00065 pt_[index].y=y;
00066 }
00067
00068 const coord_type& at(unsigned index) const
00069 {
00070 assert(index<size_);
00071 return pt_[index];
00072 }
00073
00074 const coord_type& operator[] (unsigned index) const
00075 {
00076 assert (index<size_);
00077 return pt_[index];
00078 }
00079
00080 coord_type& operator[] (unsigned index)
00081 {
00082 assert (index<size_);
00083 return pt_[index];
00084 }
00085
00086 private:
00087 coord_array& operator=(const coord_array&);
00088 };
00089 }
00090
00091
00092 #endif //COORD_ARRAY_HPP