/home/andreas/src/svn/mapnik/include/mapnik/feature.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: feature.hpp 40 2005-04-13 20:20:46Z pavlenko $
00024 
00025 #ifndef FEATURE_HPP
00026 #define FEATURE_HPP
00027 // stl
00028 #include <map>
00029 // boost
00030 #include <boost/property_map.hpp>
00031 #include <boost/utility.hpp>
00032 #include <boost/shared_ptr.hpp>
00033 // mapnik
00034 #include <mapnik/value.hpp>
00035 #include <mapnik/geometry.hpp>
00036 #include <mapnik/raster.hpp>
00037 
00038 namespace mapnik {
00039     typedef boost::shared_ptr<raster> raster_ptr;    
00040     typedef boost::associative_property_map<
00041         std::map<std::string,value
00042                  > > properties;
00043     
00044     template <typename T1,typename T2>
00045     struct feature : public properties,
00046                      private boost::noncopyable
00047     {
00048     public:
00049         typedef T1 geometry_type;
00050         typedef T2 raster_type;
00051       typedef std::map<std::string,value>::value_type value_type;
00052       typedef std::map<std::string,value>::size_type size_type;
00053       
00054     private:
00055         int id_;
00056         geometry_type geom_;
00057         raster_type   raster_;
00058         std::map<std::string,value> props_;
00059     public:
00060         typedef std::map<std::string,value>::iterator iterator;
00061         explicit feature(int id)
00062             : properties(props_),
00063               id_(id),
00064               geom_(),
00065               raster_() {}
00066 
00067         feature(int id,const geometry_type& geom)
00068             : properties(props_),
00069               id_(id),
00070               geom_(geom),
00071               raster_() {}
00072 
00073         int id() const 
00074         {
00075             return id_;
00076         }
00077         
00078         void set_geometry(geometry_type& geom)
00079         {
00080             geom_=geom;
00081         }
00082         
00083         geometry_type const& get_geometry() const
00084         {
00085             return geom_;
00086         }
00087         
00088         const raster_type& get_raster() const
00089         {
00090             return raster_;
00091         }
00092         void set_raster(raster_type const& raster)
00093         {
00094             raster_=raster;
00095         }
00096         
00097         std::map<std::string,value> const& props() const 
00098         {
00099             return props_;
00100         }
00101         
00102         iterator begin() const
00103         {
00104             return props_.begin();
00105         }
00106         
00107         iterator end() const
00108         {
00109             return props_.end();
00110         }
00111         
00112         std::string to_string() const
00113         {
00114             std::stringstream ss;
00115             ss << "feature (" << std::endl;
00116             for (std::map<std::string,value>::const_iterator itr=props_.begin();
00117                  itr != props_.end();++itr)
00118             {
00119                 ss << "  " << itr->first  << ":" <<  itr->second << std::endl;
00120             }
00121             ss << ")" << std::endl;
00122             return ss.str();
00123         }
00124     };
00125 
00126     typedef feature<geometry_ptr,raster_ptr> Feature;
00127     
00128     inline std::ostream& operator<< (std::ostream & out,Feature const& f)
00129     {
00130         out << f.to_string();
00131         return out;
00132     }
00133 }
00134 
00135 #endif //FEATURE_HPP

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