Warning, file /include/boost/python/enum.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005 #ifndef ENUM_DWA200298_HPP
0006 # define ENUM_DWA200298_HPP
0007
0008 # include <boost/python/detail/prefix.hpp>
0009
0010 # include <boost/python/object/enum_base.hpp>
0011 # include <boost/python/converter/rvalue_from_python_data.hpp>
0012 # include <boost/python/converter/registered.hpp>
0013
0014 namespace boost { namespace python {
0015
0016 template <class T>
0017 struct enum_ : public objects::enum_base
0018 {
0019 typedef objects::enum_base base;
0020
0021
0022 enum_(char const* name, char const* doc = 0);
0023
0024
0025 inline enum_<T>& value(char const* name, T);
0026
0027
0028
0029 inline enum_<T>& export_values();
0030 private:
0031 static PyObject* to_python(void const* x);
0032 static void* convertible_from_python(PyObject* obj);
0033 static void construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data);
0034 };
0035
0036 template <class T>
0037 inline enum_<T>::enum_(char const* name, char const* doc )
0038 : base(
0039 name
0040 , &enum_<T>::to_python
0041 , &enum_<T>::convertible_from_python
0042 , &enum_<T>::construct
0043 , type_id<T>()
0044 , doc
0045 )
0046 {
0047 }
0048
0049
0050
0051 template <class T>
0052 PyObject* enum_<T>::to_python(void const* x)
0053 {
0054 return base::to_python(
0055 converter::registered<T>::converters.m_class_object
0056 , static_cast<long>(*(T const*)x));
0057 }
0058
0059
0060
0061
0062
0063
0064
0065
0066 template <class T>
0067 void* enum_<T>::convertible_from_python(PyObject* obj)
0068 {
0069 return PyObject_IsInstance(
0070 obj
0071 , upcast<PyObject>(
0072 converter::registered<T>::converters.m_class_object))
0073
0074 ? obj : 0;
0075 }
0076
0077
0078
0079 template <class T>
0080 void enum_<T>::construct(PyObject* obj, converter::rvalue_from_python_stage1_data* data)
0081 {
0082 #if PY_VERSION_HEX >= 0x03000000
0083 T x = static_cast<T>(PyLong_AS_LONG(obj));
0084 #else
0085 T x = static_cast<T>(PyInt_AS_LONG(obj));
0086 #endif
0087 void* const storage = ((converter::rvalue_from_python_storage<T>*)data)->storage.bytes;
0088 new (storage) T(x);
0089 data->convertible = storage;
0090 }
0091
0092 template <class T>
0093 inline enum_<T>& enum_<T>::value(char const* name, T x)
0094 {
0095 this->add_value(name, static_cast<long>(x));
0096 return *this;
0097 }
0098
0099 template <class T>
0100 inline enum_<T>& enum_<T>::export_values()
0101 {
0102 this->base::export_values();
0103 return *this;
0104 }
0105
0106 }}
0107
0108 #endif