From 007927ebcbda6132d69783e79b35611793547435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Jaroszy=C5=84ski?= Date: Mon, 13 Aug 2007 16:28:42 +0000 Subject: (python) Headers clean up. --- python/action.cc | 3 +- python/contents.cc | 3 +- python/dep_list.cc | 3 +- python/dep_spec.cc | 5 ++- python/dep_tag.cc | 5 ++- python/environment.cc | 3 +- python/fs_entry.cc | 3 +- python/iterable.hh | 49 ++++++++++++++++++++++++ python/log.cc | 2 +- python/mask.cc | 3 +- python/metadata_key.cc | 2 +- python/metadata_key.hh | 2 +- python/name.cc | 7 ++-- python/options.hh | 87 ++++++++++++++++++++++++++++++++++++++++++ python/package_database.cc | 3 +- python/package_id.cc | 4 +- python/paludis_python.hh | 87 ------------------------------------------ python/paludis_python_so.cc | 3 +- python/qa.cc | 9 +++-- python/query.cc | 2 +- python/repository.cc | 4 +- python/validated.hh | 48 +++++++++++++++++++++++ python/version_operator.cc | 3 +- python/version_requirements.cc | 4 +- python/version_spec.cc | 6 ++- 25 files changed, 230 insertions(+), 120 deletions(-) create mode 100644 python/iterable.hh create mode 100644 python/options.hh create mode 100644 python/validated.hh diff --git a/python/action.cc b/python/action.cc index 7fd9287..0b7ff8c 100644 --- a/python/action.cc +++ b/python/action.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include diff --git a/python/contents.cc b/python/contents.cc index c98ccc4..9bf3170 100644 --- a/python/contents.cc +++ b/python/contents.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include + #include #include diff --git a/python/dep_list.cc b/python/dep_list.cc index a840051..6b6f282 100644 --- a/python/dep_list.cc +++ b/python/dep_list.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include diff --git a/python/dep_spec.cc b/python/dep_spec.cc index fb14f25..b3e1af5 100644 --- a/python/dep_spec.cc +++ b/python/dep_spec.cc @@ -17,8 +17,9 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include +#include "dep_spec.hh" +#include +#include #include #include diff --git a/python/dep_tag.cc b/python/dep_tag.cc index b0491c4..471b9e9 100644 --- a/python/dep_tag.cc +++ b/python/dep_tag.cc @@ -17,11 +17,12 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include +#include #include #include -#include #include using namespace paludis; diff --git a/python/environment.cc b/python/environment.cc index 34419de..8599e6a 100644 --- a/python/environment.cc +++ b/python/environment.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include diff --git a/python/fs_entry.cc b/python/fs_entry.cc index 20af921..4e46ff5 100644 --- a/python/fs_entry.cc +++ b/python/fs_entry.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include diff --git a/python/iterable.hh b/python/iterable.hh new file mode 100644 index 0000000..cd1be99 --- /dev/null +++ b/python/iterable.hh @@ -0,0 +1,49 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2007 Piotr Jaroszyński + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis 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 + */ + +#ifndef PALUDIS_GUARD_PYTHON_ITERABLE_HH +#define PALUDIS_GUARD_PYTHON_ITERABLE_HH 1 + +#include + +#include +#include + +namespace paludis +{ + namespace python + { + // expose iterable classes + template + class class_iterable : + public boost::python::class_ + { + public: + class_iterable(const std::string & name, const std::string & class_doc) : + boost::python::class_(name.c_str(), class_doc.c_str(), + boost::python::no_init) + { + this->def("__iter__", boost::python::range(&C_::begin, &C_::end)); + register_shared_ptrs_to_python(); + } + }; + } // namespace paludis::python +} // namespace paludis + +#endif diff --git a/python/log.cc b/python/log.cc index 1b2efdb..365332b 100644 --- a/python/log.cc +++ b/python/log.cc @@ -17,7 +17,7 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include diff --git a/python/mask.cc b/python/mask.cc index c9cd5dd..cbd5a9c 100644 --- a/python/mask.cc +++ b/python/mask.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include diff --git a/python/metadata_key.cc b/python/metadata_key.cc index 3c96955..fbfb722 100644 --- a/python/metadata_key.cc +++ b/python/metadata_key.cc @@ -18,7 +18,7 @@ */ #include "metadata_key.hh" -#include +#include #include #include diff --git a/python/metadata_key.hh b/python/metadata_key.hh index e7d2e2d..07e330f 100644 --- a/python/metadata_key.hh +++ b/python/metadata_key.hh @@ -20,7 +20,7 @@ #ifndef PYTHON_GUARD_PYTHON_METADATA_KEY_HH #define PYTHON_GUARD_PYTHON_METADATA_KEY_HH 1 -#include +#include #include diff --git a/python/name.cc b/python/name.cc index d341a3d..548f477 100644 --- a/python/name.cc +++ b/python/name.cc @@ -17,11 +17,12 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include +#include +#include #include -#include -#include #include using namespace paludis; diff --git a/python/options.hh b/python/options.hh new file mode 100644 index 0000000..641fc64 --- /dev/null +++ b/python/options.hh @@ -0,0 +1,87 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2007 Piotr Jaroszyński + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis 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 + */ + +#ifndef PALUDIS_GUARD_PYTHON_OPTIONS_HH +#define PALUDIS_GUARD_PYTHON_OPTIONS_HH 1 + +#include + +#include + +namespace paludis +{ + namespace python + { + // expose Options classes + template + class class_options : + public boost::python::class_ + { + public: + class_options(const std::string & set_name, const std::string & bit_name, + const std::string & class_doc) : + boost::python::class_(set_name.c_str(), class_doc.c_str(), + boost::python::init<>("__init__()")) + { + this->add_property("any", &O_::any, + "[ro] bool\n" + "Is any bit enabled." + ); + this->add_property("none", &O_::none, + "[ro] bool\n" + "Are all bits disabled." + ); + this->def("__add__", &O_::operator+, + ("__add__("+bit_name+") -> "+set_name+"\n" + "Return a copy of ourself with the specified bit enabled.").c_str() + ); + this->def("__iadd__", &O_::operator+=, boost::python::return_self<>(), + ("__iadd__("+bit_name+") -> "+set_name+"\n" + "Enable the specified bit.").c_str() + ); + this->def("__sub__", &O_::operator-, + ("__sub__("+bit_name+") -> "+set_name+"\n" + "Return a copy of ourself with the specified bit disabled.").c_str() + ); + this->def("__isub__", &O_::operator-=, boost::python::return_self<>(), + ("__isub__("+bit_name+") -> "+set_name+"\n" + "Disable the specified bit.").c_str() + ); + this->def("__or__", &O_::operator|, + ("__or__("+set_name+") -> "+set_name+"\n" + "Return a copy of ourself, bitwise 'or'ed with another Options set.").c_str() + ); + this->def("__ior__", &O_::operator|=, boost::python::return_self<>(), + ("__ior__("+set_name+") -> "+set_name+"\n" + "Enable any bits that are enabled in the parameter.").c_str() + ); + this->def("__getitem__", &O_::operator[], + ("__getitem__("+bit_name+") -> bool\n" + "Returns whether the specified bit is enabled.").c_str() + ); + this->def("subtract", &O_::subtract, boost::python::return_self<>(), + ("subtract("+set_name+") -> "+set_name+"\n" + "Disable any bits that are enabled in the parameter.").c_str() + ); + } + }; + } // namespace paludis::python +} // namespace paludis + +#endif diff --git a/python/package_database.cc b/python/package_database.cc index e463c9a..9b283d3 100644 --- a/python/package_database.cc +++ b/python/package_database.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include diff --git a/python/package_id.cc b/python/package_id.cc index a936718..d2645bd 100644 --- a/python/package_id.cc +++ b/python/package_id.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/python/paludis_python.hh b/python/paludis_python.hh index 68c5e87..95e9ebb 100644 --- a/python/paludis_python.hh +++ b/python/paludis_python.hh @@ -20,7 +20,6 @@ #ifndef PALUDIS_GUARD_PYTHON_PALUDIS_PYTHON_HH #define PALUDIS_GUARD_PYTHON_PALUDIS_PYTHON_HH 1 -#include #include #include @@ -132,92 +131,6 @@ namespace paludis return ! (a == b); } - // expose Validated classes - template - class class_validated : - public boost::python::class_ - { - public: - class_validated(const std::string & name, - const std::string & class_doc, const std::string & init_arg="string") : - boost::python::class_(name.c_str(), class_doc.c_str(), - boost::python::init(("__init__("+init_arg+")").c_str()) - ) - { - this->def(boost::python::self_ns::str(boost::python::self)); - boost::python::implicitly_convertible(); - } - }; - - // expose iterable classes - template - class class_iterable : - public boost::python::class_ - { - public: - class_iterable(const std::string & name, const std::string & class_doc) : - boost::python::class_(name.c_str(), class_doc.c_str(), - boost::python::no_init) - { - this->def("__iter__", boost::python::range(&C_::begin, &C_::end)); - register_shared_ptrs_to_python(); - } - }; - - // expose Options classes - template - class class_options : - public boost::python::class_ - { - public: - class_options(const std::string & set_name, const std::string & bit_name, - const std::string & class_doc) : - boost::python::class_(set_name.c_str(), class_doc.c_str(), - boost::python::init<>("__init__()")) - { - this->add_property("any", &O_::any, - "[ro] bool\n" - "Is any bit enabled." - ); - this->add_property("none", &O_::none, - "[ro] bool\n" - "Are all bits disabled." - ); - this->def("__add__", &O_::operator+, - ("__add__("+bit_name+") -> "+set_name+"\n" - "Return a copy of ourself with the specified bit enabled.").c_str() - ); - this->def("__iadd__", &O_::operator+=, boost::python::return_self<>(), - ("__iadd__("+bit_name+") -> "+set_name+"\n" - "Enable the specified bit.").c_str() - ); - this->def("__sub__", &O_::operator-, - ("__sub__("+bit_name+") -> "+set_name+"\n" - "Return a copy of ourself with the specified bit disabled.").c_str() - ); - this->def("__isub__", &O_::operator-=, boost::python::return_self<>(), - ("__isub__("+bit_name+") -> "+set_name+"\n" - "Disable the specified bit.").c_str() - ); - this->def("__or__", &O_::operator|, - ("__or__("+set_name+") -> "+set_name+"\n" - "Return a copy of ourself, bitwise 'or'ed with another Options set.").c_str() - ); - this->def("__ior__", &O_::operator|=, boost::python::return_self<>(), - ("__ior__("+set_name+") -> "+set_name+"\n" - "Enable any bits that are enabled in the parameter.").c_str() - ); - this->def("__getitem__", &O_::operator[], - ("__getitem__("+bit_name+") -> bool\n" - "Returns whether the specified bit is enabled.").c_str() - ); - this->def("subtract", &O_::subtract, boost::python::return_self<>(), - ("subtract("+set_name+") -> "+set_name+"\n" - "Disable any bits that are enabled in the parameter.").c_str() - ); - } - }; - // Convert to string template struct to_string diff --git a/python/paludis_python_so.cc b/python/paludis_python_so.cc index be4d429..a51db28 100644 --- a/python/paludis_python_so.cc +++ b/python/paludis_python_so.cc @@ -17,8 +17,7 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - +#include #include void expose_action(); diff --git a/python/qa.cc b/python/qa.cc index 75ba272..9e5ad22 100644 --- a/python/qa.cc +++ b/python/qa.cc @@ -17,10 +17,11 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include +#include #include -#include #include using namespace paludis; @@ -33,8 +34,8 @@ struct QAReporterWrapper : { void message(const QAMessage & msg) { - if (get_override("message")) - get_override("message")(msg); + if (bp::override f = get_override("message")) + f(msg); else throw PythonMethodNotImplemented("QAReporter", "message"); } diff --git a/python/query.cc b/python/query.cc index 84d7450..18b23b8 100644 --- a/python/query.cc +++ b/python/query.cc @@ -17,7 +17,7 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include diff --git a/python/repository.cc b/python/repository.cc index ba225e6..26b660f 100644 --- a/python/repository.cc +++ b/python/repository.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include #include #include diff --git a/python/validated.hh b/python/validated.hh new file mode 100644 index 0000000..cf71209 --- /dev/null +++ b/python/validated.hh @@ -0,0 +1,48 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2007 Piotr Jaroszyński + * + * This file is part of the Paludis package manager. Paludis is free software; + * you can redistribute it and/or modify it under the terms of the GNU General + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis 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 + */ + +#ifndef PALUDIS_GUARD_PYTHON_VALIDATED_HH +#define PALUDIS_GUARD_PYTHON_VALIDATED_HH 1 + +#include + +namespace paludis +{ + namespace python + { + // expose Validated classes + template + class class_validated : + public boost::python::class_ + { + public: + class_validated(const std::string & name, + const std::string & class_doc, const std::string & init_arg="string") : + boost::python::class_(name.c_str(), class_doc.c_str(), + boost::python::init(("__init__("+init_arg+")").c_str()) + ) + { + this->def(boost::python::self_ns::str(boost::python::self)); + boost::python::implicitly_convertible(); + } + }; + } // namespace paludis::python +} // namespace paludis + +#endif diff --git a/python/version_operator.cc b/python/version_operator.cc index 00dd9a5..eacb1a4 100644 --- a/python/version_operator.cc +++ b/python/version_operator.cc @@ -17,7 +17,8 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include #include diff --git a/python/version_requirements.cc b/python/version_requirements.cc index b0adc9a..d88cc6c 100644 --- a/python/version_requirements.cc +++ b/python/version_requirements.cc @@ -17,10 +17,10 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include +#include #include -#include #include using namespace paludis; diff --git a/python/version_spec.cc b/python/version_spec.cc index ae1dca7..1e50106 100644 --- a/python/version_spec.cc +++ b/python/version_spec.cc @@ -17,9 +17,11 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include +#include +#include + #include +#include using namespace paludis; using namespace paludis::python; -- cgit v1.0