/home/andreas/src/svn/mapnik/include/mapnik/coord_array.hpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * 
00003  * This file is part of Mapnik (c++ mapping toolkit)
00004  *
00005  * Copyright (C) 2006 Artem Pavlenko
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  *
00021  *****************************************************************************/
00022 
00023 //$Id: coord_array.hpp 39 2005-04-10 20:39:53Z pavlenko $
00024 
00025 #ifndef COORD_ARRAY_HPP
00026 #define COORD_ARRAY_HPP
00027 
00028 // stl
00029 #include <cassert>
00030 //mapnik
00031 #include <mapnik/coord.hpp>
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

Generated on Thu Jul 19 17:59:25 2007 for Mapnik by  doxygen 1.4.7