14#include <boost/python/class.hpp>
15#include <boost/python/copy_const_reference.hpp>
16#include <boost/python/dict.hpp>
17#include <boost/python/iterator.hpp>
18#include <boost/python/list.hpp>
19#include <boost/python/register_ptr_to_python.hpp>
20#include <boost/python/return_internal_reference.hpp>
21#include <boost/python/stl_iterator.hpp>
22#include <boost/python/str.hpp>
40void setProperty(
IPropertyManager &self,
const std::string &name,
const boost::python::object &
value) {
42 if (valuecpp.check()) {
47 const auto &entry = Registry::TypeRegistry::retrieve(*(p->
type_info()));
48 entry.set(&self, name,
value);
49 }
catch (std::invalid_argument &e) {
50 throw std::invalid_argument(
"When converting parameter \"" + name +
"\": " + e.what());
55void setProperties(
IPropertyManager &self,
const boost::python::dict &kwargs) {
56 const object view = kwargs.attr(
"items")();
57 const object objectItems(handle<>(PyObject_GetIter(view.ptr())));
58 auto begin = stl_input_iterator<object>(objectItems);
59 auto end = stl_input_iterator<object>();
60 for (
auto it = begin; it != end; ++it) {
72void declareProperty(
IPropertyManager &self,
const std::string &name,
const boost::python::object &
value) {
73 auto p = std::unique_ptr<Property>(Registry::PropertyWithValueFactory::create(name,
value, 0));
85void declareOrSetProperty(
IPropertyManager &self,
const std::string &name,
const boost::python::object &
value) {
88 setProperty(self, name,
value);
90 declareProperty(self, name,
value);
115 const size_t numProps = props.size();
117 boost::python::list result;
118 for (
size_t i = 0; i < numProps; ++i) {
119 result.append(props[i]->name());
141 return Registry::PropertyWithValueFactory::create(name,
value, 0).release();
147 register_ptr_to_python<IPropertyManager *>();
149 class_<IPropertyManager, boost::noncopyable>(
"IPropertyManager", no_init)
151 "Returns the number of properties being managed")
154 return_internal_reference<>(),
155 "Returns the property of the given name. Use .value to give the "
159 "Returns a string representation of the named property's value")
162 "Returns the list of properties managed by this object")
164 .def(
"declareProperty", &declareProperty, (arg(
"self"), arg(
"name"), arg(
"value")),
"Create a new named property")
167 "Set the value of the named property via a string")
169 .def(
"setProperty", &setProperty, (arg(
"self"), arg(
"name"), arg(
"value")),
"Set the value of the named property")
170 .def(
"setProperties", &setProperties, (arg(
"self"), arg(
"kwargs")),
"Set a collection of properties from a dict")
172 .def(
"setPropertySettings", &setPropertySettings, (arg(
"self"), arg(
"name"), arg(
"settingsManager")),
173 "Assign the given IPropertySettings object to the named property")
176 "Set the group for a given property")
179 "Returns whether a property exists")
186 return_value_policy<return_by_value>(),
187 "Returns the property of the given name. Use .value to give the "
189 .def(
"__setitem__", &declareOrSetProperty, (arg(
"self"), arg(
"name"), arg(
"value")),
190 "Set the value of the named property or create it if it doesn't "
192 .def(
"__delitem__", &deleteProperty, (arg(
"self"), arg(
"name")),
"Delete the named property")
195 "Returns whether a property exists")
199 "Returns whether a property exists")
200 .def(
"keys", &getKeys, arg(
"self"))
202 "Returns the list of properties managed by this object")
203 .def(
"get", &get, (arg(
"self"), arg(
"name"), arg(
"value")), return_value_policy<return_by_value>(),
204 "Returns the property of the given name. Use .value to give the "
205 "value. If property with given name does not exist, returns given "
double value
The value of the point.
#define GET_POINTER_SPECIALIZATION(TYPE)
boost::python::extract< std::string > ExtractStdString
void export_IPropertyManager()
Exception for when an item is not found in a collection.
Interface to PropertyManager.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual void removeProperty(const std::string &name, const bool delproperty=true)=0
Removes the property from management.
virtual void declareProperty(std::unique_ptr< Property > p, const std::string &doc="")=0
Function to declare properties (i.e. store them)
virtual Property * getPointerToProperty(const std::string &name) const =0
Get a pointer to property by name.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
virtual std::string getPropertyValue(const std::string &name) const =0
Get the value of a property as a string.
virtual size_t propertyCount() const =0
Returns the number of properties under management.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
virtual const std::vector< Property * > & getProperties() const =0
Get the list of managed properties.
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
virtual IPropertySettings * clone() const =0
Make a copy of the present type of IPropertySettings.
Base class for properties.
const std::type_info * type_info() const
Get the property type_info.