/home/andreas/src/svn/mapnik/include/mapnik/vertex.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 //$Id: vertex.hpp 39 2005-04-10 20:39:53Z pavlenko $
00023 
00024 #ifndef VERTEX_HPP
00025 #define VERTEX_HPP
00026 
00027 #include <iostream>
00028 #include <sstream>
00029 
00030 namespace mapnik 
00031 {
00032     enum CommandType {
00033         SEG_END   =0,
00034         SEG_MOVETO=1,
00035         SEG_LINETO=2,
00036         SEG_CLOSE =3
00037     };
00038     
00039     template <typename T,int dim>
00040     struct vertex {
00041         typedef T type;
00042     };
00043     
00044     template <typename T>
00045     struct vertex<T,2> 
00046     {
00047         typedef T type;
00048         T x;
00049         T y;
00050         unsigned cmd;
00051         vertex() 
00052             : x(0),y(0),cmd(SEG_END) {}
00053         vertex(T x,T y,unsigned cmd)
00054             : x(x),y(y),cmd(cmd) {}
00055 
00056         template <typename T2>
00057         vertex(const vertex<T2,2>& rhs)
00058             : x(type(rhs.x)),
00059               y(type(rhs.y)),
00060               cmd(rhs.cmd) {}
00061         
00062         template <typename T2> vertex<T,2> operator=(const vertex<T2,2>& rhs)
00063         {
00064             if ((void*)this == (void*)&rhs)
00065             {
00066                 return *this;
00067             }
00068             x=type(rhs.x);
00069             y=type(rhs.y);
00070             cmd=rhs.cmd;
00071             return *this;
00072         }       
00073     };
00074     
00075     typedef vertex<double,2> vertex2d;
00076     typedef vertex<int,2> vertex2i;
00077 
00078     
00079     template <class charT,class traits,class T,int dim>
00080     inline std::basic_ostream<charT,traits>&
00081     operator << (std::basic_ostream<charT,traits>& out,
00082                  const vertex<T,dim>& c);
00083 
00084     template <class charT,class traits,class T>
00085     inline std::basic_ostream<charT,traits>&
00086     operator << (std::basic_ostream<charT,traits>& out,
00087                  const vertex<T,2>& v)
00088     {
00089         std::basic_ostringstream<charT,traits> s;
00090         s.copyfmt(out);
00091         s.width(0);
00092         s<<"vertex2("<<v.x<<","<<v.y<<",cmd="<<v.cmd<<" )";
00093         out << s.str();
00094         return out;
00095     }
00096 
00097     template <class charT,class traits,class T>
00098     inline std::basic_ostream<charT,traits>&
00099     operator << (std::basic_ostream<charT,traits>& out,
00100                  const vertex<T,3>& v)
00101     {
00102         std::basic_ostringstream<charT,traits> s;
00103         s.copyfmt(out);
00104         s.width(0);
00105         s<<"vertex3("<<v.x<<","<<v.y<<","<<v.z<<",cmd="<<v.cmd<<")";
00106         out << s.str();
00107         return out;
00108     } 
00109 
00110 }
00111 
00112 #endif // VERTEX_HPP

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