Exheredludis/python/choices.cc
David Leverton 64f0d9760e Another attempt at new Boost compatibility
Instead of weird hacks with const_cast that aren't compatible with
Boost's get_pointer implementation for shared_ptr, use non-const
pointers as the representation and register conversions, like most of
the classes did already.
2013-08-27 21:56:44 +01:00

170 lines
5.5 KiB
C++

/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
* Copyright (c) 2008, 2010, 2011 Ciaran McCreesh
*
* 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
*/
#include <python/paludis_python.hh>
#include <python/exception.hh>
#include <python/wrapped_value.hh>
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/choice.hh>
using namespace paludis;
using namespace paludis::python;
namespace bp = boost::python;
void expose_choices()
{
register_shared_ptrs_to_python<Choices>(rsp_const);
bp::class_<Choices, std::shared_ptr<Choices>, boost::noncopyable> choices(
"Choices",
"A collection of configurable values for a PackageID",
bp::init<>("__init__()")
);
choices
.def("find_by_name_with_prefix", &Choices::find_by_name_with_prefix,
"find_by_name_with_prefix(ChoiceNameWithPrefix) -> ChoiceValue or nil\n"
)
.def("has_matching_contains_every_value_prefix", &Choices::has_matching_contains_every_value_prefix,
"has_matching_contains_every_value_prefix(ChoiceNameWithPrefix) -> bool\n"
)
.def("__iter__", bp::range(&Choices::begin, &Choices::end),
"[ro] Iterable of Choice\n"
)
;
register_shared_ptrs_to_python<Choice>(rsp_const);
bp::class_<Choice, std::shared_ptr<Choice>, boost::noncopyable> choice(
"Choice",
"An individual choice in a Choices collection.",
bp::no_init
);
choice
.add_property("raw_name", &Choice::raw_name,
"[ro] String\n"
)
.add_property("human_name", &Choice::human_name,
"[ro] String\n"
)
.add_property("prefix", &Choice::prefix,
"[ro] ChoicePrefixName\n"
)
.add_property("contains_every_value", &Choice::contains_every_value,
"[ro] bool\n"
)
.add_property("hidden", &Choice::hidden,
"[ro] bool\n"
)
.add_property("show_with_no_prefix", &Choice::show_with_no_prefix,
"[ro] bool\n"
)
.add_property("consider_added_or_changed", &Choice::consider_added_or_changed,
"[ro] bool\n"
)
.def("__iter__", bp::range(&Choice::begin, &Choice::end),
"[ro] Iterable of ChoiceValue\n"
)
;
register_shared_ptrs_to_python<ChoiceValue>(rsp_const);
bp::class_<ChoiceValue, std::shared_ptr<ChoiceValue>, boost::noncopyable> choice_value(
"ChoiceValue",
"An individual value in a ChoiceValue",
bp::no_init
);
choice_value
.add_property("unprefixed_name", &ChoiceValue::unprefixed_name,
"[ro] UnprefixedChoiceName\n"
)
.add_property("name_with_prefix", &ChoiceValue::name_with_prefix,
"[ro] ChoiceNameWithPrefix\n"
)
.add_property("enabled", &ChoiceValue::enabled,
"[ro] bool\n"
)
.add_property("enabled_by_default", &ChoiceValue::enabled_by_default,
"[ro] bool\n"
)
.add_property("locked", &ChoiceValue::locked,
"[ro] bool\n"
)
.add_property("description", &ChoiceValue::description,
"[ro] String\n"
)
.add_property("origin", &ChoiceValue::origin,
"[ro] ChoiceOrigin\n"
)
;
ExceptionRegister::get_instance()->add_exception<ChoiceNameWithPrefixError>
("ChoiceNameWithPrefixError", "NameError",
"Thrown if an invalid value is assigned to a ChoiceNameWithPrefix.");
register_shared_ptrs_to_python<ChoiceNameWithPrefix>();
class_wrapped_value<ChoiceNameWithPrefix>
(
"ChoiceNameWithPrefix",
"A choice name, including prefix and delim."
);
ExceptionRegister::get_instance()->add_exception<ChoicePrefixNameError>
("ChoicePrefixNameError", "NameError",
"Thrown if an invalid value is assigned to a ChoicePrefixName.");
register_shared_ptrs_to_python<ChoicePrefixName>();
class_wrapped_value<ChoicePrefixName>
(
"ChoicePrefixName",
"A choice prefix name."
);
ExceptionRegister::get_instance()->add_exception<UnprefixedChoiceNameError>
("UnprefixedChoiceNameError", "NameError",
"Thrown if an invalid value is assigned to an UnprefixedChoiceName.");
register_shared_ptrs_to_python<UnprefixedChoiceName>();
class_wrapped_value<UnprefixedChoiceName>
(
"UnprefixedChoiceName",
"A choice name, without prefix."
);
enum_auto("ChoiceOrigin", last_co,
"The origin of a ChoiceValue");
}