2005-06-14 17:06:59 +02:00
|
|
|
/* This file is part of python_mapnik (c++/python mapping toolkit)
|
|
|
|
* Copyright (C) 2005 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* Mapnik is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//$Id: mapnik_parameters.cc 17 2005-03-08 23:58:43Z pavlenko $
|
|
|
|
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <boost/python/detail/api_placeholder.hpp>
|
2005-12-01 11:04:17 +01:00
|
|
|
#include <mapnik.hpp>
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
using mapnik::parameter;
|
|
|
|
using mapnik::parameters;
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
//void (parameters::*add1)(const parameter&)=¶meters::insert;
|
|
|
|
//void (parameters::*add2)(std::make_pair(const std::string&,const std::string&))=¶meters::insert;
|
2005-06-14 17:06:59 +02:00
|
|
|
|
|
|
|
struct parameter_pickle_suite : boost::python::pickle_suite
|
|
|
|
{
|
|
|
|
static boost::python::tuple
|
2005-12-14 18:01:09 +01:00
|
|
|
getinitargs(const parameter& p)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
using namespace boost::python;
|
|
|
|
return boost::python::make_tuple(p.first,p.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct parameters_pickle_suite : boost::python::pickle_suite
|
|
|
|
{
|
|
|
|
static boost::python::tuple
|
2005-12-14 18:01:09 +01:00
|
|
|
getstate(const parameters& p)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
using namespace boost::python;
|
|
|
|
dict d;
|
2005-12-14 18:01:09 +01:00
|
|
|
parameters::const_iterator pos=p.begin();
|
2005-06-14 17:06:59 +02:00
|
|
|
while(pos!=p.end())
|
|
|
|
{
|
|
|
|
d[pos->first]=pos->second;
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
return boost::python::make_tuple(d);
|
|
|
|
}
|
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
static void setstate(parameters& p, boost::python::tuple state)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
using namespace boost::python;
|
|
|
|
if (len(state) != 1)
|
|
|
|
{
|
|
|
|
PyErr_SetObject(PyExc_ValueError,
|
|
|
|
("expected 1-item tuple in call to __setstate__; got %s"
|
|
|
|
% state).ptr()
|
|
|
|
);
|
|
|
|
throw_error_already_set();
|
|
|
|
}
|
|
|
|
dict d = extract<dict>(state[0]);
|
2005-09-08 15:20:37 +02:00
|
|
|
boost::python::list keys=d.keys();
|
2005-06-14 17:06:59 +02:00
|
|
|
for (int i=0;i<len(keys);++i)
|
|
|
|
{
|
|
|
|
std::string key=extract<std::string>(keys[i]);
|
|
|
|
std::string value=extract<std::string>(d[key]);
|
2005-12-14 18:01:09 +01:00
|
|
|
p[key] = value;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void export_parameters()
|
|
|
|
{
|
|
|
|
using namespace boost::python;
|
2005-12-14 18:01:09 +01:00
|
|
|
class_<parameter>("parameter",init<std::string,std::string>())
|
2005-06-14 17:06:59 +02:00
|
|
|
.def_pickle(parameter_pickle_suite())
|
|
|
|
;
|
|
|
|
|
2005-12-14 18:01:09 +01:00
|
|
|
class_<parameters>("parameters",init<>())
|
|
|
|
//.def("add",add1)
|
|
|
|
//.def("add",add2)
|
|
|
|
.def("get",¶meters::get)
|
2005-06-14 17:06:59 +02:00
|
|
|
.def_pickle(parameters_pickle_suite())
|
|
|
|
;
|
|
|
|
}
|