IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
PythonBoostOptional.h
Go to the documentation of this file.
1 // PythonBoostOptional.h:
3 // ----------------------
4 //
14 
15 #ifndef __PYIPSDKBASE_PYTHONBOOSTOPTIONAL_H__
16 #define __PYIPSDKBASE_PYTHONBOOSTOPTIONAL_H__
17 
18 #include <boost/python/class.hpp>
19 #include <boost/python/object.hpp>
20 #include <boost/python/make_constructor.hpp>
21 #include <boost/optional.hpp>
22 
23 namespace ipsdk {
24 namespace python {
25 
28 
29 template<typename T>
30 inline void
31 set(boost::optional<T>& o, T x)
32 {
33  o = x;
34 }
35 
36 template<typename T>
37 inline boost::python::object
38 get(boost::optional<T>& o)
39 {
40  if (o.is_initialized() == true)
41  return boost::python::object(o.get());
42  else
43  return boost::python::object();
44 }
45 
46 template<typename T>
47 inline boost::optional<T>*
48 optional_from_object (boost::python::object& o)
49 {
50  return new boost::optional<T>;
51 }
52 
53 template<typename T>
54 static void
55 exposeOptional(const char* name)
56 {
57  boost::python::class_<boost::optional<T> >(name, boost::python::init<T>())
58  .def ("__init__", boost::python::make_constructor(optional_from_object<T>))
59  .def ("set", &set<T>)
60  .def ("get", &get<T>)
61  .def ("is_initialized", &boost::optional<T>::is_initialized)
62  ;
63 }
64 
67 
68 } // end of namespace python
69 } // end of namespace ipsdk
70 
71 #endif // __PYIPSDKBASE_PYTHONBOOSTOPTIONAL_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22